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

Implement find_spec in vendored module importers #2633

Merged
merged 4 commits into from Apr 8, 2021

Conversation

webknjaz
Copy link
Member

@webknjaz webknjaz commented Apr 8, 2021

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

webknjaz added a commit to webknjaz/setuptools that referenced this pull request Apr 8, 2021
webknjaz added a commit to webknjaz/setuptools that referenced this pull request Apr 8, 2021
@webknjaz webknjaz force-pushed the bugfixes/2632-importlib-find_spec branch from c6c7b15 to dcb418f Compare April 8, 2021 18:38
@webknjaz webknjaz requested a review from jaraco April 8, 2021 18:39
@webknjaz webknjaz added the bug label Apr 8, 2021
@@ -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."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Produce a registered namespace matching module spec."""
"""Return a module spec for vendored names."""

Copy link
Member Author

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?

Copy link
Member

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).

Copy link
Member

@jaraco jaraco left a 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.

webknjaz and others added 3 commits April 8, 2021 23:41
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>
@webknjaz webknjaz force-pushed the bugfixes/2632-importlib-find_spec branch from e8e9a6d to dd1453b Compare April 8, 2021 21:46
@webknjaz webknjaz requested a review from jaraco April 8, 2021 21:46
def find_spec(self, fullname, path=None, target=None):
"""Return a module spec for vendored names."""
return (
importlib.machinery.ModuleSpec(fullname, self)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaraco jaraco merged commit fe10ebf into pypa:main Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Forward compatibility][BUG] pkg_resources.extern.VendorImporter lacks find_spec() method
2 participants