|
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +from pip._vendor.packaging.requirements import Requirement as PkgRequirement |
1 | 4 | from pip._vendor.packaging.specifiers import SpecifierSet
|
2 | 5 | from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
3 | 6 |
|
@@ -29,6 +32,9 @@ def name(self) -> str:
|
29 | 32 | # No need to canonicalize - the candidate did this
|
30 | 33 | return self.candidate.name
|
31 | 34 |
|
| 35 | + def as_serializable_requirement(self) -> PkgRequirement: |
| 36 | + return self.candidate.as_serializable_requirement() |
| 37 | + |
32 | 38 | def format_for_error(self) -> str:
|
33 | 39 | return self.candidate.format_for_error()
|
34 | 40 |
|
@@ -77,6 +83,9 @@ def format_for_error(self) -> str:
|
77 | 83 |
|
78 | 84 | return ", ".join(parts[:-1]) + " and " + parts[-1]
|
79 | 85 |
|
| 86 | + def as_serializable_requirement(self) -> Optional[PkgRequirement]: |
| 87 | + return self._ireq.req |
| 88 | + |
80 | 89 | def get_candidate_lookup(self) -> CandidateLookup:
|
81 | 90 | return None, self._ireq
|
82 | 91 |
|
@@ -120,6 +129,9 @@ def name(self) -> str:
|
120 | 129 | def format_for_error(self) -> str:
|
121 | 130 | return str(self)
|
122 | 131 |
|
| 132 | + def as_serializable_requirement(self) -> PkgRequirement: |
| 133 | + return self._candidate.as_serializable_requirement() |
| 134 | + |
123 | 135 | def get_candidate_lookup(self) -> CandidateLookup:
|
124 | 136 | if self.specifier.contains(self._candidate.version, prereleases=True):
|
125 | 137 | return self._candidate, None
|
@@ -159,6 +171,9 @@ def name(self) -> str:
|
159 | 171 | def format_for_error(self) -> str:
|
160 | 172 | return str(self)
|
161 | 173 |
|
| 174 | + def as_serializable_requirement(self) -> Optional[PkgRequirement]: |
| 175 | + raise NotImplementedError() |
| 176 | + |
162 | 177 | def get_candidate_lookup(self) -> CandidateLookup:
|
163 | 178 | return None, None
|
164 | 179 |
|
|
0 commit comments