provider.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from pip._vendor.resolvelib.providers import AbstractProvider
  2. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  3. if MYPY_CHECK_RUNNING:
  4. from typing import Any, Optional, Sequence, Tuple, Union
  5. from pip._internal.req.req_install import InstallRequirement
  6. from .base import Requirement, Candidate
  7. from .factory import Factory
  8. class PipProvider(AbstractProvider):
  9. def __init__(
  10. self,
  11. factory, # type: Factory
  12. ignore_dependencies, # type: bool
  13. ):
  14. # type: (...) -> None
  15. self._factory = factory
  16. self._ignore_dependencies = ignore_dependencies
  17. def get_install_requirement(self, c):
  18. # type: (Candidate) -> Optional[InstallRequirement]
  19. return c.get_install_requirement()
  20. def identify(self, dependency):
  21. # type: (Union[Requirement, Candidate]) -> str
  22. return dependency.name
  23. def get_preference(
  24. self,
  25. resolution, # type: Optional[Candidate]
  26. candidates, # type: Sequence[Candidate]
  27. information # type: Sequence[Tuple[Requirement, Candidate]]
  28. ):
  29. # type: (...) -> Any
  30. # Use the "usual" value for now
  31. return len(candidates)
  32. def find_matches(self, requirement):
  33. # type: (Requirement) -> Sequence[Candidate]
  34. return requirement.find_matches()
  35. def is_satisfied_by(self, requirement, candidate):
  36. # type: (Requirement, Candidate) -> bool
  37. return requirement.is_satisfied_by(candidate)
  38. def get_dependencies(self, candidate):
  39. # type: (Candidate) -> Sequence[Requirement]
  40. if self._ignore_dependencies:
  41. return []
  42. return candidate.get_dependencies()