Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building: add support for collecting .pyc files from .zip archives #7711

Merged
merged 1 commit into from Jun 18, 2023

Conversation

rokm
Copy link
Member

@rokm rokm commented Jun 17, 2023

Extend the get_code_object and compile_pymodule helpers from PyInstaller.buildings.utils to allow retrieval of code objects from .pyc files embedded in a zip archive.

This acommodates Windows embeddable python, where stdlib .pyc modules are stored in `python3x.zip˙ file.

Most of those modules are collected from modulegraph's code cache, so their source location does not really matter; this commit fixes the collection of the remaining few that are collected directly from the filesystem.


Tested manually with embeddable python 3.7.9 and 3.11.4 with basic hello-world program. Closes #4989.

Typically, only compile_pymodule seems to be called (and even that only for struct.py, probably because we put it directly into PKG). By commenting out code cache support in PYZ, calls to get_code_object can be triggered for all modules collected from stdlib (including ones that are packages and have submodules, e.g., ctypes/__init__.py) - I'm not sure if we can ever get in situation when code cache is unavailable (maybe if cached Analysis is used, but PYZ needs to be regenerated because it was manually removed from the build directory?).

Extend the `get_code_object` and `compile_pymodule` helpers from
`PyInstaller.buildings.utils` to allow retrieval of code objects
from .pyc files embedded in a zip archive.

This accommodates `Windows embeddable python`, where stdlib .pyc
modules are stored in `python3x.zip˙ file.

Most of those modules are collected from modulegraph's code cache,
so their source location does not really matter; this commit fixes
the collection of the remaining few that are collected directly
from the filesystem.
@rokm
Copy link
Member Author

rokm commented Jun 17, 2023

The revised version accounts for the fact that get_code_object is also used with entry-point script, which can have an arbitrary (or no) extension. So we now treat file with .pyc suffix as byte-compiled .pyc module, and everything else as a python source file.

@rokm rokm merged commit 1cc6719 into pyinstaller:develop Jun 18, 2023
17 of 18 checks passed
@rokm rokm deleted the pycs-from-zip-archive branch June 18, 2023 08:03
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to build executable using embedded zip Python
2 participants