Description
setuptools version
setuptools 69.0.3
Python version
3.10.12
OS
Ubuntu
Additional environment information
Applies to both src/ and flat layout
Description
I was trying to identify editable packages installed in my current environment by looking at direct_url.json for a package given by importlib.metadata.distribution(name)
. It was showing that file didn't exist. Upon further investigation, importlib.metadata.distributions()
had two entries for my package - one PathDistribution
who's files contains dist-info
in site-packages, and another PathDistribution
who's files contain egg-info
, built by setuptools in the local directory. distribution(name)
only finds the local version. Interestingly, importlib.metadata.packages_distributions()
shows that the distribution package foo
has two import packages associated, both with the same names.
Expected behavior
I would've expected just one distribution package for an editable install, in this case with a single import package associated. At a lower level, I'm not sure it really makes sense to ever have two distributions of the same name installed, and therefore perhaps setuptools should have internally raised an error when distributions
finds two of the same name or two import packages with the same name in the same distribution.
How to Reproduce
I've got an example distribution package, foo, with one import package, also named foo:
- clone and cd into repo at https://github.com/Jacob-Stevens-Haas/setuptools_test
- create and activate a virtual environment (I'm using venv)
pip install -e .
python show_dists.py
This will print the results of distributions()
, showing two named "foo", the files in the two matching distributions, and then the packages_distributions()
results.
- (optional) playing around with working directory or switching to an src layout (see
src
branch) has same result.pip freeze
shows just a single distribution package
Output
'foo'
'foo'
'pip'
'setuptools'
[PackagePath('pyproject.toml'),
PackagePath('foo/__init__.py'),
PackagePath('foo.egg-info/PKG-INFO'),
PackagePath('foo.egg-info/SOURCES.txt'),
PackagePath('foo.egg-info/dependency_links.txt'),
PackagePath('foo.egg-info/top_level.txt')]
[PackagePath('__editable__.foo-0.1.0.pth'),
PackagePath('__editable___foo_0_1_0_finder.py'),
PackagePath('__pycache__/__editable___foo_0_1_0_finder.cpython-310.pyc'),
PackagePath('foo-0.1.0.dist-info/INSTALLER'),
PackagePath('foo-0.1.0.dist-info/METADATA'),
PackagePath('foo-0.1.0.dist-info/RECORD'),
PackagePath('foo-0.1.0.dist-info/REQUESTED'),
PackagePath('foo-0.1.0.dist-info/WHEEL'),
PackagePath('foo-0.1.0.dist-info/direct_url.json'),
PackagePath('foo-0.1.0.dist-info/top_level.txt')]
{'_distutils_hack': ['setuptools'],
'debian': ['setuptools'],
'foo': ['foo', 'foo'],
'pip': ['pip'],
'pkg_resources': ['setuptools'],
'setuptools': ['setuptools']}