diff --git a/news/8724.bugfix b/news/8724.bugfix new file mode 100644 index 00000000000..8641098dde6 --- /dev/null +++ b/news/8724.bugfix @@ -0,0 +1,2 @@ +2020 Resolver: Correctly handle marker evaluation in constraints and exclude +them if their markers do not match the current environment. diff --git a/src/pip/_internal/resolution/resolvelib/resolver.py b/src/pip/_internal/resolution/resolvelib/resolver.py index 43ea248632d..aecddb1138c 100644 --- a/src/pip/_internal/resolution/resolvelib/resolver.py +++ b/src/pip/_internal/resolution/resolvelib/resolver.py @@ -90,7 +90,8 @@ def resolve(self, root_reqs, check_supported_wheels): problem = check_invalid_constraint_type(req) if problem: raise InstallationError(problem) - + if not req.match_markers(): + continue name = canonicalize_name(req.name) if name in constraints: constraints[name] = constraints[name] & req.specifier diff --git a/tests/functional/test_new_resolver.py b/tests/functional/test_new_resolver.py index 9329180334c..46e32ddd3d7 100644 --- a/tests/functional/test_new_resolver.py +++ b/tests/functional/test_new_resolver.py @@ -1,6 +1,7 @@ import json import os import sys +import textwrap import pytest from pip._vendor.packaging.utils import canonicalize_name @@ -729,6 +730,30 @@ def test_new_resolver_constraint_on_path(script): assert msg in result.stderr, str(result) +def test_new_resolver_constraint_only_marker_match(script): + create_basic_wheel_for_package(script, "pkg", "1.0") + create_basic_wheel_for_package(script, "pkg", "2.0") + create_basic_wheel_for_package(script, "pkg", "3.0") + + constrants_content = textwrap.dedent( + """ + pkg==1.0; python_version == "{ver[0]}.{ver[1]}" # Always satisfies. + pkg==2.0; python_version < "0" # Never satisfies. + """ + ).format(ver=sys.version_info) + constraints_txt = script.scratch_path / "constraints.txt" + constraints_txt.write_text(constrants_content) + + script.pip( + "install", "--use-feature=2020-resolver", + "--no-cache-dir", "--no-index", + "-c", constraints_txt, + "--find-links", script.scratch_path, + "pkg", + ) + assert_installed(script, pkg="1.0") + + def test_new_resolver_upgrade_needs_option(script): # Install pkg 1.0.0 create_basic_wheel_for_package(script, "pkg", "1.0.0")