candidate.py 1.1 KB

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