mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 05:31:15 -07:00
Update importlib-metadata==5.0.0
[skip ci]
This commit is contained in:
parent
20be945e8c
commit
5bb9dbd0f6
3 changed files with 69 additions and 211 deletions
48
lib/importlib_metadata/_py39compat.py
Normal file
48
lib/importlib_metadata/_py39compat.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
"""
|
||||
Compatibility layer with Python 3.8/3.9
|
||||
"""
|
||||
from typing import TYPE_CHECKING, Any, Optional, Tuple
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
# Prevent circular imports on runtime.
|
||||
from . import Distribution, EntryPoint
|
||||
else:
|
||||
Distribution = EntryPoint = Any
|
||||
|
||||
|
||||
def normalized_name(dist: Distribution) -> Optional[str]:
|
||||
"""
|
||||
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 dist.metadata['Name'])
|
||||
|
||||
|
||||
def ep_matches(ep: EntryPoint, **params) -> Tuple[EntryPoint, bool]:
|
||||
"""
|
||||
Workaround for ``EntryPoint`` objects without the ``matches`` method.
|
||||
For the sake of convenience, a tuple is returned containing not only the
|
||||
boolean value corresponding to the predicate evalutation, but also a compatible
|
||||
``EntryPoint`` object that can be safely used at a later stage.
|
||||
|
||||
For example, the following sequences of expressions should be compatible:
|
||||
|
||||
# Sequence 1: using the compatibility layer
|
||||
candidates = (_py39compat.ep_matches(ep, **params) for ep in entry_points)
|
||||
[ep for ep, predicate in candidates if predicate]
|
||||
|
||||
# Sequence 2: using Python 3.9+
|
||||
[ep for ep in entry_points if ep.matches(**params)]
|
||||
"""
|
||||
try:
|
||||
return ep, ep.matches(**params)
|
||||
except AttributeError:
|
||||
from . import EntryPoint # -> delay to prevent circular imports.
|
||||
|
||||
# Reconstruct the EntryPoint object to make sure it is compatible.
|
||||
_ep = EntryPoint(ep.name, ep.value, ep.group)
|
||||
return _ep, _ep.matches(**params)
|
Loading…
Add table
Add a link
Reference in a new issue