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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file.
- **`prek.toml` support**:
Sync hook versions in `prek.toml` configs, in addition to `.pre-commit-config.yaml` (#35)

### Bug Fixes

- Pluralize the summary counts by number, so a count of 1 reads "1 package" and other counts read "N packages"

### Documentation

- Document that custom file locations require updating the `files` setting in `.pre-commit-config.yaml` (#36)
Expand Down
11 changes: 9 additions & 2 deletions src/sync_with_uv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@


@app.default()
def process_precommit( # noqa: PLR0913

Check notice on line 81 in src/sync_with_uv/cli.py

View workflow job for this annotation

GitHub Actions / pylint

R0914

Too many local variables (16/15)

Check notice on line 81 in src/sync_with_uv/cli.py

View workflow job for this annotation

GitHub Actions / pylint

R0913

Too many arguments (7/5)
*,
precommit_filename: Annotated[
Path | None, Parameter(["-p", "--pre-commit-config"])
Expand Down Expand Up @@ -158,7 +158,7 @@
_print_summary(changes, dry_mode=diff or check)
# return 1 if check and changed
return int(check and fixed_text != config_text)
except Exception as e: # noqa: BLE001

Check warning on line 161 in src/sync_with_uv/cli.py

View workflow job for this annotation

GitHub Actions / pylint

W0718

Catching too general exception Exception
print("Error:", e, file=sys.stderr)
return 123

Expand Down Expand Up @@ -190,6 +190,11 @@
print("\n".join(diff_lines))


def _plural(count: int, singular: str, plural: str) -> str:
"""Return *singular* when count is exactly 1, otherwise *plural*."""
return singular if count == 1 else plural


def _print_summary(
changes: dict[str, bool | tuple[str, str]], *, dry_mode: bool
) -> None:
Expand All @@ -202,7 +207,9 @@
n_unchanged += 1
would_be = "would be " if dry_mode else ""
print(
f"{n_changed} package {would_be}changed, "
f"{n_unchanged} packages {would_be}left unchanged.",
f"{n_changed} {_plural(n_changed, 'package', 'packages')} "
f"{would_be}changed, "
f"{n_unchanged} {_plural(n_unchanged, 'package', 'packages')} "
f"{would_be}left unchanged.",
file=sys.stderr,
)
11 changes: 6 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_process_precommit_cli_check(
assert exc_info.value.code == 1
captured = capsys.readouterr()
assert captured.err == (
"All done!\n2 package would be changed, 2 packages would be left unchanged.\n"
"All done!\n2 packages would be changed, 2 packages would be left unchanged.\n"
)
assert captured.out == ""

Expand Down Expand Up @@ -100,7 +100,7 @@ def test_process_precommit_cli_check_v(
"another-package: not managed in uv\n"
"\n"
"All done!\n"
"2 package would be changed, 2 packages would be left unchanged.\n"
"2 packages would be changed, 2 packages would be left unchanged.\n"
)
assert captured.out == ""

Expand Down Expand Up @@ -132,7 +132,7 @@ def test_process_precommit_cli_diff(
assert exc_info.value.code == 0
captured = capsys.readouterr()
assert (
"All done!\n2 package would be changed, 2 packages would be left unchanged."
"All done!\n2 packages would be changed, 2 packages would be left unchanged."
in captured.err
)
assert "- rev: 23.9.1 # a comment" in captured.out
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_process_precommit_cli_with_write(
assert exc_info.value.code == 0
captured = capsys.readouterr()
assert captured.err == (
"All done!\n2 package changed, 2 packages left unchanged.\n"
"All done!\n2 packages changed, 2 packages left unchanged.\n"
)
assert captured.out == ""

Expand Down Expand Up @@ -240,7 +240,8 @@ def test_process_precommit_cli_check_no_changes_needed(
captured = capsys.readouterr()
assert "All done!" in captured.err
assert (
"0 package would be changed, 2 packages would be left unchanged" in captured.err
"0 packages would be changed, 2 packages would be left unchanged"
in captured.err
)
assert captured.out == ""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_prek_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_cli_prek_toml_write(
app(["-p", str(sample_prek_config), "-u", str(sample_uv_lock)])
assert exc_info.value.code == 0
captured = capsys.readouterr()
assert "3 package changed" in captured.err
assert "3 packages changed" in captured.err

content = sample_prek_config.read_text()
assert 'rev = "v0.15.0"' in content # ruff updated
Expand Down
Loading