|
| 1 | +--- setuptools/_vendor/importlib_metadata/_py39compat.py.orig 2024-09-17 04:01:17 UTC |
| 2 | ++++ setuptools/_vendor/importlib_metadata/_py39compat.py |
| 3 | +@@ -0,0 +1,48 @@ |
| 4 | ++""" |
| 5 | ++Compatibility layer with Python 3.8/3.9 |
| 6 | ++""" |
| 7 | ++from typing import TYPE_CHECKING, Any, Optional, Tuple |
| 8 | ++ |
| 9 | ++if TYPE_CHECKING: # pragma: no cover |
| 10 | ++ # Prevent circular imports on runtime. |
| 11 | ++ from . import Distribution, EntryPoint |
| 12 | ++else: |
| 13 | ++ Distribution = EntryPoint = Any |
| 14 | ++ |
| 15 | ++ |
| 16 | ++def normalized_name(dist: Distribution) -> Optional[str]: |
| 17 | ++ """ |
| 18 | ++ Honor name normalization for distributions that don't provide ``_normalized_name``. |
| 19 | ++ """ |
| 20 | ++ try: |
| 21 | ++ return dist._normalized_name |
| 22 | ++ except AttributeError: |
| 23 | ++ from . import Prepared # -> delay to prevent circular imports. |
| 24 | ++ |
| 25 | ++ return Prepared.normalize(getattr(dist, "name", None) or dist.metadata['Name']) |
| 26 | ++ |
| 27 | ++ |
| 28 | ++def ep_matches(ep: EntryPoint, **params) -> Tuple[EntryPoint, bool]: |
| 29 | ++ """ |
| 30 | ++ Workaround for ``EntryPoint`` objects without the ``matches`` method. |
| 31 | ++ For the sake of convenience, a tuple is returned containing not only the |
| 32 | ++ boolean value corresponding to the predicate evalutation, but also a compatible |
| 33 | ++ ``EntryPoint`` object that can be safely used at a later stage. |
| 34 | ++ |
| 35 | ++ For example, the following sequences of expressions should be compatible: |
| 36 | ++ |
| 37 | ++ # Sequence 1: using the compatibility layer |
| 38 | ++ candidates = (_py39compat.ep_matches(ep, **params) for ep in entry_points) |
| 39 | ++ [ep for ep, predicate in candidates if predicate] |
| 40 | ++ |
| 41 | ++ # Sequence 2: using Python 3.9+ |
| 42 | ++ [ep for ep in entry_points if ep.matches(**params)] |
| 43 | ++ """ |
| 44 | ++ try: |
| 45 | ++ return ep, ep.matches(**params) |
| 46 | ++ except AttributeError: |
| 47 | ++ from . import EntryPoint # -> delay to prevent circular imports. |
| 48 | ++ |
| 49 | ++ # Reconstruct the EntryPoint object to make sure it is compatible. |
| 50 | ++ _ep = EntryPoint(ep.name, ep.value, ep.group) |
| 51 | ++ return _ep, _ep.matches(**params) |
0 commit comments