-
Notifications
You must be signed in to change notification settings - Fork 2k
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
importlib.metadata vs importlib-metadata #10157
Comments
If I understand correctly, the solution would be to switch Lines 25 to 28 in 3b01fbe
for try:
from importlib.metadata import entry_points
except ImportError: # Python < 3.10 (backport)
from importlib_metadata import entry_points ? |
@astrojuanlu Yes, that would be a solution. I feel it makes sense to use the Python-provided module if it's available and only use importlib-metadata as a fallback. However, perhaps @takluyver had a good reason to not do that. |
The So if you want to change the preference around in Sphinx, you'll also have to port the code loading the entry points back to the deprecated API, and then at some point in a couple of years someone will have to switch it back again. It's pretty trivial to actually make either change, though. |
@takluyver That makes sense as well, of course. I'd prefer not to make the Sphinx code less future-proof of course. I hope you don't mind me pinging you, @jaraco. But perhaps you have an idea on how to best handle this issue:
I know it's not a proper solution, but I'm considering just adding the EDIT: I guess what matters here is whether importlib.metadata and importlib-metadata are backwards or forwards compatible. If older versions are happy with Distribution instances from newer versions (the other way around is obviously not working), perhaps I can use just importlib-metadata (when available)? |
My first basic tests with importing importlib-metadata if it's available seem to indicate that it's Distribution class is backwards compatible. i.e. the instance of my subclass is happily accepted by Python 3.9's importlib.metadata's distributions and entry_points. I'll change rinohtype to import importlib-metadata if it's available. |
Fixes compatibility with Sphinx 4.4 sphinx-doc/sphinx#10157
If you have a choice between using the older entry points API and the new one, I'd definitely recommend going with the new one where possible. I'm okay with a custom Distribution supplying its own |
@jaraco Supplying my own The importlib-metadata docs currently say "Users are encouraged to use the Python standard library where suitable and fall back to this library for future compatibility". My experience seems to suggest that this might not be the best approach. I couldn't find any other information about backwards/forwards compatibility. Please consider adding some information regarding this. |
Describe the bug
Commit 6c5c66b by @takluyver removed the dependency on pkg_resources. It prefers the third-party importlib-metadata package over the stdlib importlib.metadata module, even if the Python version provides the latter (which is the case since 3.8). The Sphinx
setup.py
specifies importlib-metadata as a dependency for Python 3.10.This poses a problem when using Sphinx 4.4.0 with the rinoh builder. rinohtype only falls back to using importlib-metadata if importlib.metadata is not available. So, when using Python 3.8 or 3.9, rinohtype will create a DynamicRinohDistribution instance which inherits from importlib.metadata.Distribution, while Sphinx will be using importlib-metadata, which expects Distribution instances to have a _normalized_name attribute and this crashes on encountering the DynamicRinohDistribution (test log).
Is there any particular reason Sphinx does not prefer to use the importlib.metadata included with Python? If that is the case, can you suggest an approach to fix this issue. Personally, I don't see one yet.
Thanks!
How to Reproduce
Expected behavior
No response
Your project
https://github.com/brechtm/rinohtype
Screenshots
No response
OS
any
Python version
3.9.9
Sphinx version
4.4.0
Sphinx extensions
rinohtype
Extra tools
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: