Skip to content

[Breaking Change] Add usethis hook command and --hook/--no-hook to usethis init#1454

Merged
nathanjmcdougall merged 4 commits intomainfrom
copilot/add-pre-commit-hook-option
Mar 22, 2026
Merged

[Breaking Change] Add usethis hook command and --hook/--no-hook to usethis init#1454
nathanjmcdougall merged 4 commits intomainfrom
copilot/add-pre-commit-hook-option

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 22, 2026

Higher-level interface for managing git hooks, analogous to usethis lint, usethis typecheck, etc. Uses pre-commit as the underlying framework for now.

Changes

  • New usethis hook command — top-level command under "Manage Tooling" with standard --remove, --how, --offline, --frozen, --backend options
    • _toolset/hook.py: wraps use_pre_commit()
    • _ui/interface/hook.py: CLI interface
    • Registered in app.py
  • usethis init flag rename--pre-commit/--no-pre-commit--hook/--no-hook (default: False)
    • Internal wiring updated to use use_hook_framework() from the toolset layer instead of importing use_pre_commit directly from _core
  • Architecturehook added to .importlinter ui_interface contract
  • Docsusethis hook added to docs/cli/overview.md, docs/cli/reference.md, and README.md
    • docs/cli/reference.md: new ## usethis hook section added and --pre-commit renamed to --hook under usethis init

Usage

$ usethis hook           # Add pre-commit framework
$ usethis hook --remove  # Remove it
$ usethis init --hook    # Include hook framework in project init
Original prompt

This section details on the original issue you should resolve

<issue_title>usethis hook or similar</issue_title>
<issue_description>Higher level interface for choosing an opinionated framework for managing git hooks. Will use pre-commit as the tool for now.

Could use #1003

Also add --hook/--no-hook to usethis init, defaulting to false.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

- Create _toolset/hook.py wrapping use_pre_commit()
- Create _ui/interface/hook.py CLI interface
- Register `usethis hook` command in app.py
- Replace --pre-commit/--no-pre-commit with --hook/--no-hook in init
- Update .importlinter, docs/cli/overview.md, and README.md
- Add test_hook.py tests and update test_init.py

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/5e55d87a-8269-437d-8ff1-abea260f5a4a
Copilot AI changed the title [WIP] Add higher level interface for choosing git hooks framework Add usethis hook command and --hook/--no-hook to usethis init Mar 22, 2026
Copilot AI requested a review from nathanjmcdougall March 22, 2026 09:14
@nathanjmcdougall nathanjmcdougall changed the title Add usethis hook command and --hook/--no-hook to usethis init [Breaking Change] Add usethis hook command and --hook/--no-hook to usethis init Mar 22, 2026
@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

This is a breaking change because it renames the --pre-commit argument to --hook in usethis init.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 22, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/add-pre-commit-hook-option (ebd433b) with main (93eebf1)

Open in CodSpeed

@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review March 22, 2026 09:42
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 88.46154% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_ui/interface/hook.py 81.25% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new high-level usethis hook CLI command (wrapping pre-commit) and renames the usethis init flag from --pre-commit/--no-pre-commit to --hook/--no-hook, aligning git hook management with other “Manage Tooling” commands.

Changes:

  • Introduces usethis hook UI + toolset entrypoint and registers it in the Typer app.
  • Renames usethis init’s pre-commit option to --hook/--no-hook and rewires init to call the toolset hook function.
  • Updates overview/README docs and import-linter layer contract; adds CLI interface tests for hook.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/usethis/_ui/interface/test_init.py Updates init CLI tests for the renamed --hook option and new output message.
tests/usethis/_ui/interface/test_hook.py Adds new CLI tests for usethis hook add/how/remove/backend behaviors.
src/usethis/_ui/interface/init.py Renames init option and routes hook setup via use_hook_framework().
src/usethis/_ui/interface/hook.py New CLI entrypoint implementing usethis hook with standard tool flags.
src/usethis/_ui/app.py Registers the new top-level hook command in the Typer app.
src/usethis/_toolset/hook.py Adds toolset wrapper use_hook_framework() (currently delegates to use_pre_commit()).
docs/cli/overview.md Adds usethis hook to the CLI overview list.
README.md Adds usethis hook to the README CLI command list.
.importlinter Adds hook to the ui_interface layers contract.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- [`usethis arch`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-arch) — Add/Configure recommended architecture analysis tools (namely, [Import Linter](https://import-linter.readthedocs.io/en/stable/)).
- [`usethis doc`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-doc) — Add/Configure recommended documentation tools (namely, [MkDocs](https://www.mkdocs.org/)).
- [`usethis format`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-format) — Add/Configure recommended formatters (namely, [Ruff](https://docs.astral.sh/ruff/formatter/) and [pyproject-fmt](https://pyproject-fmt.readthedocs.io/en/latest/)).
- [`usethis hook`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-hook) — Add/Configure a recommended git hook framework (namely, [pre-commit](https://github.com/pre-commit/pre-commit)).
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README links to .../cli/reference#usethis-hook, but the in-repo CLI reference doc (docs/cli/reference.md) currently has no usethis hook section/anchor and still documents --pre-commit/--no-pre-commit for usethis init. Until the reference is updated, this README link is likely to 404/mislead.

Suggested change
- [`usethis hook`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-hook) — Add/Configure a recommended git hook framework (namely, [pre-commit](https://github.com/pre-commit/pre-commit)).
- [`usethis hook`](https://usethis.readthedocs.io/en/stable/cli/reference) — Add/Configure a recommended git hook framework (namely, [pre-commit](https://github.com/pre-commit/pre-commit)).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot likewise, please update reference.md to ensure this hyperlink is valid

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated docs/cli/reference.md in ebd433b — added a new ## usethis hook section (with anchor #usethis-hook) and renamed --pre-commit to --hook under usethis init.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ebd433breference.md now has the #usethis-hook anchor.

- [`usethis arch`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-arch) — Add/Configure recommended architecture analysis tools (namely, [Import Linter](https://import-linter.readthedocs.io/en/stable/)).
- [`usethis doc`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-doc) — Add/Configure recommended documentation tools (namely, [MkDocs](https://www.mkdocs.org/)).
- [`usethis format`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-format) — Add/Configure recommended formatters (namely, [Ruff](https://docs.astral.sh/ruff/formatter/) and [pyproject-fmt](https://pyproject-fmt.readthedocs.io/en/latest/)).
- [`usethis hook`](https://usethis.readthedocs.io/en/stable/cli/reference#usethis-hook) — Add/Configure a recommended git hook framework (namely, [pre-commit](https://github.com/pre-commit/pre-commit)).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot likewise, please update reference.md to ensure this hyperlink is valid

…-pre-commit to --hook

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/fdd7c3d5-e514-44f7-a799-5ec619a872f5
@nathanjmcdougall nathanjmcdougall merged commit b6fcd0d into main Mar 22, 2026
19 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/add-pre-commit-hook-option branch March 22, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usethis hook or similar

3 participants