From cdeaed48d9c6281615e51792bd31e4b470b92e03 Mon Sep 17 00:00:00 2001 From: Thom Date: Fri, 3 Feb 2023 09:48:52 -0800 Subject: [PATCH 1/7] Remove extras from user-supplied constraints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: David Rodríguez --- piptools/resolver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/piptools/resolver.py b/piptools/resolver.py index 750e6c993..cd59da4b0 100644 --- a/piptools/resolver.py +++ b/piptools/resolver.py @@ -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` @@ -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 From 9128ad132a3febcba5e8170484e76bc8f00b103b Mon Sep 17 00:00:00 2001 From: Thom Date: Fri, 10 Feb 2023 09:44:26 -0800 Subject: [PATCH 2/7] Add test --- tests/test_cli_compile.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index a178aa1a4..e863494da 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -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_packages_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 + + def test_quiet_option(pip_conf, runner): with open("requirements.in", "w") as req_in: req_in.write("small-fake-a") From 78b5ce668a2c0022d1981f38dce950c6b59071be Mon Sep 17 00:00:00 2001 From: Thom Date: Fri, 10 Feb 2023 09:46:18 -0800 Subject: [PATCH 3/7] Plural --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index e863494da..68cd73a2b 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -939,7 +939,7 @@ 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_packages_with_extra(pip_conf, make_package, runner): +def test_upgrade_package_with_extra(pip_conf, make_package, runner): """ piptools ignores extras on --upgrade-package/-P items if already constrained. """ From 49f80ac4d563f972914b9489a2fdab95f7873270 Mon Sep 17 00:00:00 2001 From: Thom Date: Tue, 21 Feb 2023 10:02:47 -0800 Subject: [PATCH 4/7] Update test to use whole output --- tests/test_cli_compile.py | 48 ++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 68cd73a2b..6ca405ce9 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -939,27 +939,53 @@ 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): +def test_upgrade_package_with_extra(runner, make_package, make_sdist, tmpdir): """ 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"], - }, + test_package_1 = make_package( + "test_package_1", version="0.1", extras_require={"more": "test_package_2"} + ) + test_package_2 = make_package( + "test_package_2", + version="0.1", ) + dists_dir = tmpdir / "dists" + for pkg in (test_package_1, test_package_2): + make_sdist(pkg, dists_dir) + # Constrain our requirement with an extra with open("requirements.in", "w") as req_in: - req_in.write(f"{package_with_extra}[extra]") + req_in.write(f"test-package-1[more]") + # Run update on test-package-1[more] -- this should be equivalent to running update on test-package-1 out = runner.invoke( - cli, ["--no-annotate", "--upgrade-package", "package_with_extra[extra]"] + cli, + [ + "--output-file", + "-", + "--quiet", + "--find-links", + str(dists_dir), + "--no-annotate", + "--no-header", + "--no-emit-options", + "--no-build-isolation", + "--upgrade-package", + "test-package-1[more]" + ] ) - assert out.exit_code == 0 - assert "package_with_extra" in out.stderr - assert "small-fake-a==" in out.stderr + assert out.exit_code == 0, out + assert ( + dedent( + f"""\ + test-package-1[more]==0.1 + test-package-2==0.1 + """ + ) + == out.stdout + ) def test_quiet_option(pip_conf, runner): From 59217a18eca6f09416ebe46aa23952b3b6661963 Mon Sep 17 00:00:00 2001 From: Thom Date: Tue, 21 Feb 2023 10:07:05 -0800 Subject: [PATCH 5/7] Remove unneccesary format strings --- tests/test_cli_compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 6ca405ce9..b3fb17c1a 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -956,7 +956,7 @@ def test_upgrade_package_with_extra(runner, make_package, make_sdist, tmpdir): # Constrain our requirement with an extra with open("requirements.in", "w") as req_in: - req_in.write(f"test-package-1[more]") + req_in.write("test-package-1[more]") # Run update on test-package-1[more] -- this should be equivalent to running update on test-package-1 out = runner.invoke( @@ -979,7 +979,7 @@ def test_upgrade_package_with_extra(runner, make_package, make_sdist, tmpdir): assert out.exit_code == 0, out assert ( dedent( - f"""\ + """\ test-package-1[more]==0.1 test-package-2==0.1 """ From 68f63506b420c9dffc8137d398a8a71731a58f1c Mon Sep 17 00:00:00 2001 From: Thom Date: Tue, 21 Feb 2023 10:15:41 -0800 Subject: [PATCH 6/7] Formatting --- tests/test_cli_compile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index b3fb17c1a..76b46d5bc 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -972,8 +972,8 @@ def test_upgrade_package_with_extra(runner, make_package, make_sdist, tmpdir): "--no-emit-options", "--no-build-isolation", "--upgrade-package", - "test-package-1[more]" - ] + "test-package-1[more]", + ], ) assert out.exit_code == 0, out From 2d225def4df0ecaab5b053b903c14b659ae5e2ba Mon Sep 17 00:00:00 2001 From: Thom Date: Tue, 21 Feb 2023 10:45:32 -0800 Subject: [PATCH 7/7] Formatting comment --- tests/test_cli_compile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 76b46d5bc..186c363f9 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -958,7 +958,8 @@ def test_upgrade_package_with_extra(runner, make_package, make_sdist, tmpdir): with open("requirements.in", "w") as req_in: req_in.write("test-package-1[more]") - # Run update on test-package-1[more] -- this should be equivalent to running update on test-package-1 + # Run update on test-package-1[more] -- this should be equivalent + # to running an update on test-package-1 out = runner.invoke( cli, [