candidate.py 1.2 KB

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