blob: 9245747bf2bcdb281b9012eb84e184abe8c68070 [file] [log] [blame]
Pirama Arumuga Nainard285ad02022-02-08 09:26:56 -08001from pip._vendor.packaging.utils import canonicalize_name
2
3from pip._internal.utils.typing import MYPY_CHECK_RUNNING
4
5if MYPY_CHECK_RUNNING:
6 from typing import FrozenSet, Iterable, Optional, Tuple
7
8 from pip._vendor.packaging.version import _BaseVersion
9
10 from pip._internal.models.link import Link
11 from pip._internal.req.req_install import InstallRequirement
12
13 CandidateLookup = Tuple[
14 Optional["Candidate"],
15 Optional[InstallRequirement],
16 ]
17
18
19def format_name(project, extras):
20 # type: (str, FrozenSet[str]) -> str
21 if not extras:
22 return project
23 canonical_extras = sorted(canonicalize_name(e) for e in extras)
24 return "{}[{}]".format(project, ",".join(canonical_extras))
25
26
27class Requirement(object):
28 @property
29 def name(self):
30 # type: () -> str
31 raise NotImplementedError("Subclass should override")
32
33 def is_satisfied_by(self, candidate):
34 # type: (Candidate) -> bool
35 return False
36
37 def get_candidate_lookup(self):
38 # type: () -> CandidateLookup
39 raise NotImplementedError("Subclass should override")
40
41 def format_for_error(self):
42 # type: () -> str
43 raise NotImplementedError("Subclass should override")
44
45
46class Candidate(object):
47 @property
48 def name(self):
49 # type: () -> str
50 raise NotImplementedError("Override in subclass")
51
52 @property
53 def version(self):
54 # type: () -> _BaseVersion
55 raise NotImplementedError("Override in subclass")
56
57 @property
58 def is_installed(self):
59 # type: () -> bool
60 raise NotImplementedError("Override in subclass")
61
62 @property
63 def is_editable(self):
64 # type: () -> bool
65 raise NotImplementedError("Override in subclass")
66
67 @property
68 def source_link(self):
69 # type: () -> Optional[Link]
70 raise NotImplementedError("Override in subclass")
71
72 def iter_dependencies(self, with_requires):
73 # type: (bool) -> Iterable[Optional[Requirement]]
74 raise NotImplementedError("Override in subclass")
75
76 def get_install_requirement(self):
77 # type: () -> Optional[InstallRequirement]
78 raise NotImplementedError("Override in subclass")
79
80 def format_for_error(self):
81 # type: () -> str
82 raise NotImplementedError("Subclass should override")