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

Skip to content

Commit 315b748

Browse files
committed
Fixes make_zip.py to create temporary .pyc files in a separate directory. This avoids polluting tests that run code from TEMP.
1 parent 6703d03 commit 315b748

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

Tools/msi/make_zip.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ def copy_to_layout(target, rel_sources):
8282
target.unlink()
8383

8484
with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
85-
for s, rel in rel_sources:
86-
if rel.suffix.lower() == '.py':
87-
pyc = Path(tempfile.gettempdir()) / rel.with_suffix('.pyc').name
88-
try:
89-
py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
90-
except py_compile.PyCompileError:
91-
f.write(str(s), str(rel))
85+
with tempfile.TemporaryDirectory() as tmpdir:
86+
for s, rel in rel_sources:
87+
if rel.suffix.lower() == '.py':
88+
pyc = Path(tmpdir) / rel.with_suffix('.pyc').name
89+
try:
90+
py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
91+
except py_compile.PyCompileError:
92+
f.write(str(s), str(rel))
93+
else:
94+
f.write(str(pyc), str(rel.with_suffix('.pyc')))
9295
else:
93-
f.write(str(pyc), str(rel.with_suffix('.pyc')))
94-
else:
95-
f.write(str(s), str(rel))
96-
count += 1
96+
f.write(str(s), str(rel))
97+
count += 1
9798

9899
else:
99100
for s, rel in rel_sources:

0 commit comments

Comments
 (0)