mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Puts compiled pyc files into embedded library ZIP file instead of sources.
This commit is contained in:
commit
ec3e16a0f4
1 changed files with 11 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import py_compile
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -82,7 +83,16 @@ def copy_to_layout(target, rel_sources):
|
||||||
|
|
||||||
with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
|
with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
|
||||||
for s, rel in rel_sources:
|
for s, rel in rel_sources:
|
||||||
f.write(str(s), str(rel))
|
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))
|
||||||
|
else:
|
||||||
|
f.write(str(pyc), str(rel.with_suffix('.pyc')))
|
||||||
|
else:
|
||||||
|
f.write(str(s), str(rel))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue