pypa / pypa/setuptools

[ENH] Importlib Metadata shows two distributions with same name for editable installs

Open
#4,170 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted Long Term Needs Design Proposal Needs Implementation
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

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:

  1. clone and cd into repo at https://github.com/Jacob-Stevens-Haas/setuptools_test
  2. create and activate a virtual environment (I'm using venv)
  3. pip install -e .
  4. 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.

  1. (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']}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the duplicate results with show_dists.py from the linked setuptools_test repository, using the listed virtual-environment and pip install -e . steps. Then trace how distributions(), distribution(name), and packages_distributions() handle the egg-info and dist-info entries. Done means the intended editable-install behavior is defined and covered for both flat and src layouts.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.