mirror of
https://github.com/python/cpython.git
synced 2025-10-25 18:54:53 +00:00
bpo-22831: Use "with" to avoid possible fd leaks in distutils. (GH-10921)
This commit is contained in:
parent
71f82a2f20
commit
c5d5dfdb22
5 changed files with 63 additions and 67 deletions
|
|
@ -378,35 +378,34 @@ def byte_compile (py_files,
|
|||
else:
|
||||
script = open(script_name, "w")
|
||||
|
||||
script.write("""\
|
||||
with script:
|
||||
script.write("""\
|
||||
from distutils.util import byte_compile
|
||||
files = [
|
||||
""")
|
||||
|
||||
# XXX would be nice to write absolute filenames, just for
|
||||
# safety's sake (script should be more robust in the face of
|
||||
# chdir'ing before running it). But this requires abspath'ing
|
||||
# 'prefix' as well, and that breaks the hack in build_lib's
|
||||
# 'byte_compile()' method that carefully tacks on a trailing
|
||||
# slash (os.sep really) to make sure the prefix here is "just
|
||||
# right". This whole prefix business is rather delicate -- the
|
||||
# problem is that it's really a directory, but I'm treating it
|
||||
# as a dumb string, so trailing slashes and so forth matter.
|
||||
# XXX would be nice to write absolute filenames, just for
|
||||
# safety's sake (script should be more robust in the face of
|
||||
# chdir'ing before running it). But this requires abspath'ing
|
||||
# 'prefix' as well, and that breaks the hack in build_lib's
|
||||
# 'byte_compile()' method that carefully tacks on a trailing
|
||||
# slash (os.sep really) to make sure the prefix here is "just
|
||||
# right". This whole prefix business is rather delicate -- the
|
||||
# problem is that it's really a directory, but I'm treating it
|
||||
# as a dumb string, so trailing slashes and so forth matter.
|
||||
|
||||
#py_files = map(os.path.abspath, py_files)
|
||||
#if prefix:
|
||||
# prefix = os.path.abspath(prefix)
|
||||
#py_files = map(os.path.abspath, py_files)
|
||||
#if prefix:
|
||||
# prefix = os.path.abspath(prefix)
|
||||
|
||||
script.write(",\n".join(map(repr, py_files)) + "]\n")
|
||||
script.write("""
|
||||
script.write(",\n".join(map(repr, py_files)) + "]\n")
|
||||
script.write("""
|
||||
byte_compile(files, optimize=%r, force=%r,
|
||||
prefix=%r, base_dir=%r,
|
||||
verbose=%r, dry_run=0,
|
||||
direct=1)
|
||||
""" % (optimize, force, prefix, base_dir, verbose))
|
||||
|
||||
script.close()
|
||||
|
||||
cmd = [sys.executable]
|
||||
cmd.extend(subprocess._optim_args_from_interpreter_flags())
|
||||
cmd.append(script_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue