Skip to content

Commit

Permalink
depend/utils: strip paths from modules collected into base_library.zip (
Browse files Browse the repository at this point in the history
#5564)

Strip paths from modules collected into base_library.zip, to enable
reproducible builds regardless of python's install location.

Fixes #5563.
  • Loading branch information
rokm committed Feb 19, 2021
1 parent c24117a commit b9fcbbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion PyInstaller/depend/utils.py
Expand Up @@ -49,6 +49,10 @@ def create_py3_base_library(libzip_filename, graph):
modules is necessary to have on PYTHONPATH for initializing libpython3
in order to run the frozen executable with Python 3.
"""
# Import strip_paths_in_code locally to avoid cyclic import between
# building.utils and depend.utils (this module); building.utils
# imports depend.bindepend, which in turn imports depend.utils.
from ..building.utils import strip_paths_in_code
# Construct regular expression for matching modules that should be bundled
# into base_library.zip.
# Excluded are plain 'modules' or 'submodules.ANY_NAME'.
Expand Down Expand Up @@ -102,7 +106,8 @@ def create_py3_base_library(libzip_filename, graph):
fc.write(source_hash)
else:
fc.write(struct.pack('<II', timestamp, size))
marshal.dump(mod.code, fc)
code = strip_paths_in_code(mod.code) # Strip paths
marshal.dump(code, fc)
# Use a ZipInfo to set timestamp for deterministic build
info = zipfile.ZipInfo(new_name)
zf.writestr(info, fc.getvalue())
Expand Down
2 changes: 2 additions & 0 deletions news/5563.bugfix.rst
@@ -0,0 +1,2 @@
Strip absolute paths from ``.pyc`` modules collected into ``base_library.zip``
to enable reproducible builds that are invariant to Python install location.

0 comments on commit b9fcbbf

Please sign in to comment.