Local distribution not found for package using the 'src' layout
In the Distribution.find_local method, I assumed, apparently incorrectly, that performing a setup.py develop
or pip install -e .
on a package would generate the metadata in .
as it does on projects I've maintained.
I recently inherited the configparser project, which uses the 'src' layout, and I discover that in that project, setuptools generates the egg-info metadata in 'src', and in this condition, find_local
gets a ValueError because there's no metadata found in .
:
configparser master $ python setup.py egg_info
running egg_info
creating src/configparser.egg-info
writing src/configparser.egg-info/PKG-INFO
writing dependency_links to src/configparser.egg-info/dependency_links.txt
writing requirements to src/configparser.egg-info/requires.txt
writing top-level names to src/configparser.egg-info/top_level.txt
writing manifest file 'src/configparser.egg-info/SOURCES.txt'
reading manifest file 'src/configparser.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'src/configparser.egg-info/SOURCES.txt'
configparser master $ pip-run -q importlib_metadata==0.8
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib_metadata
>>> importlib_metadata.api.local_distribution()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/importlib_metadata/api.py", line 326, in local_distribution
return Distribution.find_local()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/importlib_metadata/api.py", line 186, in find_local
dist, = dists
ValueError: not enough values to unpack (expected 1, got 0)
>>>
I'm not sure what to do... because in the general case, any package can decide to have its metadata built wherever it likes (there's nothing special about 'src').
I think the recommendation from PEP 517 and PEP 518 is that tools that need metadata for a package that's on the file system, the way to do that is to call the hooks. I think importlib_metadata should probably do this rather than expecting the metadata to be in .
.
I'm also tempted to find metadata in .
or src
as a short-term, hacky workaround. But before I do that, I'll try to see if I can make the pep517 package help out in this regard.