Skip to content

Fixed iter_modules hook when packages are symbolically linked#7885

Merged
rokm merged 2 commits intopyinstaller:developfrom
gentlegiantJGC:develop
Aug 25, 2023
Merged

Fixed iter_modules hook when packages are symbolically linked#7885
rokm merged 2 commits intopyinstaller:developfrom
gentlegiantJGC:develop

Conversation

@gentlegiantJGC
Copy link
Copy Markdown
Contributor

When packages are symbolically linked out of the _MEIPASS directory as they are on MacOS when data files are present there is a path mismatch causing them to get skipped.
This resolves the real path of the package paths and the module paths so that they can be compared correctly.

This changes the comparison to run in path space rather than module dotted space.
I believe this is equivalent because all modules in the PyiFrozenImporter should be in the _MEIPASS directory.

Fixes #7884

@rokm
Copy link
Copy Markdown
Member

rokm commented Aug 25, 2023

Nice work, @gentlegiantJGC!

The removal of early check for sys._MEIPASS prefix does mean that we will now iterate over the TOC in vain when the given path is outside of the frozen application bundle (which is a valid situation, albeit probably an unlikely one), but I like this better than having to explicitly deal with two possible prefixes in macOS .app bundles.

toofar added a commit to qutebrowser/qutebrowser that referenced this pull request Aug 25, 2023
Pull in this PR: pyinstaller/pyinstaller#7885

How to test: make sure extensions are loaded on macOS now that data
files are under qutebrowser/... again and we are not doing any frozen
specific workarounds for loading data files or extensions.
gentlegiantJGC and others added 2 commits August 25, 2023 13:55
When a package is symbolically linked out of the _MEIPASS directory
(for example, in macOS .app bundles when package contains data files),
there is a path mismatch causing it to get skipped.

This resolves the real path of the package paths and the module paths
so that they can be compared correctly. It changes the comparison to
run in path space rather than module dotted space. I believe this is
equivalent because all modules in the PyiFrozenImporter should be in
the _MEIPASS directory.
…ta file

Add a test for `pkgutil.iter_modules` and package with data file
in macOS .app bundles. In such cases, the package's directory is
fully collected into `Contents/Resources` directory, and a symbolic
link to the package's directory is created in `Contents/Frameworks`
(the `_MEIPASS` directory). When validating the package path prefix,
our `pkgutil.iter_modules` implementation needs to account that
resolved package path does not directly match the `_MEIPASS` path
due to the symbolic link.
@rokm rokm merged commit ab4713a into pyinstaller:develop Aug 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 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.

pkgutil.iter_modules is broken on MacOS

3 participants