base.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from pip._vendor.packaging.utils import canonicalize_name
  2. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  3. if MYPY_CHECK_RUNNING:
  4. from typing import Optional, Sequence, Set
  5. from pip._internal.req.req_install import InstallRequirement
  6. from pip._vendor.packaging.version import _BaseVersion
  7. def format_name(project, extras):
  8. # type: (str, Set[str]) -> str
  9. if not extras:
  10. return project
  11. canonical_extras = sorted(canonicalize_name(e) for e in extras)
  12. return "{}[{}]".format(project, ",".join(canonical_extras))
  13. class Requirement(object):
  14. @property
  15. def name(self):
  16. # type: () -> str
  17. raise NotImplementedError("Subclass should override")
  18. def find_matches(self):
  19. # type: () -> Sequence[Candidate]
  20. raise NotImplementedError("Subclass should override")
  21. def is_satisfied_by(self, candidate):
  22. # type: (Candidate) -> bool
  23. return False
  24. class Candidate(object):
  25. @property
  26. def name(self):
  27. # type: () -> str
  28. raise NotImplementedError("Override in subclass")
  29. @property
  30. def version(self):
  31. # type: () -> _BaseVersion
  32. raise NotImplementedError("Override in subclass")
  33. def get_dependencies(self):
  34. # type: () -> Sequence[Requirement]
  35. raise NotImplementedError("Override in subclass")
  36. def get_install_requirement(self):
  37. # type: () -> Optional[InstallRequirement]
  38. raise NotImplementedError("Override in subclass")