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

Fix collecting deps for all extras in multiple input packages #1981

Merged
merged 5 commits into from
Feb 21, 2024
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
9 changes: 5 additions & 4 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def cli(
).format(", ".join(DEFAULT_REQUIREMENTS_FILES))
)

if all_extras and extras:
msg = "--extra has no effect when used with --all-extras"
raise click.BadParameter(msg)

if not output_file:
# An output file must be provided for stdin
if src_files == ("-",):
Expand Down Expand Up @@ -372,10 +376,7 @@ def cli(
if not only_build_deps:
constraints.extend(metadata.requirements)
if all_extras:
if extras:
msg = "--extra has no effect when used with --all-extras"
raise click.BadParameter(msg)
extras = metadata.extras
extras += metadata.extras
chrysle marked this conversation as resolved.
Show resolved Hide resolved
if build_deps_targets:
constraints.extend(metadata.build_requirements)
else:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,40 @@ def test_cli_compile_strip_extras(runner, make_package, make_sdist, tmpdir):
assert "[more]" not in out.stderr


def test_cli_compile_all_extras_with_multiple_packages(
runner, make_package, make_sdist, tmpdir
):
"""
Assures that ``--all-extras`` works when multiple sources are specified.
"""
test_package_1 = make_package(
"test_package_1",
version="0.1",
extras_require={"more": []},
)
test_package_2 = make_package(
"test_package_2",
version="0.1",
extras_require={"more": []},
)

out = runner.invoke(
cli,
[
"--all-extras",
"--output-file",
"requirements.txt",
chrysle marked this conversation as resolved.
Show resolved Hide resolved
str(test_package_1 / "setup.py"),
str(test_package_2 / "setup.py"),
],
)

assert out.exit_code == 0, out
assert "--all-extras" in out.stderr
assert f"test_package_1{os.path.sep}0.1{os.path.sep}setup.py" in out.stderr
assert f"test_package_2{os.path.sep}0.1{os.path.sep}setup.py" in out.stderr
chrysle marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize(
("package_specs", "constraints", "existing_reqs", "expected_reqs"),
(
Expand Down
Loading