Skip to main content

Run git hooks as shell commands from pyproject.toml

Project description

prehook

Run git hooks as shell commands from pyproject.toml.

Usage

  1. Add commands to pyproject.toml:

    [tool.prehook]
    hooks = [
        "uvx ruff check --fix",
        "uvx ruff format",
    ]
    
  2. Install the git hooks:

    uvx prehook install
    

    This creates a script in your .git/hooks/.

  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 hases 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 install detects all stages in your config and installs the right git hooks automatically.

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.1.0.tar.gz (12.4 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.1.0-py3-none-win_amd64.whl (288.4 kB view details)

Uploaded Python 3Windows x86-64

prehook-0.1.0-py3-none-manylinux_2_28_x86_64.whl (372.5 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

prehook-0.1.0-py3-none-manylinux_2_28_aarch64.whl (351.9 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

prehook-0.1.0-py3-none-macosx_11_0_arm64.whl (341.4 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

prehook-0.1.0-py3-none-macosx_10_12_x86_64.whl (355.3 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for prehook-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f1580b5ddedfce7ac24dff431506095157a48b84705812e92d8e8f49023f0386
MD5 321bb198c318517375de3208c8af9e2b
BLAKE2b-256 1bd88ca3310857c7a8651b79b26c2cf613f5330f7f70b5262a060143b3332fd5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: prehook-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 288.4 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.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4fb932bdba9803c95b8c5cbb232b417c73b9392a31ad7a723965bc1a359c8935
MD5 31706c13b08e7f3181f705f82807c748
BLAKE2b-256 d20c1666e2bc0b0b49374818a61ce43bd9475e60a7419fd18f9f474bf6ab4016

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.1.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ab5039dc7271c77d3617fa346546fedba1ebf69ee36ef14eb4421c38278bf1f
MD5 1acc8d062b4619d5925248c8c0ac6c06
BLAKE2b-256 68442d499ede5257db18dfc7a043e7be1a8a4d61f4783258205cdc90ac6a56eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.1.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 31082d2ab76ded1d0dd6653415c4d9f1e50d6805e0295fc6fc41b4e58bb3f58e
MD5 af31ea4e5082bf7dc5e91c9c82250f15
BLAKE2b-256 13e46d9d981b51596fe8a9f0f5228044885f7abce26b00ba854fb40ae557dc95

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d66c5e2983662fcb8bdbbbd6736b9570923e36622e81782b2bcd30dbf4d6d25
MD5 25904714e2e4df784c453898c108eb18
BLAKE2b-256 44ec4ee0f868c9f8ce66bd01b0a656a307d71f5f7f8675b471af7d088855e9ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.1.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 77de8ae731a279a3ec0d5d4a062263c6ef7a6dc7ccdf22139664c15f00eb45af
MD5 b9216091b313a8e8f0393290cd92e774
BLAKE2b-256 f9201c388eed0ddc0376757c4d65de07d6ad4624e991c87ca7b6a3e178c2094d

See more details on using hashes here.

Provenance

The following attestation bundles were made for prehook-0.1.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