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

Replace pkg_resources with importlib.metadata #10007

Merged
merged 5 commits into from Dec 25, 2021

Conversation

takluyver
Copy link
Contributor

Feature or Bugfix

  • Feature

Purpose

As discussed in #9595, importlib.metadata is the modern way to find entry points, replacing pkg_resources. It's in the standard library from 3.8, but part of the API I've used is new in 3.10, so the importlib_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.

@takluyver
Copy link
Contributor Author

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 setup.py if you like, but I'd rather not dig in to unrelated type checking issues.

sphinx/registry.py Show resolved Hide resolved
Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

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

LGTM with nits.

sphinx/registry.py Outdated Show resolved Hide resolved
@tk0miya
Copy link
Member

tk0miya commented Dec 23, 2021

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.

@tk0miya tk0miya added this to the 4.4.0 milestone Dec 23, 2021
@takluyver
Copy link
Contributor Author

Merged 4.x into this branch, and the CI is indeed OK again. 🙂

@tk0miya tk0miya merged commit bc17cd4 into sphinx-doc:4.x Dec 25, 2021
@tk0miya
Copy link
Member

tk0miya commented Dec 25, 2021

Thank you for your contribution. Merged!

tk0miya added a commit that referenced this pull request Dec 25, 2021
AA-Turner pushed a commit to AA-Turner/sphinx that referenced this pull request Dec 29, 2021
Comment on lines +25 to +28
try: # Python < 3.10 (backport)
from importlib_metadata import entry_points
except ImportError:
from importlib.metadata import entry_points

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?

Copy link
Contributor Author

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

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! 😄

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants