- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Replace pkg_resources with importlib.metadata #10007
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
Conversation
The mypy failure appears to be unrelated. Mypy 0.930 was just released today, and if I use this on the 4.x branch, it fails. Mypy 0.921 passes on both branches. I can limit the version range used in |
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.
LGTM with nits.
Now I just fixed the warnings from mypy on the HEAD of 4.x branch now. Could you merge it to your branch, please? Then CI will go fine. |
Merged 4.x into this branch, and the CI is indeed OK again. 🙂 |
Thank you for your contribution. Merged! |
try: # Python < 3.10 (backport) | ||
from importlib_metadata import entry_points | ||
except ImportError: | ||
from importlib.metadata import entry_points |
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.
Is there a reason the builtin isn't tried before the backport?
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.
Yes: the code is using APIs that were changed in 3.10, so for 3.8 and 3.9 we want to use the backport over the standard library module. 🙂
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.
Got it. Thanks for the context! 😄
Feature or Bugfix
Purpose
As discussed in #9595,
importlib.metadata
is the modern way to find entry points, replacingpkg_resources
. It's in the standard library from 3.8, but part of the API I've used is new in 3.10, so theimportlib_metadata
backport is used on older versions.Concretely,
pkg_resources
scans metadata from all packages at import time, which is generally considered a bad thing.importlib.metadata
only scans metadata when it's called.