Allow constraining an explicit requirement

This commit is contained in:
Tzu-ping Chung 2020-11-04 00:29:19 +08:00
parent 9b3cd280fd
commit d589795834
2 changed files with 9 additions and 8 deletions

View File

@ -58,6 +58,13 @@ class Constraint(object):
hashes = self.hashes & other.hashes(trust_internet=False)
return Constraint(specifier, hashes)
def is_satisfied_by(self, candidate):
# type: (Candidate) -> bool
# We can safely always allow prereleases here since PackageFinder
# already implements the prerelease logic, and would have filtered out
# prerelease candidates if the user does not expect them.
return self.specifier.contains(candidate.version, prereleases=True)
class Requirement(object):
@property

View File

@ -235,16 +235,10 @@ class Factory(object):
prefers_installed,
)
if constraint:
name = explicit_candidates.pop().name
raise InstallationError(
"Could not satisfy constraints for {!r}: installation from "
"path or url cannot be constrained to a version".format(name)
)
return (
c for c in explicit_candidates
if all(req.is_satisfied_by(c) for req in requirements)
if constraint.is_satisfied_by(c)
and all(req.is_satisfied_by(c) for req in requirements)
)
def make_requirement_from_install_req(self, ireq, requested_extras):