Skip to main content

Run git hooks as shell commands from pyproject.toml

Project description

prehook

CI PyPI License: MIT

Run git hooks as shell commands from pyproject.toml.

Usage

  1. Install:

    uvx prehook install
    

    Adds [tool.prehook] to pyproject.toml (if missing) and installs git hooks. Use --force to overwrite existing hooks.

  2. Edit the hooks in pyproject.toml:

    [tool.prehook]
    hooks = [
        "uvx ruff check --fix",
        "uvx ruff format",
    ]
    
  3. git commit -m "unfinished commit"

To run hooks manually:

uvx prehook run

To uninstall:

uvx prehook uninstall

Why?

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

But for projects where I just need to run ruff check and ruff format, setting up a separate config file with repo URLs and rev hashes felt like too much.

So I made this. Hooks live in pyproject.toml, and they're just shell commands.

Configuration

Simple form

Commands run in order. If any command exits non-zero, the commit is blocked.

[tool.prehook]
hooks = [
    "uvx ruff check --fix",
    "uvx ruff format",
]

A single command works too:

[tool.prehook]
hooks = ["just lint"]

Full form

For naming, stages, or per-hook options:

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

Global options

[tool.prehook]
fail_fast = true
parallel = true
hooks = [...]
Key Default Description
fail_fast false Stop after first failure.
parallel false Run all hooks concurrently.

Parallel mode

When parallel = true, all hooks run at the same time. If two commands must run in order (e.g. fix then format), combine them:

[tool.prehook]
parallel = true
hooks = [
    { name = "lint+format", run = "uvx ruff check --fix && uvx ruff format" },
    { name = "typecheck", run = "uvx pyright" },
]

Stages

Hooks run on pre-commit by default. To run on other git hooks (e.g. pre-push), set stages:

[tool.prehook]
hooks = [
    { name = "lint", run = "uvx ruff check" },
    { name = "test", run = "pytest", stages = ["pre-push"] },
]

prehook init installs hooks for all common git stages, so adding new stages to your config works without re-running init.

Skipping hooks

Skip all hooks:

git commit --no-verify -m "wip"

Skip specific hooks by name:

SKIP=typecheck git commit -m "wip"
SKIP=lint,typecheck git commit -m "wip"

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.4.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distributions

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

prehook-0.4.0-py3-none-win_amd64.whl (284.6 kB view details)

Uploaded Python 3Windows x86-64

prehook-0.4.0-py3-none-manylinux_2_28_x86_64.whl (370.2 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

prehook-0.4.0-py3-none-manylinux_2_28_aarch64.whl (350.2 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

prehook-0.4.0-py3-none-macosx_11_0_arm64.whl (339.7 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

prehook-0.4.0-py3-none-macosx_10_12_x86_64.whl (353.0 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for prehook-0.4.0.tar.gz
Algorithm Hash digest
SHA256 bb93f8b9c99f5f1536924c5e1f3155db69c4f54391f56a5646f388c79cb80c1f
MD5 f99eecfcd59fa7bfc531846d5fc858b6
BLAKE2b-256 65e8569ae281073b63c2345cfa6d15403aea0c5d4320220b41f8844fedc79bf5

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.4.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.4.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: prehook-0.4.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 284.6 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for prehook-0.4.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 881ee30531f0069ec63bb2afdee8cb95276e5a119f50617817a75ee37f6aef6c
MD5 f91a14e8dd653fdfbc717b3766853b7c
BLAKE2b-256 30d7d595b65e40deb2d0b1c128f14c710465e8669dc813c1656e5320e4834318

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.4.0-py3-none-win_amd64.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.

File details

Details for the file prehook-0.4.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for prehook-0.4.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5cc12d5d41c544bde7864f1c6cb2c25817b028bed4104acc57278bb74fff6b0e
MD5 1a9cec80f6d0018caaad03f33e211804
BLAKE2b-256 ef31bbd49e30febf9aa97c23640ed948e3840f6270355838abfab1386e4e88a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.4.0-py3-none-manylinux_2_28_x86_64.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.

File details

Details for the file prehook-0.4.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for prehook-0.4.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b2013fb84976310d5452d3e8ddbb41501587d9c3108f63eecdb7a7877db8f5c6
MD5 f77913d30027eac2f45a1ddf99ec2615
BLAKE2b-256 e483a7e5db0573a3745c68804bc4267377db81f26d71704cc5b526ebb4569c89

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.4.0-py3-none-manylinux_2_28_aarch64.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.

File details

Details for the file prehook-0.4.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for prehook-0.4.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98f6d4fafb192406465f6a5d0b75e931ecedc9e7aba25c5395b8be6708fcd157
MD5 5c636a9388fa5d44a987531a76efabac
BLAKE2b-256 02b9fabb437b1da48aadf62872e2e7e97975a29562e5f6531dd8aa5b5ccfdf62

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.4.0-py3-none-macosx_11_0_arm64.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.

File details

Details for the file prehook-0.4.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for prehook-0.4.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d8cfb6fb6552faa5b04d5c19ee33ad7c181a9fe71627cf4fdf832a7a6972ac1c
MD5 2ce682c4a62def67e04e96a9f67c801c
BLAKE2b-256 421541f57d5479437d9f7525694eb407167d9942d0f17c6fa4a709760c3419d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.4.0-py3-none-macosx_10_12_x86_64.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