Skip to content

Commit 79db2b6

Browse files
committed
Merge branch 'master' into bugfix/pickleable-ep
2 parents 74c3e35 + 71697ae commit 79db2b6

File tree

7 files changed

+56
-42
lines changed

7 files changed

+56
-42
lines changed

.gitlab-ci.yml

Lines changed: 4 additions & 4 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:
@@ -41,6 +41,6 @@ codecov:
4141
release:
4242
stage: deploy
4343
only:
44-
- /^\d+\.\d+(\.\d+)?([abc]\d*)?$/
44+
- /^v\d+\.\d+(\.\d+)?([abc]\d*)?$/
4545
script:
4646
- tox -e release

importlib_metadata/__init__.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
ModuleNotFoundError,
2828
MetaPathFinder,
2929
email_message_from_string,
30-
ensure_is_path,
3130
)
3231
from importlib import import_module
3332
from itertools import starmap
@@ -184,8 +183,7 @@ def from_name(cls, name):
184183
metadata cannot be found.
185184
"""
186185
for resolver in cls._discover_resolvers():
187-
context = DistributionFinder.Context(name=name)
188-
dists = cls._maybe_bind(resolver, context)
186+
dists = resolver(DistributionFinder.Context(name=name))
189187
dist = next(dists, None)
190188
if dist is not None:
191189
return dist
@@ -207,32 +205,18 @@ def discover(cls, **kwargs):
207205
raise ValueError("cannot accept context and kwargs")
208206
context = context or DistributionFinder.Context(**kwargs)
209207
return itertools.chain.from_iterable(
210-
cls._maybe_bind(resolver, context)
208+
resolver(context)
211209
for resolver in cls._discover_resolvers()
212210
)
213211

214-
@staticmethod
215-
def _maybe_bind(resolver, context):
216-
"""
217-
Only bind the context to the resolver if as a callable,
218-
the resolver accepts the context parameter.
219-
220-
Workaround for
221-
https://gitlab.com/python-devs/importlib_metadata/issues/86
222-
"""
223-
try: # pragma: nocover
224-
return resolver(context)
225-
except TypeError: # pragma: nocover
226-
return resolver(name=context.name, path=context.path)
227-
228212
@staticmethod
229213
def at(path):
230214
"""Return a Distribution for the indicated metadata path
231215
232216
:param path: a string or path-like object
233217
:return: a concrete Distribution instance for the path
234218
"""
235-
return PathDistribution(ensure_is_path(path))
219+
return PathDistribution(pathlib.Path(path))
236220

237221
@staticmethod
238222
def _discover_resolvers():

importlib_metadata/_compat.py

Lines changed: 25 additions & 10 deletions
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,
@@ -89,12 +113,3 @@ def py2_message_from_string(text): # nocoverpy3
89113

90114
# https://bitbucket.org/pypy/pypy/issues/3021/ioopen-directory-leaks-a-file-descriptor
91115
PYPY_OPEN_BUG = getattr(sys, 'pypy_version_info', (9, 9, 9))[:3] <= (7, 1, 1)
92-
93-
94-
def ensure_is_path(ob):
95-
"""Construct a Path from ob even if it's already one.
96-
Specialized for Python 3.4.
97-
"""
98-
if (3,) < sys.version_info < (3, 5):
99-
ob = str(ob) # pragma: nocover
100-
return pathlib.Path(ob)

importlib_metadata/docs/changelog.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22
importlib_metadata NEWS
33
=========================
44

5-
0.24
6-
====
5+
v1.1.0
6+
======
77

8+
* Dropped support for Python 3.4.
89
* EntryPoints are now pickleable. Closes #96.
910

11+
v1.0.0
12+
======
13+
14+
* Project adopts semver for versioning.
15+
16+
* Removed compatibility shim introduced in 0.23.
17+
18+
* For better compatibility with the stdlib implementation and to
19+
avoid the same distributions being discovered by the stdlib and
20+
backport implementations, the backport now disables the
21+
stdlib DistributionFinder during initialization (import time).
22+
Closes #91 and closes #100.
23+
1024
0.23
1125
====
1226
* Added a compatibility shim to prevent failures on beta releases

importlib_metadata/docs/index.rst

Lines changed: 4 additions & 3 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

@@ -50,4 +51,4 @@ Indices and tables
5051
.. _`metadata API`: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#metadata-api
5152
.. _`Python 3.7 and newer`: https://docs.python.org/3/library/importlib.html#module-importlib.resources
5253
.. _`importlib_resources`: https://importlib-resources.readthedocs.io/en/latest/index.html
53-
.. _`importlib.metadata`: TBD
54+
.. _`importlib.metadata`: https://docs.python.org/3/library/importlib.metadata.html

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ classifiers =
1515
Programming Language :: Python :: 2
1616

1717
[options]
18-
python_requires = >=2.7,!=3.0,!=3.1,!=3.2,!=3.3
18+
python_requires = >=2.7,!=3.0,!=3.1,!=3.2,!=3.3,!=3.4
1919
setup_requires = setuptools-scm
2020
install_requires =
2121
zipp>=0.5
22-
pathlib2; python_version=='3.4.*' or python_version < '3'
22+
pathlib2; python_version < '3'
2323
contextlib2; python_version < '3'
2424
configparser>=3.5; python_version < '3'
2525
packages = find:

tox.ini

Lines changed: 2 additions & 2 deletions
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

@@ -33,7 +33,7 @@ setenv =
3333
cov: COVERAGE_OPTIONS="-p"
3434
cov: COVERAGE_FILE={toxinidir}/.coverage
3535
py27: PYV=2
36-
py34,py35,py36,py37,py38: PYV=3
36+
py35,py36,py37,py38: PYV=3
3737
# workaround deprecation warnings in pip's vendored packages
3838
PYTHONWARNINGS=ignore:Using or importing the ABCs:DeprecationWarning:pip._vendor
3939
extras =

0 commit comments

Comments
 (0)