Pip: New resolver: Code to reject constraints isn't working?

Created on 25 Apr 2020  路  7Comments  路  Source: pypa/pip

Environment

  • pip version: master
  • Python version: 3.8
  • OS: Windows 10

Description
The following test should fail with the new resolver, as constraints are not yet implemented (see here). However, it seems to be passing...

def test_new_resolver_constraints(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")
    constraints_file = script.scratch_path / "constraints.txt"
    constraints_file.write_text("pkg<2.0")
    script.pip(
        "install", "--unstable-feature=resolver",
        "--no-cache-dir", "--no-index",
        "--find-links", script.scratch_path,
        "-c", constraints_file,
        "pkg"
    )
    assert_installed(script, pkg="1.0")

Have I messed up my test, or is the new resolver not correctly rejecting constraints? (The test success suggests that the constraint is being treated as a "normal" requirement).

Expected behavior
The test should fail.

Additional context
I have an implementation of constraints for the new resolver, but it appears that the detection of constraints that we're using isn't correct...?

@pradyunsg @uranusjr What dumb mistake am I making here?

constraint new resolver bug

Most helpful comment

... although now I'm wondering if we need to fix #8061 before we have a meaningful way of testing constraints.

(Let's worry about that later 馃檪)

All 7 comments

My guess is #8061. RequirementSet merges requirement lines with the same name, so the constraint got merged before they reach the resolver.

Oddly, if I change the constraints to

constraints_file.write_text("pkg<2.0\nconstraint_only<1.0")

the test fails as expected. Adding that plus

assert_not_installed(script, "constraint_only")

is actually a better test, so maybe this isn't worth worrying about...

@uranusjr Yeah, that probably answers it.

... although now I'm wondering if we need to fix #8061 before we have a meaningful way of testing constraints.

(Let's worry about that later 馃檪)

I think this got fixed with #8061. One of us should check if that's the case. :)

Well, the test Paul attached is already in master, and it鈥檚 passing just fine, so yeah.

I鈥檓 posting a PR so both test variants in this issue are covered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nijel picture nijel  路  79Comments

dstufft picture dstufft  路  170Comments

jeanlaroche picture jeanlaroche  路  89Comments

HenrikOssipoff picture HenrikOssipoff  路  94Comments

qwcode picture qwcode  路  89Comments