Skip to content

Commit cf36870

Browse files
tsvikasclaude
andauthored
Pluralize summary counts by number (#58)
The end-of-run summary hardcoded "package" for the changed count and "packages" for the unchanged count, so it read "1 packages" or "2 package" depending on the numbers. Add a small `_plural` helper and use it for both counts, so a count of 1 reads "package" and any other count reads "packages". Claude-Session: https://claude.ai/code/session_01K6m3rhqg4ssCTaan8K1BDi Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a6df7ed commit cf36870

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file.
99
- **`prek.toml` support**:
1010
Sync hook versions in `prek.toml` configs, in addition to `.pre-commit-config.yaml` (#35)
1111

12+
### Bug Fixes
13+
14+
- Pluralize the summary counts by number, so a count of 1 reads "1 package" and other counts read "N packages"
15+
1216
### Documentation
1317

1418
- Document that custom file locations require updating the `files` setting in `.pre-commit-config.yaml` (#36)

src/sync_with_uv/cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ def _print_diff(
190190
print("\n".join(diff_lines))
191191

192192

193+
def _plural(count: int, singular: str, plural: str) -> str:
194+
"""Return *singular* when count is exactly 1, otherwise *plural*."""
195+
return singular if count == 1 else plural
196+
197+
193198
def _print_summary(
194199
changes: dict[str, bool | tuple[str, str]], *, dry_mode: bool
195200
) -> None:
@@ -202,7 +207,9 @@ def _print_summary(
202207
n_unchanged += 1
203208
would_be = "would be " if dry_mode else ""
204209
print(
205-
f"{n_changed} package {would_be}changed, "
206-
f"{n_unchanged} packages {would_be}left unchanged.",
210+
f"{n_changed} {_plural(n_changed, 'package', 'packages')} "
211+
f"{would_be}changed, "
212+
f"{n_unchanged} {_plural(n_unchanged, 'package', 'packages')} "
213+
f"{would_be}left unchanged.",
207214
file=sys.stderr,
208215
)

tests/test_cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_process_precommit_cli_check(
3636
assert exc_info.value.code == 1
3737
captured = capsys.readouterr()
3838
assert captured.err == (
39-
"All done!\n2 package would be changed, 2 packages would be left unchanged.\n"
39+
"All done!\n2 packages would be changed, 2 packages would be left unchanged.\n"
4040
)
4141
assert captured.out == ""
4242

@@ -100,7 +100,7 @@ def test_process_precommit_cli_check_v(
100100
"another-package: not managed in uv\n"
101101
"\n"
102102
"All done!\n"
103-
"2 package would be changed, 2 packages would be left unchanged.\n"
103+
"2 packages would be changed, 2 packages would be left unchanged.\n"
104104
)
105105
assert captured.out == ""
106106

@@ -132,7 +132,7 @@ def test_process_precommit_cli_diff(
132132
assert exc_info.value.code == 0
133133
captured = capsys.readouterr()
134134
assert (
135-
"All done!\n2 package would be changed, 2 packages would be left unchanged."
135+
"All done!\n2 packages would be changed, 2 packages would be left unchanged."
136136
in captured.err
137137
)
138138
assert "- rev: 23.9.1 # a comment" in captured.out
@@ -166,7 +166,7 @@ def test_process_precommit_cli_with_write(
166166
assert exc_info.value.code == 0
167167
captured = capsys.readouterr()
168168
assert captured.err == (
169-
"All done!\n2 package changed, 2 packages left unchanged.\n"
169+
"All done!\n2 packages changed, 2 packages left unchanged.\n"
170170
)
171171
assert captured.out == ""
172172

@@ -240,7 +240,8 @@ def test_process_precommit_cli_check_no_changes_needed(
240240
captured = capsys.readouterr()
241241
assert "All done!" in captured.err
242242
assert (
243-
"0 package would be changed, 2 packages would be left unchanged" in captured.err
243+
"0 packages would be changed, 2 packages would be left unchanged"
244+
in captured.err
244245
)
245246
assert captured.out == ""
246247

tests/test_prek_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_cli_prek_toml_write(
4646
app(["-p", str(sample_prek_config), "-u", str(sample_uv_lock)])
4747
assert exc_info.value.code == 0
4848
captured = capsys.readouterr()
49-
assert "3 package changed" in captured.err
49+
assert "3 packages changed" in captured.err
5050

5151
content = sample_prek_config.read_text()
5252
assert 'rev = "v0.15.0"' in content # ruff updated

0 commit comments

Comments
 (0)