Skip to content

Commit 19db875

Browse files
Direct references show extra requirements in .txt files (#1582)
1 parent 9e4aeff commit 19db875

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

piptools/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def _build_direct_reference_best_efforts(ireq: InstallRequirement) -> str:
155155

156156
# If we get here then we have a requirement that supports direct reference.
157157
# We need to remove the egg if it exists and keep the rest of the fragments.
158-
direct_reference = f"{ireq.name.lower()} @ {ireq.link.url_without_fragment}"
158+
lowered_ireq_name = canonicalize_name(ireq.name)
159+
extras = f"[{','.join(sorted(ireq.extras))}]" if ireq.extras else ""
160+
direct_reference = f"{lowered_ireq_name}{extras} @ {ireq.link.url_without_fragment}"
159161
fragments = []
160162

161163
# Check if there is any fragment to add to the URI.

tests/test_cli_compile.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,10 @@ def test_direct_reference_with_extras(runner):
779779
)
780780
out = runner.invoke(cli, ["-n", "--rebuild", "--no-build-isolation"])
781781
assert out.exit_code == 0
782-
assert "pip-tools @ git+https://github.com/jazzband/pip-tools@6.2.0" in out.stderr
782+
assert (
783+
"pip-tools[coverage,testing] @ git+https://github.com/jazzband/pip-tools@6.2.0"
784+
in out.stderr
785+
)
783786
assert "pytest==" in out.stderr
784787
assert "pytest-cov==" in out.stderr
785788

@@ -2955,7 +2958,7 @@ def test_compile_recursive_extras(runner, tmp_path, current_resolver):
29552958
os.fspath(tmp_path / "pyproject.toml"),
29562959
],
29572960
)
2958-
expected = rf"""foo @ {tmp_path.as_uri()}
2961+
expected = rf"""foo[footest] @ {tmp_path.as_uri()}
29592962
small-fake-a==0.2
29602963
small-fake-b==0.3
29612964
"""

tests/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ def test_format_requirement(from_line):
7979
"example @ https://example.com/example.zip?egg=test",
8080
id="direct reference with egg in query",
8181
),
82+
pytest.param(
83+
"example[b,c,a] @ https://example.com/example.zip",
84+
"example[a,b,c] @ https://example.com/example.zip",
85+
id="direct reference with optional dependency",
86+
),
8287
pytest.param(
8388
"file:./vendor/package.zip",
8489
"file:./vendor/package.zip",

0 commit comments

Comments
 (0)