Skip to main content

Run git hooks as shell commands from pyproject.toml

Project description

prehook

CI PyPI License: MIT

Run git hooks configured in pyproject.toml using uv.

Usage

  1. Install (one-time):

    uvx prehook install
    

    Use --force to overwrite existing git hooks.

    Installed hooks are self-contained sh (they read pyproject.toml directly), so committing never needs prehook itself, and editing the hook list needs no reinstall.

  2. Update hooks in pyproject.toml:

    [tool.prehook]
    hooks = [
        "uvx ruff check",
        "uvx ruff format",
    ]
    
  3. Commit:

    git commit -m "unfinished commit"
    

To uninstall:

uvx prehook uninstall

Run the hooks on demand (e.g. in CI) without committing:

uvx prehook run                 # pre-commit hooks
uvx prehook run --on pre-push   # a specific stage

Configuration

Each hook can have a name, target git hook type, and other options:

[tool.prehook]
hooks = [
    { name = "lint", run = "uvx ruff check --fix" },
    { name = "format", run = "uvx ruff format" },
    { name = "typecheck", run = "uvx pyright" },
    { name = "test", run = "pytest", on = ["pre-push"] },
]
Key Default Description
run required Command to execute.
name derived from command Label for output and SKIP.
on ["pre-commit"] Which git hook types to run on.
verbose false Show output even on success.

uvx prehook install installs hooks for all supported git hook types, so adding new on values works without reinstalling.

Skipping hooks

SKIP=typecheck git commit -m "wip"         # skip by name
SKIP=lint,typecheck git commit -m "wip"    # skip multiple
git commit --no-verify -m "wip"            # skip all

Parallel and fail fast

[tool.prehook]
parallel = true
fail_fast = true
hooks = [
    { name = "lint+format", run = "uvx ruff check --fix && uvx ruff format" },
    { name = "typecheck", run = "uvx pyright" },
]
Key Default Description
fail_fast false Stop after first failure.
parallel false Run all hooks concurrently.

Why?

I used pre-commit for a long time, and it's a great tool.

But I prefer less configuration files, and for most projects I just want a quick:

uvx ruff check
uvx ruff format

Which are fast enough to always run on all files (rather than just staged ones).

Alternatives

If this tool doesn't do what you need, these are worth a look:

Tool Config What it does well
pre-commit .pre-commit-config.yaml Huge ecosystem of ready-made hooks, multi-language virtualenv management.
lefthook lefthook.yml Fast, language-agnostic, great parallel execution.
prek prek.toml Compatible with pre-commit configs, written in Rust, parallel execution.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prehook-0.6.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prehook-0.6.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file prehook-0.6.0.tar.gz.

File metadata

  • Download URL: prehook-0.6.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for prehook-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5f54b5750de71e248fbc4f2466b721f17a670dae4f64c97593fca92a0df159c0
MD5 89d7bc9c71790b7240b745a98f25cc5e
BLAKE2b-256 3fb1232a010a4e9d9f0bd39e20e89ae3f6f9f8b966499679605f2347d32c2a69

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.6.0.tar.gz:

Publisher: release.yml on scriptogre/prehook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prehook-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: prehook-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for prehook-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cacc99f427f2828b2a589c2ebc78d25da9855eb9ab5d88aa893f4776fd5b5ef1
MD5 0685de0073027267e3636a25efef6643
BLAKE2b-256 00ed433c8669ef79450dea8b39764edfe8da8cf7e111a5c85e85d4f326033dd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.6.0-py3-none-any.whl:

Publisher: release.yml on scriptogre/prehook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page