Repository: jazzband/pip-tools

Issue:
Running pip-tools compile on multiple sources fails with --all-extras
Running pip-tools compile with `--all-extras` on multiple sources containing extras always fails with the following error:

> ```console
> Error: Invalid value: --extra has no effect when used with --all-extras
> ```

#### Environment Versions

1. Linux
1. Python version: `python 3.10.8`
1. pip version: `pip 22.2.2`
1. pip-tools version: `pip-compile, version 7.3.1.dev21`

#### Steps to replicate

1. Create two small projects with `pyproject.toml` containing
```toml
[project]
name = "package-a"
version = "0.1.0"

[project.optional-dependencies]
test = []
```
2. Run `python -m piptools compile --all-extras package-a/pyproject.toml package-b/pyproject.toml`

#### Expected result

A `requirements.txt` file for the combined projects including all extras should be generated.

#### Actual result

> ```console
> Error: Invalid value: --extra has no effect when used with --all-extras
> ```


Discussion:

Resolving patch:
diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py
--- a/piptools/scripts/compile.py
+++ b/piptools/scripts/compile.py
@@ -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 == ("-",):
@@ -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
             if build_deps_targets:
                 constraints.extend(metadata.build_requirements)
         else:


Test patch:
diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py
--- a/tests/test_cli_compile.py
+++ b/tests/test_cli_compile.py
@@ -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",
+            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
+
+
 @pytest.mark.parametrize(
     ("package_specs", "constraints", "existing_reqs", "expected_reqs"),
     (