distributions() finds two packages for editable installs #481
Description
Cross-posting from pypa/setuptools#4170, since I'm not sure which is the right repo to fix this in, or whether both repos have something to consider here:
tl;dr: When setuptools does an editable install, importlib.metadata.distributions()
finds a PathDistribution
for both the dist-info
directory in site-packages as well as a PathDistribution
for the local egg-info
directory. See the above issue for MWE repo. The current consequences for importlib.metadata are:
- As mentioned,
distributions()
finds two distributions distribution(name)
gives a different distribution depending upon whether the package has a flat or src layout. In a flat layout, the egg-info distribution is found at""
( I think, because it's the first entry ofsys.path
), and in an src layout, the egg-info distribution is found in whatever folder is added by the .pth file created in an editable install (the last entry ofsys.path
).distributions_packages()
shows a single distribution package name with identical copies of import package names, e.g."foo": ["foo", "foo"]
So regardless of anything setuptools needs to do differently in creating editable installs, what is the expected behavior when importlib metadata finds multiple packages of the same name? I can think of a few options...
- Do nothing, because there's legitimate reasons for two distribution packages with the same name that provide different/partially-overlapping/fully-conflicting import package names.
- Try to resolve whether they actually mean the same thing, such as comparing associated import packages and following some heirarchical rule (e.g. dist-info is better egg-info)
- Raise a warning/exception because importlib.metadata can't tell which metadata will be associated with the package that gets imported
I can't think of a legitimate reason for two distribution package names to be installed simultaneously with the exact same import package names, so I'm not sure 1 is correct. But IIUC and I probably don't, 2 or 3 would change the expected behavior of a DistributionFinder
, and I'm not sure what the performance cost of disambiguation would be.