|
35 | 35 |
|
36 | 36 | # Avoid conflicting with the PyPI package "Python".
|
37 | 37 | REQUIRES_PYTHON_IDENTIFIER = cast(NormalizedName, "<Python from Requires-Python>")
|
| 38 | +# Avoid clashing with any package on PyPI, but remain parseable as a Requirement. This |
| 39 | +# should only be used for .as_serializable_requirement(). |
| 40 | +REQUIRES_PYTHON_SERIALIZABLE_IDENTIFIER = cast(NormalizedName, "Requires-Python") |
38 | 41 |
|
39 | 42 |
|
40 | 43 | def as_base_candidate(candidate: Candidate) -> Optional[BaseCandidate]:
|
@@ -160,7 +163,7 @@ def __init__(
|
160 | 163 | def __str__(self) -> str:
|
161 | 164 | return f"{self.name} {self.version}"
|
162 | 165 |
|
163 |
| - def as_requirement(self) -> PkgRequirement: |
| 166 | + def as_serializable_requirement(self) -> PkgRequirement: |
164 | 167 | return produce_exact_version_requirement(self.name, str(self.version))
|
165 | 168 |
|
166 | 169 | def __repr__(self) -> str:
|
@@ -371,6 +374,9 @@ def name(self) -> str:
|
371 | 374 | def version(self) -> CandidateVersion:
|
372 | 375 | return self.dist.version
|
373 | 376 |
|
| 377 | + def as_serializable_requirement(self) -> PkgRequirement: |
| 378 | + return self.dist.as_serializable_requirement() |
| 379 | + |
374 | 380 | @property
|
375 | 381 | def is_editable(self) -> bool:
|
376 | 382 | return self.dist.editable
|
@@ -453,6 +459,9 @@ def name(self) -> str:
|
453 | 459 | def version(self) -> CandidateVersion:
|
454 | 460 | return self.base.version
|
455 | 461 |
|
| 462 | + def as_serializable_requirement(self) -> PkgRequirement: |
| 463 | + return self.base.as_serializable_requirement() |
| 464 | + |
456 | 465 | def format_for_error(self) -> str:
|
457 | 466 | return "{} [{}]".format(
|
458 | 467 | self.base.format_for_error(), ", ".join(sorted(self.extras))
|
@@ -535,9 +544,10 @@ def name(self) -> str:
|
535 | 544 | def version(self) -> CandidateVersion:
|
536 | 545 | return self._version
|
537 | 546 |
|
538 |
| - def as_requirement(self) -> PkgRequirement: |
539 |
| - raise NotImplementedError("FIXME!!!") |
540 |
| - # return produce_exact_version_requirement(self.name, str(self.version)) |
| 547 | + def as_serializable_requirement(self) -> PkgRequirement: |
| 548 | + return produce_exact_version_requirement( |
| 549 | + REQUIRES_PYTHON_SERIALIZABLE_IDENTIFIER, str(self.version) |
| 550 | + ) |
541 | 551 |
|
542 | 552 | @property
|
543 | 553 | def is_editable(self) -> bool:
|
|
0 commit comments