Skip to content

Commit

Permalink
re-resolve dependencies of combined install_requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuyi Xue committed Oct 17, 2021
1 parent eb9162f commit 98c8060
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def combine_install_requirements(

# deepcopy the accumulator so as to not modify the inputs
combined_ireq = copy.deepcopy(source_ireqs[0])
# combined install_requirement needs to be prepared again, i.e. to have its
# dependencies be resolved again.
combined_ireq.prepared = False

for ireq in source_ireqs[1:]:
# NOTE we may be losing some info on dropped reqs here
Expand Down
64 changes: 64 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,70 @@ def test_combine_extras(pip_conf, runner, make_package):
assert "small-fake-b==" in out.stderr


def test_combine_different_extras_of_the_same_package(
pip_conf, runner, tmpdir, make_package, make_wheel
):
"""
Loosely based on the example from https://github.com/jazzband/pip-tools/issues/1511.
"""
pkgs = [
make_package(
"fake-colorful",
version="0.3",
),
make_package(
"fake-tensorboardX",
version="0.5",
),
make_package(
"fake-ray",
version="0.1",
extras_require={
"default": ["fake-colorful==0.3"],
"tune": ["fake-tensorboardX==0.5"],
},
),
make_package(
"fake-tune-sklearn",
version="0.7",
install_requires=[
"fake-ray[tune]==0.1",
],
),
]

dists_dir = tmpdir / "dists"
for pkg in pkgs:
make_wheel(pkg, dists_dir)

with open("requirements.in", "w") as req_in:
req_in.writelines(
[
f"fake-ray[default]==0.1\n",
"fake-tune-sklearn==0.7\n",
]
)

out = runner.invoke(cli, ["--find-links", str(dists_dir)])

assert out.exit_code == 0
assert (
"""\
fake-colorful==0.3
# via fake-ray
fake-ray[default,tune]==0.1
# via
# -r requirements.in
# fake-tune-sklearn
fake-tensorboardx==0.5
# via fake-ray
fake-tune-sklearn==0.7
# via -r requirements.in
"""
in out.stderr
)


@pytest.mark.parametrize(
("pkg2_install_requires", "req_in_content", "out_expected_content"),
(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ def test_combine_install_requirements_extras_no_req(
)


def test_combine_install_requirements_with_multiple_extras_reset_prepared(repository, from_line):
"""Regression test for https://github.com/jazzband/pip-tools/pull/1512/files."""
pkg1 = from_line("ray[default]==1.1.1")
pkg1.prepared = True
pkg2 = from_line("ray[tune]==1.1.1")
combined = combine_install_requirements(repository, [pkg1, pkg2])

assert str(combined) == 'ray[default,tune]==1.1.1'
assert combined.prepared is False

def test_compile_failure_shows_provenance(resolver, from_line):
"""
Provenance of conflicting dependencies should be printed on failure.
Expand Down

0 comments on commit 98c8060

Please sign in to comment.