Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extras from user-supplied constraints in backtracking resolver #1808

Merged
4 changes: 3 additions & 1 deletion piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ def resolve(self, max_rounds: int = 10) -> set[InstallRequirement]:
), get_build_tracker() as build_tracker, global_tempdir_manager(), indent_log():
# Mark direct/primary/user_supplied packages
for ireq in self.constraints:
if ireq.constraint:
ireq.extras = set() # pip does not support extras in constraints
ireq.user_supplied = True

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

ireq.extras = set() # pip does not support extras in constraints
ireq.extras = set()
ireq.constraint = True
ireq.user_supplied = False
compatible_existing_constraints[key_from_ireq(ireq)] = ireq
Expand Down
23 changes: 23 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,29 @@ def test_upgrade_packages_version_option_and_upgrade_no_existing_file(pip_conf,
assert "small-fake-b==0.1" in out.stderr


def test_upgrade_package_with_extra(pip_conf, make_package, runner):
"""
piptools ignores extras on --upgrade-package/-P items if already constrained.
"""
package_with_extra = make_package(
"package_with_extra",
extras_require={
"extra": ["small-fake-a==0.1"],
},
)

with open("requirements.in", "w") as req_in:
req_in.write(f"{package_with_extra}[extra]")

out = runner.invoke(
cli, ["--no-annotate", "--upgrade-package", "package_with_extra[extra]"]
)

assert out.exit_code == 0
assert "package_with_extra" in out.stderr
assert "small-fake-a==" in out.stderr
thomdixon marked this conversation as resolved.
Show resolved Hide resolved


def test_quiet_option(pip_conf, runner):
with open("requirements.in", "w") as req_in:
req_in.write("small-fake-a")
Expand Down