Skip to content

Commit 7d22cb1

Browse files
Remove extras from user-supplied constraints in backtracking resolver (#1808)
Co-Authored-By: David Rodríguez <deivid.rodriguez@riseup.net>
1 parent bce5b24 commit 7d22cb1

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

piptools/resolver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ def resolve(self, max_rounds: int = 10) -> set[InstallRequirement]:
520520
), get_build_tracker() as build_tracker, global_tempdir_manager(), indent_log():
521521
# Mark direct/primary/user_supplied packages
522522
for ireq in self.constraints:
523+
if ireq.constraint:
524+
ireq.extras = set() # pip does not support extras in constraints
523525
ireq.user_supplied = True
524526

525527
# Pass compiled requirements from `requirements.txt`
@@ -535,7 +537,7 @@ def resolve(self, max_rounds: int = 10) -> set[InstallRequirement]:
535537
if not primary_ireq.specifier.contains(version, prereleases):
536538
continue
537539

538-
ireq.extras = set() # pip does not support extras in constraints
540+
ireq.extras = set()
539541
ireq.constraint = True
540542
ireq.user_supplied = False
541543
compatible_existing_constraints[key_from_ireq(ireq)] = ireq

tests/test_cli_compile.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,56 @@ def test_upgrade_packages_version_option_and_upgrade_no_existing_file(pip_conf,
939939
assert "small-fake-b==0.1" in out.stderr
940940

941941

942+
def test_upgrade_package_with_extra(runner, make_package, make_sdist, tmpdir):
943+
"""
944+
piptools ignores extras on --upgrade-package/-P items if already constrained.
945+
"""
946+
test_package_1 = make_package(
947+
"test_package_1", version="0.1", extras_require={"more": "test_package_2"}
948+
)
949+
test_package_2 = make_package(
950+
"test_package_2",
951+
version="0.1",
952+
)
953+
dists_dir = tmpdir / "dists"
954+
for pkg in (test_package_1, test_package_2):
955+
make_sdist(pkg, dists_dir)
956+
957+
# Constrain our requirement with an extra
958+
with open("requirements.in", "w") as req_in:
959+
req_in.write("test-package-1[more]")
960+
961+
# Run update on test-package-1[more] -- this should be equivalent
962+
# to running an update on test-package-1
963+
out = runner.invoke(
964+
cli,
965+
[
966+
"--output-file",
967+
"-",
968+
"--quiet",
969+
"--find-links",
970+
str(dists_dir),
971+
"--no-annotate",
972+
"--no-header",
973+
"--no-emit-options",
974+
"--no-build-isolation",
975+
"--upgrade-package",
976+
"test-package-1[more]",
977+
],
978+
)
979+
980+
assert out.exit_code == 0, out
981+
assert (
982+
dedent(
983+
"""\
984+
test-package-1[more]==0.1
985+
test-package-2==0.1
986+
"""
987+
)
988+
== out.stdout
989+
)
990+
991+
942992
def test_quiet_option(pip_conf, runner):
943993
with open("requirements.in", "w") as req_in:
944994
req_in.write("small-fake-a")

0 commit comments

Comments
 (0)