From a27a8f72c3e466d2f324491d8640f374b89d758e Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 30 Jun 2022 15:06:05 +0200 Subject: [PATCH 1/5] Fix compile cached vcs package --- piptools/resolver.py | 10 +++++++++- piptools/scripts/compile.py | 3 ++- tests/test_cli_compile.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/piptools/resolver.py b/piptools/resolver.py index f9d3d1250..3f4342e5c 100644 --- a/piptools/resolver.py +++ b/piptools/resolver.py @@ -761,9 +761,17 @@ def _get_install_requirement_from_candidate( version_pin_operator = "===" break + # Prepare extra kwargs for pinned install requirement. + pinned_ireq_kwargs = {} + if candidate.source_link is not None: + # InstallRequirement.link after dependency resolution might contain + # a link to a cached wheel, see GH-1647 for details. Override the link + # with the candidate's source link. + pinned_ireq_kwargs["link"] = candidate.source_link + # Prepare pinned install requirement. Copy it from candidate's install # requirement so that it could be mutated later. - pinned_ireq = copy_install_requirement(ireq) + pinned_ireq = copy_install_requirement(ireq, **pinned_ireq_kwargs) # Canonicalize name assert ireq.name is not None diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 0c98c6b2d..b83df70e3 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -6,7 +6,6 @@ from typing import IO, Any, BinaryIO, List, Optional, Tuple, Union, cast import click -from build import BuildBackendException from build.util import project_wheel_metadata from click.utils import LazyFile, safecall from pip._internal.commands import create_command @@ -14,6 +13,8 @@ from pip._internal.req.constructors import install_req_from_line from pip._internal.utils.misc import redact_auth_from_url +from build import BuildBackendException + from .._compat import IS_CLICK_VER_8_PLUS, parse_requirements from ..cache import DependencyCache from ..exceptions import PipToolsError diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 359ce3f1a..1df35a2e3 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -511,6 +511,39 @@ def test_editable_package_vcs(runner): assert "click" in out.stderr # dependency of pip-tools +@pytest.mark.network +def test_compile_cached_editable_vcs_package(runner, tmp_path): + """ + Test that cached vcs package does not interfere pip-compile results. + + Regression test for issue GH-1647. + """ + vcs_package = ( + "six @ git+https://github.com/benjaminp/six@" + "65486e4383f9f411da95937451205d3c7b61b9e1" + ) + + # Install and cache VCS package + # TODO: install package in isolated environment + subprocess.run( + [ + sys.executable, + "-m" "pip", + "install", + vcs_package, + ], + check=True, + ) + + with open("requirements.in", "w") as req_in: + req_in.write(vcs_package) + + out = runner.invoke(cli, ["--no-header", "--no-emit-options", "--no-annotate"]) + + assert out.exit_code == 0, out + assert vcs_package == out.stderr.strip() + + @legacy_resolver_only def test_locally_available_editable_package_is_not_archived_in_cache_dir( pip_conf, tmpdir, runner From 9b31c06f24f5c84caa2564088b70e480d94a77d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Jun 2022 16:00:26 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- piptools/scripts/compile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index b83df70e3..0c98c6b2d 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -6,6 +6,7 @@ from typing import IO, Any, BinaryIO, List, Optional, Tuple, Union, cast import click +from build import BuildBackendException from build.util import project_wheel_metadata from click.utils import LazyFile, safecall from pip._internal.commands import create_command @@ -13,8 +14,6 @@ from pip._internal.req.constructors import install_req_from_line from pip._internal.utils.misc import redact_auth_from_url -from build import BuildBackendException - from .._compat import IS_CLICK_VER_8_PLUS, parse_requirements from ..cache import DependencyCache from ..exceptions import PipToolsError From 28bebfd8913e973659f81310e8d9c8ae3e4b4798 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 30 Jun 2022 19:25:41 +0200 Subject: [PATCH 3/5] Pass always candidate.source_link --- piptools/resolver.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/piptools/resolver.py b/piptools/resolver.py index 3f4342e5c..ab35983d5 100644 --- a/piptools/resolver.py +++ b/piptools/resolver.py @@ -761,17 +761,16 @@ def _get_install_requirement_from_candidate( version_pin_operator = "===" break - # Prepare extra kwargs for pinned install requirement. - pinned_ireq_kwargs = {} - if candidate.source_link is not None: - # InstallRequirement.link after dependency resolution might contain - # a link to a cached wheel, see GH-1647 for details. Override the link - # with the candidate's source link. - pinned_ireq_kwargs["link"] = candidate.source_link - # Prepare pinned install requirement. Copy it from candidate's install # requirement so that it could be mutated later. - pinned_ireq = copy_install_requirement(ireq, **pinned_ireq_kwargs) + pinned_ireq = copy_install_requirement( + template=ireq, + # The link this candidate "originates" from. This is different + # from ``ireq.link`` when the link is found in the wheel cache. + # ``ireq.link`` would point to the wheel cache, while this points + # to the found remote link (e.g. from pypi.org). + link=candidate.source_link, + ) # Canonicalize name assert ireq.name is not None From 57012f6b09aa1f2963fb73e418198930ce535faf Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 30 Jun 2022 20:54:44 +0200 Subject: [PATCH 4/5] Correct test name --- 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 1df35a2e3..d638b053c 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -512,7 +512,7 @@ def test_editable_package_vcs(runner): @pytest.mark.network -def test_compile_cached_editable_vcs_package(runner, tmp_path): +def test_compile_cached_vcs_package(runner): """ Test that cached vcs package does not interfere pip-compile results. From ccfc3dff432acc3b7e6d868079a553c7609c2ac1 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Sat, 1 Oct 2022 01:22:41 +0200 Subject: [PATCH 5/5] Remove test :( Motivation: https://github.com/jazzband/pip-tools/pull/1649/files#r984986932 --- tests/test_cli_compile.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index d638b053c..359ce3f1a 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -511,39 +511,6 @@ def test_editable_package_vcs(runner): assert "click" in out.stderr # dependency of pip-tools -@pytest.mark.network -def test_compile_cached_vcs_package(runner): - """ - Test that cached vcs package does not interfere pip-compile results. - - Regression test for issue GH-1647. - """ - vcs_package = ( - "six @ git+https://github.com/benjaminp/six@" - "65486e4383f9f411da95937451205d3c7b61b9e1" - ) - - # Install and cache VCS package - # TODO: install package in isolated environment - subprocess.run( - [ - sys.executable, - "-m" "pip", - "install", - vcs_package, - ], - check=True, - ) - - with open("requirements.in", "w") as req_in: - req_in.write(vcs_package) - - out = runner.invoke(cli, ["--no-header", "--no-emit-options", "--no-annotate"]) - - assert out.exit_code == 0, out - assert vcs_package == out.stderr.strip() - - @legacy_resolver_only def test_locally_available_editable_package_is_not_archived_in_cache_dir( pip_conf, tmpdir, runner