-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Wrong handling of .
with namespace packages
#261
Comments
This is the error that I was getting:
It worked with normal packages; it fails for namespace packages. |
Here's how to reproduce this error:
Now in Python: import first.second # works Try importlib_metadata: from importlib_metadata import Distribution
Distribution.from_name('first.second')
# importlib_metadata.PackageNotFoundError: No package metadata was found for first.second this is what fails: from importlib_metadata import Prepared, FastPath
list(FastPath('./').search(Prepared('first.second'))) # ->
[] try deeper: from importlib_metadata import Prepared
Prepared('first.second').exact_matches # ->
['first_second.dist-info', 'first_second.egg-info'] so you see that it's the |
Yes, this is a pretty serious bug. It is going to break any project using namespace packages that use this package. |
@jaraco I assume you want this behavior in new versions? If so I can open a PR that only ops-in to normalization in Python >=3.10. |
Well, actually, I am not sure if that is the correct approach as people might want to use this because it backports the new behavior. Let me know what you think. |
I don't believe the issue is with namespace packages, but with any package whose name has a |
I don't believe this repro is correct. Importlib_metadata operates on package metadata and not on packages themselves. Creating a Python package called It's this test that's intended to capture the legacy expectation. In that test, the fixture ensures that
Here, I think I see the issue now. The issue is that the compatibility fallback is looking for a name with a version but will miss metadata directories without a version. |
…hasn't been updated to the new normalization technique. Ref #261.
…hasn't been updated to the new normalization technique. Ref #261.
I've found a fix for the issue, but I'm pretty sure the fix, although it passes all the tests, will break package discovery. This code is so hairy and hyper-optimized that this one tweak has really mucked things up. |
In 4098b51, I've captured the breakage with package discovery with a test and addressed the concern. I still have a concern that now legacy egg discovery is no longer accurate. |
You mean this? Seems to be working >>> import importlib_metadata
>>> importlib_metadata.Distribution.from_name('jaraco.classes')._path
PosixPath('/usr/lib/python3.8/site-packages/jaraco.classes-3.1.0-py3.8.egg-info')
>>> importlib_metadata.Distribution.from_name('jaraco_classes')._path
PosixPath('/usr/lib/python3.8/site-packages/jaraco.classes-3.1.0-py3.8.egg-info') |
We have a namespace package:
which is incorrectly handled by this backport.
As a result, this search fails:
as a result, our build broke as soon as this package was updated :)
Please revert this change: dbdef6b . It should not replace
.
with_
!In Cpython, it's still like it used to be: https://github.com/python/cpython/blob/master/Lib/importlib/metadata.py#L478
The text was updated successfully, but these errors were encountered: