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