Skip to content

Commit d6d84e7

Browse files
authored
Merge pull request #8727 from uranusjr/new-resolver-constraint-markers
2 parents 595aa7b + 4683ad0 commit d6d84e7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

news/8724.bugfix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2020 Resolver: Correctly handle marker evaluation in constraints and exclude
2+
them if their markers do not match the current environment.

src/pip/_internal/resolution/resolvelib/resolver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def resolve(self, root_reqs, check_supported_wheels):
8080
problem = check_invalid_constraint_type(req)
8181
if problem:
8282
raise InstallationError(problem)
83-
83+
if not req.match_markers():
84+
continue
8485
name = canonicalize_name(req.name)
8586
if name in constraints:
8687
constraints[name] = constraints[name] & req.specifier

tests/functional/test_new_resolver.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import sys
4+
import textwrap
45

56
import pytest
67
from pip._vendor.packaging.utils import canonicalize_name
@@ -729,6 +730,30 @@ def test_new_resolver_constraint_on_path(script):
729730
assert msg in result.stderr, str(result)
730731

731732

733+
def test_new_resolver_constraint_only_marker_match(script):
734+
create_basic_wheel_for_package(script, "pkg", "1.0")
735+
create_basic_wheel_for_package(script, "pkg", "2.0")
736+
create_basic_wheel_for_package(script, "pkg", "3.0")
737+
738+
constrants_content = textwrap.dedent(
739+
"""
740+
pkg==1.0; python_version == "{ver[0]}.{ver[1]}" # Always satisfies.
741+
pkg==2.0; python_version < "0" # Never satisfies.
742+
"""
743+
).format(ver=sys.version_info)
744+
constraints_txt = script.scratch_path / "constraints.txt"
745+
constraints_txt.write_text(constrants_content)
746+
747+
script.pip(
748+
"install", "--use-feature=2020-resolver",
749+
"--no-cache-dir", "--no-index",
750+
"-c", constraints_txt,
751+
"--find-links", script.scratch_path,
752+
"pkg",
753+
)
754+
assert_installed(script, pkg="1.0")
755+
756+
732757
def test_new_resolver_upgrade_needs_option(script):
733758
# Install pkg 1.0.0
734759
create_basic_wheel_for_package(script, "pkg", "1.0.0")

0 commit comments

Comments
 (0)