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. Run init in your project:

    uvx prehook init
    

    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.3.1.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.3.1-py3-none-win_amd64.whl (284.5 kB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

prehook-0.3.1-py3-none-macosx_11_0_arm64.whl (339.8 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

prehook-0.3.1-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.3.1.tar.gz.

File metadata

  • Download URL: prehook-0.3.1.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.3.1.tar.gz
Algorithm Hash digest
SHA256 d9a27df0a5ab306454ff28e3a4f7023694ce14af5ea2fc4c504bcf0931fcf936
MD5 0556c7c7385bcc8dfdd0e43af706ddee
BLAKE2b-256 75d3640ddb99aa2adf5bda1ff2ac1da3e45931e43dbc54946b377a42b19daa7b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: prehook-0.3.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 284.5 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.3.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 0eabc267e5847f6a7457b9caa2378d4adf6eb3e97bd10c45e977d34a18effd1b
MD5 c10f04bed0bc37d64e23f849d8e090b6
BLAKE2b-256 941698dbb0acbe5501832135d00f1bca7b91da52655d663d50d83fbd7b3e4393

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b15d70ffcc14ed4eff4835e32d3ab1241b907b2730f7e5c4484dab40e43500df
MD5 3cbb670abece5b71a35210ba0c8ed64c
BLAKE2b-256 6b39ab46dcb8fdcd9a4ab8a0ac438ed73e0961e44a43ccc4668816cb2adb07a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b14b66fe23cb88a1501cee43a282324e2f57a9a280b525a53e9f051e1cd2be65
MD5 9881a187adf6d271f7d438f1bc91edbc
BLAKE2b-256 ae83a694149b23b693d6b98e71d60e6ad2919708bcfbed50e654d313cbb4af4a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 39c78e57250fb055a7319c8d61847f58e0b208b3655b297c142e3cb4d24e6aaa
MD5 5f56b727167d8f27c6687faf68919106
BLAKE2b-256 d194621aa9e67d5568f62bdfa11a67cb784f2279769fc04d6ee040b2630ed22c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ba1ea82eb16f7ff9ea39b13b711178d420fd03fd3a5a3e83c12112be89503d97
MD5 8f69a5587f125c6cbbf6dec745e39905
BLAKE2b-256 f3d7952a8d5a78f3cd2a5d970bf38d7e17b67d4bfd18881b3c67809e9a74af88

See more details on using hashes here.

Provenance

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