Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9216cfe

Browse files
committed
Added a long-winded comment (and commented-out comment to go with out)
about how it would be nice to write absolute paths to the temporary byte-compilation script, but this doesn't work because it screws up the trailing-slash trickery done to 'prefix' in build_py's 'byte_compile()' method. Fixed to use 'execute()' instead of 'os.remove()' to remove the temporary script: now it doesn't blow up in dry-run mode!
1 parent d52755f commit 9216cfe

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

Lib/distutils/util.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,21 @@ def byte_compile (py_files,
353353
from distutils.util import byte_compile
354354
files = [
355355
""")
356+
357+
# XXX would be nice to write absolute filenames, just for
358+
# safety's sake (script should be more robust in the face of
359+
# chdir'ing before running it). But this requires abspath'ing
360+
# 'prefix' as well, and that breaks the hack in build_lib's
361+
# 'byte_compile()' method that carefully tacks on a trailing
362+
# slash (os.sep really) to make sure the prefix here is "just
363+
# right". This whole prefix business is rather delicate -- the
364+
# problem is that it's really a directory, but I'm treating it
365+
# as a dumb string, so trailing slashes and so forth matter.
366+
367+
#py_files = map(os.path.abspath, py_files)
368+
#if prefix:
369+
# prefix = os.path.abspath(prefix)
370+
356371
script.write(string.join(map(repr, py_files), ",\n") + "]\n")
357372
script.write("""
358373
byte_compile(files, optimize=%s, force=%s,
@@ -369,7 +384,8 @@ def byte_compile (py_files,
369384
elif optimize == 2:
370385
cmd.insert(1, "-OO")
371386
spawn(cmd, verbose=verbose, dry_run=dry_run)
372-
os.remove(script_name)
387+
execute(os.remove, (script_name,), "removing %s" % script_name,
388+
verbose=verbose, dry_run=dry_run)
373389

374390
# "Direct" byte-compilation: use the py_compile module to compile
375391
# right here, right now. Note that the script generated in indirect

0 commit comments

Comments
 (0)