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.3.0.tar.gz (14.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.3.0-py3-none-win_amd64.whl (284.6 kB view details)

Uploaded Python 3Windows x86-64

prehook-0.3.0-py3-none-manylinux_2_28_x86_64.whl (370.5 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

prehook-0.3.0-py3-none-manylinux_2_28_aarch64.whl (350.3 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

prehook-0.3.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.3.0.tar.gz.

File metadata

  • Download URL: prehook-0.3.0.tar.gz
  • Upload date:
  • Size: 14.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.3.0.tar.gz
Algorithm Hash digest
SHA256 8bd62b7eacc3b81023699d9f136dd4fdd7e78dfa765988c47ac26260192e0ae4
MD5 7c17361267844994210b0295dba821bd
BLAKE2b-256 301c147a5c2765b3185b9d596a5f08cc924c585e7da953aa3a939fea75438f48

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: prehook-0.3.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.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 abbc364c8d3aec3057e3a12b34d84e9b573eda6e14d8c95f6c46e615f4e85a8c
MD5 2374d04e5e2fd28e1e94f5f7fafcc394
BLAKE2b-256 a3191ac88153a3c4f7d803080537e8a56e4c2bc9f3a5f234d6002788d28934d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3ef9a92d9728eac6a6baead4977723db8a79d2a9343889d5674e8368d325e5a0
MD5 46ffec6757e8b1dd7ac328d1eb9920e5
BLAKE2b-256 475993ae492bead57daa3fc40f5b16737d764d91db92b29142e3bafda5d65fc8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0d6704fe81f7191e4b522af665469e7d75eb3eef3e8c22083b2664db541b12aa
MD5 edbee70845401c9614bd01547c39cbd9
BLAKE2b-256 0a1da81c861fdbb92c712c6322e5ea1b087bde35f1717e9d31bee2f276cdf762

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d99856bbea0489c480d86b0fc3fd03f50986bd08011efd8d3bbf09faa2bbd941
MD5 499f35fc34e3dbcfd5c9e4c549707d2c
BLAKE2b-256 b52ba3403b42398d9f9cdcef37a697d4f35d9d790c7e96ec6bf98d8cd5666930

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for prehook-0.3.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 13510825a5e48f2f8e44857937d1f1d2c6aecfdefd5d38936d54df58eae1e012
MD5 f48d0544c076cea1509c71d1b831d3ad
BLAKE2b-256 cc30ed109c9d8c3f512da3fce86e8eac3f3fa02499e3611326a7c37b60699491

See more details on using hashes here.

Provenance

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