New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importlib.metadata.Distribution.files empty for editable install #96144
Comments
I believe this should be reported in https://github.com/python/importlib_metadata and below seem to be related to this issue. cc: @jaraco pypa/packaging-problems#609 |
I'm not able to replicate this issue on Python 3.11rc1 (and pylauncher):
The output is neither empty nor is it missing files from the distribution. Since the report says that the output should be empty for any project installed as editable, I believe the report is invalid as described. Although I believe the output you described above, it doesn't describe a situation where I can replicate the issue (I don't have the contents of setup.py). If this issue is still reproducible for you, could you put together a repository or zip of the project where the issue occurs? |
the details of the repo case are described in the issue; it has been attached as a zip for your convenience at your request. it requires creating a setup.py file and at least 1 module inside the package to be installed. one possibly relevant detail that is only implicitly stated is the use of namespace packages - your repro includes an also noted in the issue, I am not using python 3.11, but python 3.10.5 the title is not entirely accurate, but I don't think that makes the issue 'invalid' hopefully you will be able to piece together what you require. if there is additional supplemental data required please let me know. |
Oh, this is interesting. Using your repro, I can in fact replicate the issue locally. After pip installing the package as editable using the latest setuptools, I see that
I can see that in one case, the metadata is coming from the egg-info, and in the other, from a dist-info. The latter appears to be generated by a virtual package generated for editable installs, whereas the former appears to be coming from the .egg-info. I'll need to do some more investigation. |
I created this dockerfile to easily replicate the issue: FROM jaraco/multipy-tox
RUN apt install -y libarchive-tools
RUN pipx install httpie
RUN http --follow GET https://github.com/python/cpython/files/9497942/pkg.zip | bsdtar x
WORKDIR pkg
RUN py -m venv .venv
RUN py -m pip uninstall -y setuptools
RUN py -m pip install -e .
CMD py -c "import importlib.metadata as metadata, pprint; pprint.pprint({d.name: d.files for d in metadata.distributions() if d.name.startswith('editable')})" |
Aha! The use of the dict comprehension is what is masking the presence of two metadata implementations for
That explains why there are different values coming from different calls. Moreover, that also explains why the files are missing from the second metadata found. The metadata that pip/setuptools installs for that editable package doesn't include the list of files "installed" (the RECORD file only includes the metadata and finder hook). In that sense, importlib metadata is doing the "right" thing here (reflecting the reality of the situation, if somewhat awkwardly), but the PyPA is going to need to figure out what needs to happen to generate the correct metadata for an editable-installed package. There are a few questions I'd like to answer:
It's quite possible because of (2) that the metadata specification is going to need to be expanded to support "files linked to but not installed by this package" or possibly separate the editable shim metadata from the metadata for the package under development. cc: @abravalheri, @pfmoore; If you have some time to review the findings above, I'd be interested in your insights and links to any known issues relating to these concerns or other considerations you may have. |
Hi @jaraco,
This is a tricky subject. Generally, I have the impression that setuptools implementation for the The When implementing the PEP 660, I tried to improve this behaviour. We can see that when running However,
My understanding from the specs is that
If we take the example of >>> from pprint import pprint
>>> import importlib.metadata as md
>>> installer = next(md.distributions(name='installer'))
>>> pprint(installer.files)
[PackagePath('installer-0.6.0.dev0.dist-info/INSTALLER'),
PackagePath('installer-0.6.0.dev0.dist-info/LICENSE'),
PackagePath('installer-0.6.0.dev0.dist-info/METADATA'),
PackagePath('installer-0.6.0.dev0.dist-info/RECORD'),
PackagePath('installer-0.6.0.dev0.dist-info/REQUESTED'),
PackagePath('installer-0.6.0.dev0.dist-info/WHEEL'),
PackagePath('installer-0.6.0.dev0.dist-info/direct_url.json'),
PackagePath('installer.pth')]
>>> installer._path
PosixPath('/tmp/venv/lib/python3.10/site-packages/installer-0.6.0.dev0.dist-info') |
I believe that (right now) it is tricky for Even if we re-implement |
Thanks @abravalheri. That's very useful. It clarifies that for editable installs, even for packages installed by flit (discarding any setuptools-specific issues), the RECORD file does not list the package modules. That leads me to believe this issue can't be solved by importlib metadata, but first needs to be solved by the PyPA - to design and then implement a spec for reporting the "files" of an editable install... or to declare that such behavior is unsupported. In the meantime, importlib metadata will continue to make a best effort to reflect the metadata that's present. I don't believe there's anything particularly wrong with the current implementation, other than it awkwardly and arbitrarily exposes different metadata depending on the technique used to consume it (dict comprehension vs list iteration). I plan to file an issue with pypa/packaging-problems to track the underlying need. |
Bug report
when installing a package as editable, importlib.metadata.Distribution.files returns only the metadata for the install, and not the actual files of the distribution.
notably, this does not occur if the package location is separately added to $PYTHONPATH or see you soon.path.
install any package with
-e
obtain the importlib.metadata.Distribution for that package.
enumerate the
files
property.e.g:
given a test project set up as:
that has been editably-installed, e.g. from src -
pip install -e pkg
then attempt to discover the modules of the package like so:Output
note no modules from pkg are listed.
Your environment
The text was updated successfully, but these errors were encountered: