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 a [tool.prehook] section to pyproject.toml and installs the git 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 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 init 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.2.0.tar.gz (14.3 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.2.0-py3-none-win_amd64.whl (284.5 kB view details)

Uploaded Python 3Windows x86-64

prehook-0.2.0-py3-none-manylinux_2_28_x86_64.whl (370.4 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

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

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

prehook-0.2.0-py3-none-macosx_10_12_x86_64.whl (352.9 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for prehook-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6e8a50d8c02f31c9f64969250af79dd541611319200f92d2531862b7a967675f
MD5 77394a62b1ea464e1e1faf627188ec1a
BLAKE2b-256 005d4d0e90494e3861d0e7a1a90cafb0d52163b936ccaf686e2ea169e53ef904

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: prehook-0.2.0-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.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 501e686cdea60473bd564f8636cd621009df9fdddd9fe49ee748b379f4331ef2
MD5 24c219b134660d245e603d9c7247c872
BLAKE2b-256 f2571778f3b336e9f54d914f92d9eca596ff5b3a7403799b81aa3e1b0d2aac9f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.2.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a2a644f616fd18feea7c77a37051a46adf6765ca2c3073e916fb055df3af552
MD5 a8e7b2416a123f22dde45505b2de021e
BLAKE2b-256 19dc6308264c17dd227d2271a0adcb4c8cef91ca1dc1d1869d6a31d6814c955c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.2.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3283a2a4c6d6d59270f44b16cdc409b6eb9a6e02d1fd86dab566f93e41acbbce
MD5 f0d3f151e4bc4c886d05d5b87dc7268e
BLAKE2b-256 84d778308eef56dcacededa02e0ed786c13f5fb56d7218af2a95e4bb60865ef9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e5d71b9da0d12a6f4703ab36887349e0e9fba9cb18ea50a4cb1c6da6e7c14a00
MD5 d1a2687656d0d0dfc076ac5ffaaf6805
BLAKE2b-256 48fbd5fdafab5f040a0b377911cd344fc909ed61919c84f910912861475f45f8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.2.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 40a36a74982d76460bc3e5b5df34aefac9a1269c9a4f58edba7f5c916afc3756
MD5 843398c8dbe668fcb67774154c45da7e
BLAKE2b-256 84cf21cd1d17fecb80d56faf12782ee10083cc9693451ced30970dcfd06ace26

See more details on using hashes here.

Provenance

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