candidate.py 990 B

12345678910111213141516171819202122232425262728293031323334
  1. from pip._vendor.packaging.version import parse as parse_version
  2. from pip._internal.models.link import Link
  3. from pip._internal.utils.models import KeyBasedCompareMixin
  4. class InstallationCandidate(KeyBasedCompareMixin):
  5. """Represents a potential "candidate" for installation."""
  6. __slots__ = ["name", "version", "link"]
  7. def __init__(self, name: str, version: str, link: Link) -> None:
  8. self.name = name
  9. self.version = parse_version(version)
  10. self.link = link
  11. super().__init__(
  12. key=(self.name, self.version, self.link),
  13. defining_class=InstallationCandidate,
  14. )
  15. def __repr__(self) -> str:
  16. return "<InstallationCandidate({!r}, {!r}, {!r})>".format(
  17. self.name,
  18. self.version,
  19. self.link,
  20. )
  21. def __str__(self) -> str:
  22. return "{!r} candidate (version {} at {})".format(
  23. self.name,
  24. self.version,
  25. self.link,
  26. )