|
14 | 14 | import posixpath |
15 | 15 | import collections |
16 | 16 |
|
17 | | -from . import _adapters, _meta |
| 17 | +from . import _adapters, _meta, _py39compat |
18 | 18 | from ._collections import FreezableDefaultDict, Pair |
19 | 19 | from ._compat import ( |
20 | 20 | NullFinder, |
|
29 | 29 | from importlib import import_module |
30 | 30 | from importlib.abc import MetaPathFinder |
31 | 31 | from itertools import starmap |
32 | | -from typing import List, Mapping, Optional, Tuple, Union |
| 32 | +from typing import List, Mapping, Optional, Union |
33 | 33 |
|
34 | 34 |
|
35 | 35 | __all__ = [ |
@@ -382,8 +382,8 @@ def select(self, **params): |
382 | 382 | Select entry points from self that match the |
383 | 383 | given parameters (typically group and/or name). |
384 | 384 | """ |
385 | | - candidates = (_ep_matches(ep, **params) for ep in self) |
386 | | - return EntryPoints(ep for ep, ep_matches in candidates if ep_matches) |
| 385 | + candidates = (_py39compat.ep_matches(ep, **params) for ep in self) |
| 386 | + return EntryPoints(ep for ep, predicate in candidates if predicate) |
387 | 387 |
|
388 | 388 | @property |
389 | 389 | def names(self): |
@@ -415,15 +415,6 @@ def _from_text(text): |
415 | 415 | ) |
416 | 416 |
|
417 | 417 |
|
418 | | -def _ep_matches(ep: EntryPoint, **params) -> Tuple[EntryPoint, bool]: |
419 | | - """Compatibility layer for EntryPoint objects in Python 3.8/3.9 stdlib.""" |
420 | | - try: |
421 | | - return ep, ep.matches(**params) |
422 | | - except AttributeError: |
423 | | - _ep = EntryPoint(ep.name, ep.value, ep.group) |
424 | | - return _ep, _ep.matches(**params) |
425 | | - |
426 | | - |
427 | 418 | class Deprecated: |
428 | 419 | """ |
429 | 420 | Compatibility add-in for mapping to indicate that |
@@ -1029,21 +1020,9 @@ def version(distribution_name): |
1029 | 1020 | return distribution(distribution_name).version |
1030 | 1021 |
|
1031 | 1022 |
|
1032 | | -def _compat_normalized_name(dist: Distribution) -> Optional[str]: |
1033 | | - """ |
1034 | | - Compatibility shim to honor name normalization for distributions |
1035 | | - that don't provide ``_normalized_name`` |
1036 | | - (as in ``importlib.metadata`` for Python 3.8/3.9). |
1037 | | - """ |
1038 | | - try: |
1039 | | - return dist._normalized_name |
1040 | | - except AttributeError: |
1041 | | - return Prepared.normalize(getattr(dist, "name", None) or dist.metadata['Name']) |
1042 | | - |
1043 | | - |
1044 | 1023 | _unique = functools.partial( |
1045 | 1024 | unique_everseen, |
1046 | | - key=_compat_normalized_name, |
| 1025 | + key=_py39compat.normalized_name, |
1047 | 1026 | ) |
1048 | 1027 | """ |
1049 | 1028 | Wrapper for ``distributions`` to return unique distributions by name. |
|
0 commit comments