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

Direct references show extra requirements in .txt files #1582

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,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 = 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 = []

# Check if there is any fragment to add to the URI.
Expand Down
7 changes: 5 additions & 2 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,10 @@ def test_direct_reference_with_extras(runner):
)
out = runner.invoke(cli, ["-n", "--rebuild", "--no-build-isolation"])
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

Expand Down Expand Up @@ -2955,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
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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",
Expand Down