]> granicus.if.org Git - python/commitdiff
Fixes make_zip.py to create temporary .pyc files in a separate directory. This avoids...
authorSteve Dower <steve.dower@microsoft.com>
Wed, 5 Aug 2015 18:34:50 +0000 (11:34 -0700)
committerSteve Dower <steve.dower@microsoft.com>
Wed, 5 Aug 2015 18:34:50 +0000 (11:34 -0700)
Tools/msi/make_zip.py

index bace19a2be3c2d961fd459981b4d6e4615f263f0..ba711c484a9b58e3c847f05d4dd9a9566e1cb4eb 100644 (file)
@@ -82,18 +82,19 @@ def copy_to_layout(target, rel_sources):
             target.unlink()
 
         with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
-            for s, rel in rel_sources:
-                if rel.suffix.lower() == '.py':
-                    pyc = Path(tempfile.gettempdir()) / rel.with_suffix('.pyc').name
-                    try:
-                        py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
-                    except py_compile.PyCompileError:
-                        f.write(str(s), str(rel))
+            with tempfile.TemporaryDirectory() as tmpdir:
+                for s, rel in rel_sources:
+                    if rel.suffix.lower() == '.py':
+                        pyc = Path(tmpdir) / rel.with_suffix('.pyc').name
+                        try:
+                            py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
+                        except py_compile.PyCompileError:
+                            f.write(str(s), str(rel))
+                        else:
+                            f.write(str(pyc), str(rel.with_suffix('.pyc')))
                     else:
-                        f.write(str(pyc), str(rel.with_suffix('.pyc')))
-                else:
-                    f.write(str(s), str(rel))
-                count += 1
+                        f.write(str(s), str(rel))
+                    count += 1
 
     else:
         for s, rel in rel_sources: