-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathpy39.py
42 lines (32 loc) · 1.16 KB
/
py39.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Compatibility layer with Python 3.8/3.9
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING: # pragma: no cover
# Prevent circular imports on runtime.
from .. import Distribution, EntryPoint
else:
Distribution = EntryPoint = Any
from .._typing import md_none
def normalized_name(dist: Distribution) -> str | None:
"""
Honor name normalization for distributions that don't provide ``_normalized_name``.
"""
try:
return dist._normalized_name
except AttributeError:
from .. import Prepared # -> delay to prevent circular imports.
return Prepared.normalize(
getattr(dist, "name", None) or md_none(dist.metadata)['Name']
)
def ep_matches(ep: EntryPoint, **params) -> bool:
"""
Workaround for ``EntryPoint`` objects without the ``matches`` method.
"""
try:
return ep.matches(**params)
except AttributeError:
from .. import EntryPoint # -> delay to prevent circular imports.
# Reconstruct the EntryPoint object to make sure it is compatible.
return EntryPoint(ep.name, ep.value, ep.group).matches(**params)