Skip to content

Commit dd3b031

Browse files
committed
Merge branch 'master' into housekeeping/98-remove-shim
2 parents ae13d5e + c854e9a commit dd3b031

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ qa:
1313

1414
tests:
1515
script:
16-
- tox -e py27,py34,py35,py36,py37,py38
16+
- tox -e py27,py35,py36,py37,py38
1717

1818
coverage:
1919
script:
20-
- tox -e py27-cov,py34-cov,py35-cov,py36-cov,py37-cov,py38-cov
20+
- tox -e py27-cov,py35-cov,py36-cov,py37-cov,py38-cov
2121
artifacts:
2222
paths:
2323
- coverage.xml
2424

2525
diffcov:
2626
script:
27-
- tox -e py27-diffcov,py34-diffcov,py35-diffcov,py36-diffcov,py37-diffcov,py38-diffcov
27+
- tox -e py27-diffcov,py35-diffcov,py36-diffcov,py37-diffcov,py38-diffcov
2828

2929
docs:
3030
script:

importlib_metadata/_compat.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,35 @@ class MetaPathFinder(object):
5151

5252

5353
def 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+
5983
class NullFinder:
6084
"""
6185
A "Finder" (aka "MetaClassFinder") that never finds any modules,

importlib_metadata/docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ v1.0.0
77

88
* Removed compatibility shim introduced in 0.23.
99

10+
* For better compatibility with the stdlib implementation and to
11+
avoid the same distributions being discovered by the stdlib and
12+
backport implementations, the backport now disables the
13+
stdlib DistributionFinder during initialization (import time).
14+
Closes #91 and closes #100.
15+
1016
0.23
1117
====
1218
* Added a compatibility shim to prevent failures on beta releases

importlib_metadata/docs/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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.
1718
Developers looking for detailed API descriptions should refer to the Python
1819
3.8 standard library documentation.
1920

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = {py27,py34,py35,py36,py37,py38}{,-cov,-diffcov},qa,docs
2+
envlist = {py27,py35,py36,py37,py38}{,-cov,-diffcov},qa,docs
33
skip_missing_interpreters = True
44

55

0 commit comments

Comments
 (0)