From 65d4904af0b438c31fc31334ef5638e5e579ccdf Mon Sep 17 00:00:00 2001 From: Florent Jeannot <12172017+FlorentJeannot@users.noreply.github.com> Date: Tue, 15 Feb 2022 00:18:24 +0100 Subject: [PATCH 1/3] Direct references show extra requirements in .txt --- piptools/utils.py | 4 +++- tests/test_cli_compile.py | 5 ++++- tests/test_utils.py | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/piptools/utils.py b/piptools/utils.py index ccd94721d..a34443ffa 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -152,7 +152,9 @@ def _build_direct_reference_best_efforts(ireq: InstallRequirement) -> str: # If we get here then we have a requirement that supports direct reference. # We need to remove the egg if it exists and keep the rest of the fragments. - direct_reference = f"{ireq.name.lower()} @ {ireq.link.url_without_fragment}" + lowered_ireq_name = ireq.name.lower() + extras = f"[{','.join(sorted(ireq.extras))}]" if ireq.extras else "" + direct_reference = f"{lowered_ireq_name}{extras} @ {ireq.link.url_without_fragment}" fragments = [] # Check if there is any fragment to add to the URI. diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 63544bb13..90e34267c 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -659,7 +659,10 @@ def test_direct_reference_with_extras(runner): ) out = runner.invoke(cli, ["-n", "--rebuild"]) assert out.exit_code == 0 - assert "pip-tools @ git+https://github.com/jazzband/pip-tools@6.2.0" in out.stderr + assert ( + "pip-tools[coverage,testing] @ git+https://github.com/jazzband/pip-tools@6.2.0" + in out.stderr + ) assert "pytest==" in out.stderr assert "pytest-cov==" in out.stderr diff --git a/tests/test_utils.py b/tests/test_utils.py index 27f8cebea..76d189f31 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -73,6 +73,11 @@ def test_format_requirement(from_line): "example @ https://example.com/example.zip?egg=test", id="direct reference with egg in query", ), + pytest.param( + "example[b,c,a] @ https://example.com/example.zip", + "example[a,b,c] @ https://example.com/example.zip", + id="direct reference with optional dependency", + ), pytest.param( "file:./vendor/package.zip", "file:./vendor/package.zip", From e9d5fb7ffe63407d44805c350dfda5e0bdbadbbd Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Mon, 7 Aug 2023 12:57:55 +0200 Subject: [PATCH 2/3] Fix failing test_compile_recursive_extras --- 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 a2935a75e..498b4a80b 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -2958,7 +2958,7 @@ def test_compile_recursive_extras(runner, tmp_path, current_resolver): os.fspath(tmp_path / "pyproject.toml"), ], ) - expected = rf"""foo @ {tmp_path.as_uri()} + expected = rf"""foo[footest] @ {tmp_path.as_uri()} small-fake-a==0.2 small-fake-b==0.3 """ From 3b19f6d656ec76eb5b0d0318f4296ccd85391ff3 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Mon, 7 Aug 2023 12:58:55 +0200 Subject: [PATCH 3/3] Canonicalize direct reference package name --- piptools/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piptools/utils.py b/piptools/utils.py index a222abec6..fdfba40e7 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -155,7 +155,7 @@ def _build_direct_reference_best_efforts(ireq: InstallRequirement) -> str: # If we get here then we have a requirement that supports direct reference. # We need to remove the egg if it exists and keep the rest of the fragments. - lowered_ireq_name = ireq.name.lower() + lowered_ireq_name = canonicalize_name(ireq.name) extras = f"[{','.join(sorted(ireq.extras))}]" if ireq.extras else "" direct_reference = f"{lowered_ireq_name}{extras} @ {ireq.link.url_without_fragment}" fragments = []