base.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 FrozenSet, Iterable, Optional, Tuple
  5. from pip._vendor.packaging.version import _BaseVersion
  6. from pip._internal.models.link import Link
  7. from pip._internal.req.req_install import InstallRequirement
  8. CandidateLookup = Tuple[
  9. Optional["Candidate"],
  10. Optional[InstallRequirement],
  11. ]
  12. def format_name(project, extras):
  13. # type: (str, FrozenSet[str]) -> str
  14. if not extras:
  15. return project
  16. canonical_extras = sorted(canonicalize_name(e) for e in extras)
  17. return "{}[{}]".format(project, ",".join(canonical_extras))
  18. class Requirement(object):
  19. @property
  20. def name(self):
  21. # type: () -> str
  22. raise NotImplementedError("Subclass should override")
  23. def is_satisfied_by(self, candidate):
  24. # type: (Candidate) -> bool
  25. return False
  26. def get_candidate_lookup(self):
  27. # type: () -> CandidateLookup
  28. raise NotImplementedError("Subclass should override")
  29. def format_for_error(self):
  30. # type: () -> str
  31. raise NotImplementedError("Subclass should override")
  32. class Candidate(object):
  33. @property
  34. def name(self):
  35. # type: () -> str
  36. raise NotImplementedError("Override in subclass")
  37. @property
  38. def version(self):
  39. # type: () -> _BaseVersion
  40. raise NotImplementedError("Override in subclass")
  41. @property
  42. def is_installed(self):
  43. # type: () -> bool
  44. raise NotImplementedError("Override in subclass")
  45. @property
  46. def is_editable(self):
  47. # type: () -> bool
  48. raise NotImplementedError("Override in subclass")
  49. @property
  50. def source_link(self):
  51. # type: () -> Optional[Link]
  52. raise NotImplementedError("Override in subclass")
  53. def iter_dependencies(self, with_requires):
  54. # type: (bool) -> Iterable[Optional[Requirement]]
  55. raise NotImplementedError("Override in subclass")
  56. def get_install_requirement(self):
  57. # type: () -> Optional[InstallRequirement]
  58. raise NotImplementedError("Override in subclass")
  59. def format_for_error(self):
  60. # type: () -> str
  61. raise NotImplementedError("Subclass should override")