Skip to content

Commit 06e03e9

Browse files
committed
1 parent add5f5a commit 06e03e9

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--- setuptools/_vendor/importlib_metadata/__init__.py.orig 2024-09-17 03:55:02 UTC
2+
+++ setuptools/_vendor/importlib_metadata/__init__.py
3+
@@ -14,7 +14,7 @@ import collections
4+
import posixpath
5+
import collections
6+
7+
-from . import _adapters, _meta
8+
+from . import _adapters, _meta, _py39compat
9+
from ._collections import FreezableDefaultDict, Pair
10+
from ._compat import (
11+
NullFinder,
12+
@@ -180,6 +180,10 @@ class EntryPoint(DeprecatedTuple):
13+
following the attr, and following any extras.
14+
"""
15+
16+
+ name: str
17+
+ value: str
18+
+ group: str
19+
+
20+
dist: Optional['Distribution'] = None
21+
22+
def __init__(self, name, value, group):
23+
@@ -350,7 +354,8 @@ class EntryPoints(DeprecatedList):
24+
Select entry points from self that match the
25+
given parameters (typically group and/or name).
26+
"""
27+
- return EntryPoints(ep for ep in self if ep.matches(**params))
28+
+ candidates = (_py39compat.ep_matches(ep, **params) for ep in self)
29+
+ return EntryPoints(ep for ep, predicate in candidates if predicate)
30+
31+
@property
32+
def names(self):
33+
@@ -991,7 +996,7 @@ def entry_points(**params) -> Union[EntryPoints, Selec
34+
35+
:return: EntryPoints or SelectableGroups for all installed packages.
36+
"""
37+
- norm_name = operator.attrgetter('_normalized_name')
38+
+ norm_name = _py39compat.normalized_name
39+
unique = functools.partial(unique_everseen, key=norm_name)
40+
eps = itertools.chain.from_iterable(
41+
dist.entry_points for dist in unique(distributions())
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)