mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-37641 preserve relative file location in embeddable zip (GH-14884)
Previously, pyc files in the embeddable distribution reported their location as <build path>/<file stem>.py. This causes a little confusion when interpreting stack traces as the file is in a (almost certainly) incorrect location, and lacks the full relative path to Lib (e.g. email/mime/image.py will only show image.py). This change preserves the Lib relative location of the source file as a path so that stack traces are (hopefully) less misleading and more informative. Co-Authored-By: Kyle Stanley <aeros167@gmail.com>
This commit is contained in:
parent
544fa15ea1
commit
c4cda4369f
1 changed files with 5 additions and 6 deletions
|
@ -287,19 +287,18 @@ def _compile_one_py(src, dest, name, optimize, checked=True):
|
||||||
log_warning("Failed to compile {}", src)
|
log_warning("Failed to compile {}", src)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# name argument added to address bpo-37641
|
||||||
def _py_temp_compile(src, ns, dest_dir=None, checked=True):
|
def _py_temp_compile(src, name, ns, dest_dir=None, checked=True):
|
||||||
if not ns.precompile or src not in PY_FILES or src.parent in DATA_DIRS:
|
if not ns.precompile or src not in PY_FILES or src.parent in DATA_DIRS:
|
||||||
return None
|
return None
|
||||||
|
dest = (dest_dir or ns.temp) / (src.stem + ".pyc")
|
||||||
dest = (dest_dir or ns.temp) / (src.stem + ".py")
|
|
||||||
return _compile_one_py(
|
return _compile_one_py(
|
||||||
src, dest.with_suffix(".pyc"), dest, optimize=2, checked=checked
|
src, dest, name, optimize=2, checked=checked
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _write_to_zip(zf, dest, src, ns, checked=True):
|
def _write_to_zip(zf, dest, src, ns, checked=True):
|
||||||
pyc = _py_temp_compile(src, ns, checked=checked)
|
pyc = _py_temp_compile(src, dest, ns, checked=checked)
|
||||||
if pyc:
|
if pyc:
|
||||||
try:
|
try:
|
||||||
zf.write(str(pyc), dest.with_suffix(".pyc"))
|
zf.write(str(pyc), dest.with_suffix(".pyc"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue