diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 462215f4..2695956c 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -192,6 +192,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 == ("-",): @@ -359,10 +363,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 if build_deps_targets: constraints.extend(metadata.build_requirements) else: diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index e8ed406f..4586e461 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -3001,6 +3001,37 @@ 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", + str(test_package_1 / "setup.py"), + str(test_package_2 / "setup.py"), + ], + ) + + assert out.exit_code == 0, out + + @pytest.mark.parametrize( ("package_specs", "constraints", "existing_reqs", "expected_reqs"), ( @@ -3133,7 +3164,6 @@ def test_resolver_drops_existing_conflicting_constraint( req_txt_content = req_txt.read() assert expected_requirements.issubset(req_txt_content.splitlines()) - def test_resolution_failure(runner): """Test resolution impossible for unknown package.""" with open("requirements.in", "w") as reqs_out: