Skip to main content

Extract and filter pre-commit hooks.

Project description

status release ci release

Filter-pre-commit-hooks

Small Python program that extracts and filters pre-commit hooks so that only a subset of them can be executed. Why is such a program helpful? Pre-commit only provides a way to skip hooks. There is no way to explicitly state which hooks should be run.

The program is available in this repository as the script filter_pre_commit_hooks.py and as the package filter-pre-commit-hooks on PyPI.

By default, the program returns all hooks that have the given tags. In the following example, all pre-commit hooks that are tagged with fix and task are executed (tagging is described further below):

SKIP=$(uv run -s filter_pre_commit_hooks.py fix task) pre-commit run -a

The program itself is executed with uv run, a subcommand of uv, which is a package manager for Python. This is because the script contains inline script metadata specifying required dependencies. The script also contains a shebang, so it can be executed directly.

Using the package from PyPI, the equivalent command looks like this:

SKIP=$(filter-pre-commit-hooks fix task) pre-commit run -a

Tags are extracted from the "alias" field of every hook. Tags are declared by putting them into parenthesis at the end of the respective alias. Individual tags are separated by commas. Here are two exemplary aliases:

forbid-new-submodules (check, task)
mixed-line-ending (fix, task)

Options can be passed to the script to change the behavior of the script. For example, to filter hooks by their identifier instead of their tags. For more information on this, try out the --help option of the script or read the source code.

A valid config used with the script can be found in .pre-commit-config.yaml. Some tasks in Justfile run selected pre-commit hooks using the script.

Shell completion

This program uses Click for the CLI. Click provides automatically generated shell completion for Bash, Fish, and Zsh. Check out the official documentation here.

Project status

The project is maintained by me, Tim, and I am interested in keeping it alive as I am actively using it.

I'm also using the project to test out various tools and workflows.

Versioning

The project follows Semantic Versioning.

Contributing

Contributions are welcome. Please refer to CONTRIBUTE.md.

Licensing

This work is licensed under the ISC license. See LICENSE for the license text.

The license is also included in the script filter_pre_commit_hooks.py itself.

Template

This project is based on the following Copier template: https://github.com/trallnag/copier-template-python-script.

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

filter_pre_commit_hooks-2.0.5.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

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

filter_pre_commit_hooks-2.0.5-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file filter_pre_commit_hooks-2.0.5.tar.gz.

File metadata

  • Download URL: filter_pre_commit_hooks-2.0.5.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for filter_pre_commit_hooks-2.0.5.tar.gz
Algorithm Hash digest
SHA256 09308207a952972439ad2fc68269b1f680f68f37389f076f4d48e4c175e61f7e
MD5 f23f9736d164eb508ed601532d0d59e2
BLAKE2b-256 6503c0a36829795075806858112273bd1d796319f015b71839c78ea332cdc265

See more details on using hashes here.

Provenance

The following attestation bundles were made for filter_pre_commit_hooks-2.0.5.tar.gz:

Publisher: release.yaml on trallnag/filter-pre-commit-hooks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file filter_pre_commit_hooks-2.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for filter_pre_commit_hooks-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3d889cd9d56b764a4815c2e2f735b2bef0a91e99669de41ca41ce70785dcf9d9
MD5 1806c5d41aa054747f1edc13b7687b0e
BLAKE2b-256 2345fea46db53301bb4f27d4a5493ae85dc6dcae4159268e77a62fab5b1a46db

See more details on using hashes here.

Provenance

The following attestation bundles were made for filter_pre_commit_hooks-2.0.5-py3-none-any.whl:

Publisher: release.yaml on trallnag/filter-pre-commit-hooks

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