diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6676030..d1c488f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,9 @@ Unreleased - Raise a clear ``TypeError`` when an ``include-group`` value is not a string (was a cryptic ``TypeError`` from name normalization), and accept any ``Mapping`` for include items, not only ``dict``. +- Fix a bug in which ``pip-install-dependency-groups`` failed when the + resolved groups were empty. It now prints ``Nothing to install`` and exits + normally. 1.3.1 ----- diff --git a/src/dependency_groups/_pip_wrapper.py b/src/dependency_groups/_pip_wrapper.py index e41bbae..d6d33d0 100644 --- a/src/dependency_groups/_pip_wrapper.py +++ b/src/dependency_groups/_pip_wrapper.py @@ -55,6 +55,10 @@ def main(*, argv: list[str] | None = None) -> None: print(f" {msg}") sys.exit(1) + if not resolved: + print("Nothing to install") + return + _invoke_pip(resolved) diff --git a/tests/test_pip_wrapper_cli.py b/tests/test_pip_wrapper_cli.py new file mode 100644 index 0000000..05967de --- /dev/null +++ b/tests/test_pip_wrapper_cli.py @@ -0,0 +1,49 @@ +import dataclasses + +import pytest + + +@dataclasses.dataclass +class CLIResult: + code: int + stdout: str + stderr: str + + +@pytest.fixture +def invoked_pip_args(monkeypatch): + calls: list[list[str]] = [] + monkeypatch.setattr("dependency_groups._pip_wrapper._invoke_pip", calls.append) + return calls + + +@pytest.fixture +def run(capsys, invoked_pip_args): + from dependency_groups._pip_wrapper import main as cli_main + + def _run(*argv): + try: + cli_main(argv=[str(arg) for arg in argv]) + rc = 0 + except SystemExit as e: + rc = e.code + + stdio = capsys.readouterr() + return CLIResult(rc, stdio.out, stdio.err) + + return _run + + +def test_empty_group_skips_pip(run, invoked_pip_args, tmp_path): + tomlfile = tmp_path / "pyproject.toml" + tomlfile.write_text( + """\ +[dependency-groups] +empty = [] +""" + ) + + res = run("-f", tomlfile, "empty") + assert res.code == 0 + assert invoked_pip_args == [] + assert "Nothing to install" in res.stdout