Replace deprecated imp with importlib#7676
Merged
bwoodsend merged 9 commits intopyinstaller:developfrom Jun 4, 2023
Merged
Conversation
Whilst the former function does provide additional information, and whilst the code base does juggle that information around, only the suffixes themselves ever get used.
This eliminates usages of imp.find_module().
Doing so removes its usages of imp. For future reference, this is done by
running:
swig -python sample.i
This does highlight though that, since swig's new generated files use
plain imports rather than imp/importlib, swig works fine without all our
special handling so dropping support for old style swig templates may be
the simplest way forward.
hook-pkg_without_hook_for_pkg.sub1.py contains checks that pkg_without_hook_for_pkg.sub1 has a hook and pkg_without_hook_for_pkg doesn't. Since PyInstaller lacks a nice standalone find_hook(module_name) function, it uses imp.find_module() (which is not how PyInstaller normally finds hooks) with the module search path being the expected location of the hook plus PyInstaller's own hooks subpackage. importlib.util.find_spec() (the closet equivalent to imp.find_module()) is unable to find any module with a `-` in it so an equivalent check is impossible. I consider a dumb `git ls-files | grep hook-pkg_without_hook_for_pkg.py` to be all I need to convince me that `hook-pkg_without_hook_for_pkg.py` doesn't exist so lets solve this problem by removing it.
This was
linked to
issues
Jun 3, 2023
Member
Author
|
This doesn't fix #7524 or modulegraph being recursive so we will still need to replace modulegraph eventually but at least this gets rid of the Python 3.12 deadline. |
Member
|
Okay, let's take this route, then. I tried to build a hello world program with 3.12b1 on my linux box, and I can get it running with this and #7670 and a couple of small additions that I'll organize into a proper PR. There's also an index-out-of-range error coming from byte-code scanning (which I had to disable), but I think that's standard stuff. So extending the life of the modulegraph for 3.12 does seem feasible. |
rokm
approved these changes
Jun 3, 2023
pkgutil.ImpImporter is not available in python 3.12 anymore; but we don't really use it anywhere in that code, and instead end up using importlib.machinery.FileFinder if python >= 3.3, which covers all supported python versions.
When retrieving loader from importer/finder, prefer the PEP 451 `find_spec` to retrieve spec and loader from it, instead of using PEP 302 `find_loader`. The latter has been obsolete for a while, and became unavailabe on built-in importers/finders with python 3.12.
Member
|
I've cherry-picked the two commits that are related to modulegraph and use of obsolete import mechanisms, as they thematically fit into this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This wasn't as scary as I expected. The most complicated usages of
impwithout drop-inimportlibequivalents were mostly inside unused parts of the codebase.