Skip to content

Commit

Permalink
Merge pull request #8727 from uranusjr/new-resolver-constraint-markers
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored Aug 7, 2020
2 parents 595aa7b + 4683ad0 commit d6d84e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/8724.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2020 Resolver: Correctly handle marker evaluation in constraints and exclude
them if their markers do not match the current environment.
3 changes: 2 additions & 1 deletion src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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
Expand Down
25 changes: 25 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import sys
import textwrap

import pytest
from pip._vendor.packaging.utils import canonicalize_name
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit d6d84e7

Please sign in to comment.