mirror of https://github.com/pypa/pip
cleanups
This commit is contained in:
parent
49159c314c
commit
6e62169ee7
|
@ -102,6 +102,7 @@ class Distribution(BaseDistribution):
|
|||
self._dist = dist
|
||||
self._info_location = info_location
|
||||
self._installed_location = installed_location
|
||||
self._cached_canonical_name: Optional[NormalizedName] = None
|
||||
|
||||
@classmethod
|
||||
def from_directory(cls, directory: str) -> BaseDistribution:
|
||||
|
@ -169,8 +170,10 @@ class Distribution(BaseDistribution):
|
|||
|
||||
@property
|
||||
def canonical_name(self) -> NormalizedName:
|
||||
name = self._get_dist_name_from_location() or get_dist_name(self._dist)
|
||||
return canonicalize_name(name)
|
||||
if self._cached_canonical_name is None:
|
||||
name = self._get_dist_name_from_location() or get_dist_name(self._dist)
|
||||
self._cached_canonical_name = canonicalize_name(name)
|
||||
return self._cached_canonical_name
|
||||
|
||||
@property
|
||||
def version(self) -> DistributionVersion:
|
||||
|
|
|
@ -7,7 +7,7 @@ import re
|
|||
from typing import FrozenSet, NewType, Tuple, Union, cast
|
||||
|
||||
from .tags import Tag, parse_tag
|
||||
from .version import InvalidVersion, Version
|
||||
from .version import parse_version, InvalidVersion, Version
|
||||
|
||||
BuildTag = Union[Tuple[()], Tuple[int, str]]
|
||||
NormalizedName = NewType("NormalizedName", str)
|
||||
|
@ -30,6 +30,7 @@ _canonicalize_regex = re.compile(r"[-_.]+")
|
|||
_build_tag_regex = re.compile(r"(\d+)(.*)")
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=4096)
|
||||
def canonicalize_name(name: str) -> NormalizedName:
|
||||
# This is taken from PEP 503.
|
||||
value = _canonicalize_regex.sub("-", name).lower()
|
||||
|
@ -44,7 +45,7 @@ def canonicalize_version(version: Union[Version, str]) -> str:
|
|||
"""
|
||||
if isinstance(version, str):
|
||||
try:
|
||||
parsed = Version(version)
|
||||
parsed = parse_version(version)
|
||||
except InvalidVersion:
|
||||
# Legacy versions cannot be normalized
|
||||
return version
|
||||
|
|
Loading…
Reference in New Issue