Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
4 changes: 4 additions & 0 deletions src/dependency_groups/_pip_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
49 changes: 49 additions & 0 deletions tests/test_pip_wrapper_cli.py
Original file line number Diff line number Diff line change
@@ -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