File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -51,11 +51,35 @@ class MetaPathFinder(object):
5151
5252
5353def install (cls ):
54- """Class decorator for installation on sys.meta_path."""
54+ """
55+ Class decorator for installation on sys.meta_path.
56+
57+ Adds the backport DistributionFinder to sys.meta_path and
58+ attempts to disable the finder functionality of the stdlib
59+ DistributionFinder.
60+ """
5561 sys .meta_path .append (cls ())
62+ disable_stdlib_finder ()
5663 return cls
5764
5865
66+ def disable_stdlib_finder ():
67+ """
68+ Give the backport primacy for discovering path-based distributions
69+ by monkey-patching the stdlib O_O.
70+
71+ See #91 for more background for rationale on this sketchy
72+ behavior.
73+ """
74+ def matches (finder ):
75+ return (
76+ finder .__module__ == '_frozen_importlib_external'
77+ and hasattr (finder , 'find_distributions' )
78+ )
79+ for finder in filter (matches , sys .meta_path ): # pragma: nocover
80+ del finder .find_distributions
81+
82+
5983class NullFinder :
6084 """
6185 A "Finder" (aka "MetaClassFinder") that never finds any modules,
Original file line number Diff line number Diff line change 22 importlib_metadata NEWS
33=========================
44
5+ v1.0.0
6+ ======
7+ * For better compatibility with the stdlib implementation and to
8+ avoid the same distributions being discovered by the stdlib and
9+ backport implementations, the backport now disables the
10+ stdlib DistributionFinder during initialization (import time).
11+ Closes #91 and closes #100.
12+
5130.23
614====
715* Added a compatibility shim to prevent failures on beta releases
Original file line number Diff line number Diff line change @@ -12,8 +12,9 @@ efficient ``pkg_resources`` package.
1212
1313``importlib_metadata `` is a backport of Python 3.8's standard library
1414`importlib.metadata `_ module for Python 2.7, and 3.4 through 3.7. Users of
15- Python 3.8 and beyond are encouraged to use the standard library module, and
16- in fact for these versions, ``importlib_metadata `` just shadows that module.
15+ Python 3.8 and beyond are encouraged to use the standard library module.
16+ When imported on Python 3.8 and later, ``importlib_metadata `` replaces the
17+ DistributionFinder behavior from the stdlib, but leaves the API in tact.
1718Developers looking for detailed API descriptions should refer to the Python
18193.8 standard library documentation.
1920
You can’t perform that action at this time.
0 commit comments