Kaydet (Commit) 315b748c authored tarafından Steve Dower's avatar Steve Dower

Fixes make_zip.py to create temporary .pyc files in a separate directory. This…

Fixes make_zip.py to create temporary .pyc files in a separate directory. This avoids polluting tests that run code from TEMP.
üst 6703d032
...@@ -82,18 +82,19 @@ def copy_to_layout(target, rel_sources): ...@@ -82,18 +82,19 @@ def copy_to_layout(target, rel_sources):
target.unlink() target.unlink()
with ZipFile(str(target), 'w', ZIP_DEFLATED) as f: with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
for s, rel in rel_sources: with tempfile.TemporaryDirectory() as tmpdir:
if rel.suffix.lower() == '.py': for s, rel in rel_sources:
pyc = Path(tempfile.gettempdir()) / rel.with_suffix('.pyc').name if rel.suffix.lower() == '.py':
try: pyc = Path(tmpdir) / rel.with_suffix('.pyc').name
py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2) try:
except py_compile.PyCompileError: py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
f.write(str(s), str(rel)) except py_compile.PyCompileError:
f.write(str(s), str(rel))
else:
f.write(str(pyc), str(rel.with_suffix('.pyc')))
else: else:
f.write(str(pyc), str(rel.with_suffix('.pyc'))) f.write(str(s), str(rel))
else: count += 1
f.write(str(s), str(rel))
count += 1
else: else:
for s, rel in rel_sources: for s, rel in rel_sources:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment