building: add support for collecting .pyc files from .zip archives #7711
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Extend the
get_code_object
andcompile_pymodule
helpers fromPyInstaller.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 forstruct.py
, probably because we put it directly into PKG). By commenting out code cache support in PYZ, calls toget_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?).