[BUG] Setuptools overriding standard lib `importlib.metadata.PathDistribution`
See original GitHub issuesetuptools version
60.9.3
Python version
python 3.9
OS
macOS
Additional environment information
❯ pip list
Package Version
---------- -------
pip 22.0.4
setuptools 60.9.3
wheel 0.37.1
Description
this seems similar to https://github.com/pypa/setuptools/issues/3102, but issue was closed by #3108, without activity since then, and I still seeing this issue in the latest release.
importing setuptools overrides/removes the behavior and return type of of the standard library importlib.metadata.distribution()
function:
Expected behavior
importing setuptools doesn’t supersede/remove the distribution finder from standard library importlib
How to Reproduce
- import
setuptools
- call
importlib.metadata.distribution()
Output
>>> from importlib import metadata
>>> metadata.distribution('pip') # returns the expected type
<importlib.metadata.PathDistribution object at 0x101665910>
>>> import sys
>>> [getattr(finder, 'find_distributions', None) for finder in sys.meta_path]
[None, None, None, <bound method PathFinder.find_distributions of <class '_frozen_importlib_external.PathFinder'>>]
# importing setuptools changes the type of object returned by metadata.distribution
# and removes the _frozen_importlib_external.PathFinder from
# the list of finders used by `metadata.Distribution.discover`
>>> import setuptools
>>> metadata.distribution('pip')
<setuptools._vendor.importlib_metadata.PathDistribution object at 0x102253070>
>>> [getattr(finder, 'find_distributions', None) for finder in sys.meta_path]
[None, None, None, None, None, None, <bound method MetadataPathFinder.find_distributions of <setuptools._vendor.importlib_metadata.MetadataPathFinder object at 0x101fdad00>>]
# note:
>>> import importlib_metadata
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'importlib_metadata'
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
ImportError: cannot import name 'metadata' from 'importlib'
Today, I ran into an error similar (but not exactly the same) to yours. Starting from Python 3.8, the importlib module has a...
Read more >Using importlib.metadata — Python 3.11.1 documentation
importlib_metadata is a library that provides access to the metadata of an installed Distribution Package, such as its entry points or its top-level...
Read more >History - setuptools 65.6.3.post20221216 documentation
Future releases of setuptools may simply ignore externally set metadata not backed by dynamic or even halt the build with an error.
Read more >Changelog — pytest documentation
#9741: On Python 3.11, use the standard library's tomllib to parse TOML. ... issue #1953: Fixed error when overwriting a parametrized fixture, ...
Read more >Python - Using importlib.metadata | Docs4dev
importlib.metadata is a library that provides for access to installed package metadata. Built in part on Python's import system, this library ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it would be nice to avoid breaking the users’ expectations like it is happening right now, but since this workaround comes directly from
importlib_metadata
, there might be very little we can do in setuptools 😓This workaround also seems necessary for
importlib_metadata
to work properly.I agree. thanks for having a look. If you feel like this is just how it’s going to be, I can close this issue (but feel free to re-open if you think there’s anything actionable here on your end)