mirror of https://github.com/pypa/pip
add type annotations for pip._internal.models (#6065)
This commit is contained in:
parent
7ee388178a
commit
410072bc8b
|
@ -1,6 +1,12 @@
|
|||
from pip._vendor.packaging.version import parse as parse_version
|
||||
|
||||
from pip._internal.utils.models import KeyBasedCompareMixin
|
||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from pip._vendor.packaging.version import _BaseVersion # noqa: F401
|
||||
from pip._internal.models.link import Link # noqa: F401
|
||||
from typing import Any, Union # noqa: F401
|
||||
|
||||
|
||||
class InstallationCandidate(KeyBasedCompareMixin):
|
||||
|
@ -8,8 +14,9 @@ class InstallationCandidate(KeyBasedCompareMixin):
|
|||
"""
|
||||
|
||||
def __init__(self, project, version, location):
|
||||
# type: (Any, str, Link) -> None
|
||||
self.project = project
|
||||
self.version = parse_version(version)
|
||||
self.version = parse_version(version) # type: _BaseVersion
|
||||
self.location = location
|
||||
|
||||
super(InstallationCandidate, self).__init__(
|
||||
|
@ -18,6 +25,7 @@ class InstallationCandidate(KeyBasedCompareMixin):
|
|||
)
|
||||
|
||||
def __repr__(self):
|
||||
# type: () -> str
|
||||
return "<InstallationCandidate({!r}, {!r}, {!r})>".format(
|
||||
self.project, self.version, self.location,
|
||||
)
|
||||
|
|
|
@ -6,6 +6,7 @@ class PackageIndex(object):
|
|||
"""
|
||||
|
||||
def __init__(self, url, file_storage_domain):
|
||||
# type: (str, str) -> None
|
||||
super(PackageIndex, self).__init__()
|
||||
self.url = url
|
||||
self.netloc = urllib_parse.urlsplit(url).netloc
|
||||
|
@ -18,6 +19,7 @@ class PackageIndex(object):
|
|||
self.file_storage_domain = file_storage_domain
|
||||
|
||||
def _url_for_path(self, path):
|
||||
# type: (str) -> str
|
||||
return urllib_parse.urljoin(self.url, path)
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,11 @@ from pip._internal.utils.misc import (
|
|||
WHEEL_EXTENSION, redact_password_from_url, splitext,
|
||||
)
|
||||
from pip._internal.utils.models import KeyBasedCompareMixin
|
||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from typing import Optional, Tuple, Union, Text # noqa: F401
|
||||
from pip._internal.index import HTMLPage # noqa: F401
|
||||
|
||||
|
||||
class Link(KeyBasedCompareMixin):
|
||||
|
@ -15,6 +20,7 @@ class Link(KeyBasedCompareMixin):
|
|||
"""
|
||||
|
||||
def __init__(self, url, comes_from=None, requires_python=None):
|
||||
# type: (str, Optional[Union[str, HTMLPage]], Optional[str]) -> None
|
||||
"""
|
||||
url:
|
||||
url of the resource pointed to (href of the link)
|
||||
|
@ -55,6 +61,7 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def filename(self):
|
||||
# type: () -> str
|
||||
_, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
|
||||
name = posixpath.basename(path.rstrip('/')) or netloc
|
||||
name = urllib_parse.unquote(name)
|
||||
|
@ -63,25 +70,31 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def scheme(self):
|
||||
# type: () -> str
|
||||
return urllib_parse.urlsplit(self.url)[0]
|
||||
|
||||
@property
|
||||
def netloc(self):
|
||||
# type: () -> str
|
||||
return urllib_parse.urlsplit(self.url)[1]
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
# type: () -> str
|
||||
return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
|
||||
|
||||
def splitext(self):
|
||||
# type: () -> Tuple[str, str]
|
||||
return splitext(posixpath.basename(self.path.rstrip('/')))
|
||||
|
||||
@property
|
||||
def ext(self):
|
||||
# type: () -> str
|
||||
return self.splitext()[1]
|
||||
|
||||
@property
|
||||
def url_without_fragment(self):
|
||||
# type: () -> str
|
||||
scheme, netloc, path, query, fragment = urllib_parse.urlsplit(self.url)
|
||||
return urllib_parse.urlunsplit((scheme, netloc, path, query, None))
|
||||
|
||||
|
@ -89,6 +102,7 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def egg_fragment(self):
|
||||
# type: () -> Optional[str]
|
||||
match = self._egg_fragment_re.search(self.url)
|
||||
if not match:
|
||||
return None
|
||||
|
@ -98,6 +112,7 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def subdirectory_fragment(self):
|
||||
# type: () -> Optional[str]
|
||||
match = self._subdirectory_fragment_re.search(self.url)
|
||||
if not match:
|
||||
return None
|
||||
|
@ -109,6 +124,7 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def hash(self):
|
||||
# type: () -> Optional[str]
|
||||
match = self._hash_re.search(self.url)
|
||||
if match:
|
||||
return match.group(2)
|
||||
|
@ -116,6 +132,7 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def hash_name(self):
|
||||
# type: () -> Optional[str]
|
||||
match = self._hash_re.search(self.url)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
@ -123,14 +140,17 @@ class Link(KeyBasedCompareMixin):
|
|||
|
||||
@property
|
||||
def show_url(self):
|
||||
# type: () -> Optional[str]
|
||||
return posixpath.basename(self.url.split('#', 1)[0].split('?', 1)[0])
|
||||
|
||||
@property
|
||||
def is_wheel(self):
|
||||
# type: () -> bool
|
||||
return self.ext == WHEEL_EXTENSION
|
||||
|
||||
@property
|
||||
def is_artifact(self):
|
||||
# type: () -> bool
|
||||
"""
|
||||
Determines if this points to an actual artifact (e.g. a tarball) or if
|
||||
it points to an "abstract" thing like a path or a VCS location.
|
||||
|
|
Loading…
Reference in New Issue