Extract and filter pre-commit hooks.
Project description
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.
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
src/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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file filter_pre_commit_hooks-2.0.3.tar.gz.
File metadata
- Download URL: filter_pre_commit_hooks-2.0.3.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24128025b9d4b34a86291a2572c220bbfe2aafb42d2820c1cc49bf259a005541
|
|
| MD5 |
d7295fece622471b6822d808a408c4b0
|
|
| BLAKE2b-256 |
063e15a2818df8829f0d775cfe990d947aec26bc8dc56677c9fe52b02d582ef9
|
Provenance
The following attestation bundles were made for filter_pre_commit_hooks-2.0.3.tar.gz:
Publisher:
release.yaml on trallnag/filter-pre-commit-hooks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
filter_pre_commit_hooks-2.0.3.tar.gz -
Subject digest:
24128025b9d4b34a86291a2572c220bbfe2aafb42d2820c1cc49bf259a005541 - Sigstore transparency entry: 173062778
- Sigstore integration time:
-
Permalink:
trallnag/filter-pre-commit-hooks@116df5f197e784821afc9d635a3d6dc089c63302 -
Branch / Tag:
refs/tags/v2.0.3 - Owner: https://github.com/trallnag
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@116df5f197e784821afc9d635a3d6dc089c63302 -
Trigger Event:
push
-
Statement type:
File details
Details for the file filter_pre_commit_hooks-2.0.3-py3-none-any.whl.
File metadata
- Download URL: filter_pre_commit_hooks-2.0.3-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb830e40580c1470a042b4bbe5d5c5c09e7fb038993eda6511d25e5d3e8f361
|
|
| MD5 |
c53e4d375cb591330900eca8bf9b56e6
|
|
| BLAKE2b-256 |
e9ac64a6c1b2a834c0da219087a8e6bcb8854536dc78ea60b8143d6cab8a031d
|
Provenance
The following attestation bundles were made for filter_pre_commit_hooks-2.0.3-py3-none-any.whl:
Publisher:
release.yaml on trallnag/filter-pre-commit-hooks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
filter_pre_commit_hooks-2.0.3-py3-none-any.whl -
Subject digest:
ffb830e40580c1470a042b4bbe5d5c5c09e7fb038993eda6511d25e5d3e8f361 - Sigstore transparency entry: 173062779
- Sigstore integration time:
-
Permalink:
trallnag/filter-pre-commit-hooks@116df5f197e784821afc9d635a3d6dc089c63302 -
Branch / Tag:
refs/tags/v2.0.3 - Owner: https://github.com/trallnag
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@116df5f197e784821afc9d635a3d6dc089c63302 -
Trigger Event:
push
-
Statement type: