-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Same distribution can appear multiple times on Python 3.8 #91
Comments
In GitLab by @jaraco on Sep 30, 2019, 03:12 changed the description |
In GitLab by @jaraco on Sep 30, 2019, 03:13 changed the description |
In GitLab by @jaraco on Sep 30, 2019, 03:16 See jaraco/pytest-checkdocs#2 where I encountered this issue. |
In GitLab by @RonnyPfannschmidt on Sep 30, 2019, 12:07 i am also observing this on a python 3.7 virtualenv where i tested this with a ipython started in site-packages and eded up with triples there, as a distribution was found in |
In GitLab by @warsaw on Sep 30, 2019, 17:54
I'm inclined toward adding logic to the standalone backport that knows about Python version peculiarities, rather than the other way around. The reasoning being that Can you explain a bit more about the limits this approach imposes? |
In GitLab by @jaraco on Oct 26, 2019, 18:25 To illustrate, this patch corrects the test failure reported in #93 by disabling the stdlib distribution resolver: diff --git a/importlib_metadata/_compat.py b/importlib_metadata/_compat.py
index 4f54864..f1439eb 100644
--- a/importlib_metadata/_compat.py
+++ b/importlib_metadata/_compat.py
@@ -52,6 +52,7 @@ __all__ = [
def install(cls):
"""Class decorator for installation on sys.meta_path."""
+ del sys.meta_path[2].find_distributions
sys.meta_path.append(cls())
return cls
This patch is a rough implementation of option (3) and isn't viable, but begins to illustrate how the issue might be addressed. |
In GitLab by @jaraco on Nov 30, 2019, 02:57 In #100, I learned that there's another issue at play here. The fact that both |
In GitLab by @jaraco on Nov 30, 2019, 03:17
Agreed.
The main limitation is that from the perspective of a DistributionFinder implementation, one must register their finder with one implementation (stdlib or backport), but then have your Distribution classes discovered by either implementation. So in some sense, neither implementation can have primacy. Both implementations have to honor the presence of the other. The patch above has one nice behavior - when it installs its own MetaPathFinder, it disables the stdlib MetaPathFinder, which will cause subsequent calls to I'm thinking more and more that's okay and maybe even preferable, but I can imagine risks with that approach, mainly that the code can't guarantee that the |
In GitLab by @jaraco on Nov 30, 2019, 10:10 mentioned in merge request !98 |
In GitLab by @jaraco on Nov 30, 2019, 19:29 closed via merge request !98 |
In GitLab by @layday on Jan 27, 2020, 18:50 @jaraco FYI this patch broke compatibility with PyOxidizer whose finder is not attached to a module:
Is there an expectation that a finder should have a |
In GitLab by @jaraco on Jan 28, 2020, 03:07
Not necessarily. In fact, probably not if the finders spec doesn't require it. The relevant specs, like PEP 302, don't specifically call for a |
In GitLab by @jaraco on Sep 30, 2019, 03:09
With Python 3.8, if one imports
importlib_metadata
, both thePathFinder
and theMetadataPathFinder
will appear onsys.meta_path
withfind_distributions
methods... causing every package to be reported twice. This behavior is fine for some calls likefind_distribution(name)
which will just find the first one, but less desirable for ones likefind_distributions(path=['.'])
, where one might expect to find exactly one (distribution on the current path), but instead finds two (the same one twice).Here are some of the goals that led us here:
importlib_metadata
behavior should be available on Python 3.8 and later even thoughimportlib.metadata
is available (possibly providing forward compatibility and feature backports).I'm not sure what should happen here, but there are a few options that seem possible to me:
importlib_metadata
on Python 3.8 or later. That would preventimportlib_metadata
from installing its duplicate finder. This approach goes directly counter to the second goal above... and doesn't scale well. If one library imports importlib_metadata, they all get the new global state (MetadataPathFinder
onsys.meta_path
).importlib_metadata
don't install thesys.meta_path
hook if on Python 3.8 or later (always rely on the system-provided one). That's probably suitable but limits the scope of backward compatibility that can be provided.importlib_metadata
, bypass the systemPathFinder
forfind_distributions
. This approach would allow the backport to avoid interactions with finders as found in CPython but would still honor other distribution finders. This approach would address the issue when usingimportlib_metadata
but not when usingimportlib.metadata
(but some other library has importedimportlib_metadata
).The text was updated successfully, but these errors were encountered: