candidate.py 946 B

12345678910111213141516171819202122232425262728293031
  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. """
  7. __slots__ = ["name", "version", "link"]
  8. def __init__(self, name: str, version: str, link: Link) -> None:
  9. self.name = name
  10. self.version = parse_version(version)
  11. self.link = link
  12. super().__init__(
  13. key=(self.name, self.version, self.link),
  14. defining_class=InstallationCandidate
  15. )
  16. def __repr__(self) -> str:
  17. return "<InstallationCandidate({!r}, {!r}, {!r})>".format(
  18. self.name, self.version, self.link,
  19. )
  20. def __str__(self) -> str:
  21. return '{!r} candidate (version {} at {})'.format(
  22. self.name, self.version, self.link,
  23. )