Include Requires-Python dep even with --no-deps

This commit is contained in:
Tzu-ping Chung 2020-08-14 08:41:42 +08:00
parent 0b18e21cbe
commit 8b2b92485c
2 changed files with 41 additions and 15 deletions

View File

@ -230,31 +230,25 @@ class _InstallRequirementBackedCandidate(Candidate):
self._prepare()
return self._dist
def _get_requires_python_specifier(self):
# type: () -> Optional[SpecifierSet]
def _get_requires_python_dependency(self):
# type: () -> Optional[Requirement]
requires_python = get_requires_python(self.dist)
if requires_python is None:
return None
try:
spec = SpecifierSet(requires_python)
except InvalidSpecifier as e:
logger.warning(
"Package %r has an invalid Requires-Python: %s", self.name, e,
)
message = "Package %r has an invalid Requires-Python: %s"
logger.warning(message, self.name, e)
return None
return spec
return self._factory.make_requires_python_requirement(spec)
def iter_dependencies(self, with_requires):
# type: (bool) -> Iterable[Optional[Requirement]]
if not with_requires:
return
for r in self.dist.requires():
requires = self.dist.requires() if with_requires else ()
for r in requires:
yield self._factory.make_requirement_from_spec(str(r), self._ireq)
python_dep = self._factory.make_requires_python_requirement(
self._get_requires_python_specifier(),
)
if python_dep:
yield python_dep
yield self._get_requires_python_dependency()
def get_install_requirement(self):
# type: () -> Optional[InstallRequirement]
@ -285,7 +279,7 @@ class LinkCandidate(_InstallRequirementBackedCandidate):
wheel = Wheel(ireq.link.filename)
wheel_name = canonicalize_name(wheel.name)
assert name == wheel_name, (
"{!r} != {!r} for wheel".format(name, wheel_name)
"{!r} != {!r} for wheel".format(name, wheel_name)
)
# Version may not be present for PEP 508 direct URLs
if version is not None:

View File

@ -988,3 +988,35 @@ def test_new_resolver_local_and_req(script):
source_dir, "pkg!=0.1.0",
expect_error=True,
)
def test_new_resolver_no_deps_checks_requires_python(script):
create_basic_wheel_for_package(
script,
"base",
"0.1.0",
depends=["dep"],
requires_python="<2", # Something that always fails.
)
create_basic_wheel_for_package(
script,
"dep",
"0.2.0",
)
result = script.pip(
"install",
"--use-feature=2020-resolver",
"--no-cache-dir",
"--no-index",
"--no-deps",
"--find-links", script.scratch_path,
"base",
expect_error=True,
)
message = (
"Package 'base' requires a different Python: "
"{}.{}.{} not in '<2'".format(*sys.version_info[:3])
)
assert message in result.stderr