# HG changeset patch # User Robert Bradshaw # Date 1350066866 25200 # Node ID e27a93ecb6bb597cf2aad30ec2f32750d7d525d3 # Parent 182884b460bf40896512ec969dc57659b66ad186 Issue #16202 Run script in empty directory, not /tmp. diff -r 182884b460bf -r e27a93ecb6bb Lib/distutils/util.py --- a/Lib/distutils/util.py Fri Oct 12 11:44:19 2012 -0400 +++ b/Lib/distutils/util.py Fri Oct 12 11:34:26 2012 -0700 @@ -386,17 +386,16 @@ # run it with the appropriate flags. if not direct: try: - from tempfile import mkstemp - (script_fd, script_name) = mkstemp(".py") + from tempfile import mkdtemp + tmpdir = mkdtemp() + script_name = os.path.join(tmpdir, "script.py") except ImportError: from tempfile import mktemp - (script_fd, script_name) = None, mktemp(".py") + tmpdir = None + script_name = mktemp(".py") log.info("writing byte-compilation script '%s'", script_name) if not dry_run: - if script_fd is not None: - script = os.fdopen(script_fd, "w") - else: - script = open(script_name, "w") + script = open(script_name, "w") script.write("""\ from distutils.util import byte_compile @@ -433,8 +432,16 @@ elif optimize == 2: cmd.insert(1, "-OO") spawn(cmd, dry_run=dry_run) - execute(os.remove, (script_name,), "removing %s" % script_name, - dry_run=dry_run) + if tmpdir is not None: + for filename in os.listdir(tmpdir): + path = os.path.join(tmpdir, filename) + execute(os.remove, (path,), "removing %s" % path, + dry_run=dry_run) + execute(os.rmdir, (tmpdir,), "removing %s" % tmpdir, + dry_run=dry_run) + else: + execute(os.remove, (script_name,), "removing %s" % script_name, + dry_run=dry_run) # "Direct" byte-compilation: use the py_compile module to compile # right here, right now. Note that the script generated in indirect