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
Implement find_spec
in vendored module importers
#2633
Conversation
c6c7b15
to
dcb418f
Compare
setuptools/extern/__init__.py
Outdated
@@ -60,6 +62,13 @@ def create_module(self, spec): | |||
def exec_module(self, module): | |||
pass | |||
|
|||
def find_spec(self, fullname, path=None, target=None): | |||
"""Produce a registered namespace matching module spec.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Produce a registered namespace matching module spec.""" | |
"""Return a module spec for vendored names.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, I wanted to ask if there's any particular reason for having two duplicate loaders (one in pkg_resources and another one in setuptools) — can't one import another instead of maintaining the duplicates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split them in preparation for separating pkg_resources into its own package, but never succeeded at that. It would be fine for setuptools to use the loader from pkg_resources again (but not vice-versa).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of small questions, but overall, LGTM.
This change makes the import warning emitted by Python 3.10 disappear but implementing the hook that is supposed to replace the old import mechanism. Refs: * https://bugs.python.org/issue42134 * https://bugs.python.org/issue43540 * pypa#2632 (comment) Fixes pypa#2632 Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
e8e9a6d
to
dd1453b
Compare
pkg_resources/extern/__init__.py
Outdated
def find_spec(self, fullname, path=None, target=None): | ||
"""Return a module spec for vendored names.""" | ||
return ( | ||
importlib.machinery.ModuleSpec(fullname, self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this could (should?) be https://docs.python.org/3/library/importlib.html#importlib.util.spec_from_loader.
Summary of changes
This change makes the import warning emitted by Python 3.10 disappear
but implementing the hook that is supposed to replace the old import
mechanism.
Refs:
Fixes #2632
Pull Request Checklist
changelog.d/
.(See documentation for details)