Make a proper get_install_requirement method for candidates

This commit is contained in:
Paul Moore 2020-03-25 11:41:33 +00:00
parent 653bac26c9
commit 76de49bc24
3 changed files with 9 additions and 9 deletions

View File

@ -46,3 +46,7 @@ class Candidate(object):
def get_dependencies(self):
# type: () -> Sequence[InstallRequirement]
raise NotImplementedError("Override in subclass")
def get_install_requirement(self):
# type: () -> InstallRequirement
raise NotImplementedError("Override in subclass")

View File

@ -124,3 +124,7 @@ class LinkCandidate(Candidate):
self._make_install_req(str(r), self._ireq)
for r in self.dist.requires()
]
def get_install_requirement(self):
# type: () -> InstallRequirement
return self._ireq

View File

@ -38,15 +38,7 @@ class PipProvider(AbstractProvider):
def get_install_requirement(self, c):
# type: (Candidate) -> InstallRequirement
# The base Candidate class does not have an _ireq attribute, so we
# fetch it dynamically here, to satisfy mypy. In practice, though, we
# only ever deal with LinkedCandidate objects at the moment, which do
# have an _ireq attribute. When we have a candidate type for installed
# requirements we should probably review this.
#
# TODO: Longer term, make a proper interface for this on the candidate.
return getattr(c, "_ireq", None)
return c.get_install_requirement()
def identify(self, dependency):
# type: (Union[Requirement, Candidate]) -> str