Skip to content

Commit

Permalink
Add --all-extras flag to pip-compile (#1630)
Browse files Browse the repository at this point in the history
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
  • Loading branch information
3 people authored Oct 5, 2022
1 parent a659e55 commit 5242ab8
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def _get_default_option(option_name: str) -> Any:
multiple=True,
help="Name of an extras_require group to install; may be used more than once",
)
@click.option(
"--all-extras",
is_flag=True,
default=False,
help="Install all extras_require groups",
)
@click.option(
"-f",
"--find-links",
Expand Down Expand Up @@ -259,6 +265,7 @@ def cli(
pre: bool,
rebuild: bool,
extras: Tuple[str, ...],
all_extras: bool,
find_links: Tuple[str, ...],
index_url: str,
extra_index_url: Tuple[str, ...],
Expand Down Expand Up @@ -442,6 +449,11 @@ def cli(
for req in metadata.get_all("Requires-Dist") or []
]
)
if all_extras:
if extras:
msg = "--extra has no effect when used with --all-extras"
raise click.BadParameter(msg)
extras = tuple(metadata.get_all("Provides-Extra"))
else:
constraints.extend(
parse_requirements(
Expand Down
64 changes: 64 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,70 @@ def test_multiple_extras(fake_dists, runner, make_module, fname, content, extra_
assert "extra ==" not in out.stderr


@pytest.mark.network
@pytest.mark.parametrize(("fname", "content"), METADATA_TEST_CASES)
def test_all_extras(fake_dists, runner, make_module, fname, content):
"""
Test passing `--all-extras` includes all applicable extras.
"""
meta_path = make_module(fname=fname, content=content)
out = runner.invoke(
cli,
[
"-n",
"--all-extras",
"--find-links",
fake_dists,
"--no-annotate",
"--no-emit-options",
"--no-header",
meta_path,
],
)
assert out.exit_code == 0, out.stderr
assert (
dedent(
"""\
small-fake-a==0.1
small-fake-b==0.2
small-fake-c==0.3
small-fake-d==0.4
small-fake-e==0.5
small-fake-f==0.6
Dry-run, so nothing updated.
"""
)
== out.stderr
)


# This should not depend on the metadata format so testing all cases is wasteful
@pytest.mark.parametrize(("fname", "content"), METADATA_TEST_CASES[:1])
def test_all_extras_fail_with_extra(fake_dists, runner, make_module, fname, content):
"""
Test that passing `--all-extras` and `--extra` fails.
"""
meta_path = make_module(fname=fname, content=content)
out = runner.invoke(
cli,
[
"-n",
"--all-extras",
"--extra",
"dev",
"--find-links",
fake_dists,
"--no-annotate",
"--no-emit-options",
"--no-header",
meta_path,
],
)
assert out.exit_code == 2
exp = "--extra has no effect when used with --all-extras"
assert exp in out.stderr


def test_extras_fail_with_requirements_in(runner, tmpdir):
"""
Test that passing `--extra` with `requirements.in` input file fails.
Expand Down

0 comments on commit 5242ab8

Please sign in to comment.