Custom hooks for pre-commit#
Typically one need to install pre-commit first:
Via pip:
pip install pre-commit
Via homebrew:
brew install pre-commit
Via conda:
conda install -c conda-forge pre-commit
Once installed, you can check the version with:
pre-commit --version
Next step is to create a configuration file .pre-commit-config.yaml in the root of the repository. It's content typically looks like this:
- repo: https://github.com/adrybakov/pre-commit-hooks
rev: 0.1.0 # Check available tags on the GitHub page
hooks:
- id: <first-hook-id> # Required
.... # Optional arguments for the first hook
- id: <second-hook-id> # Required
.... # Optional arguments for the second hook
For the content of the file see page for each individual hook:
Then install the git hook scripts:
pre-commit install
See documentation for more details.
Standalone usage#
Every hook is written in python and can be used as a standalone script.
One would need to clone the repository:
git clone https://github.com/adrybakov/pre-commit-hooks.git
And install the package:
cd pre-commit-hooks
pip install .
Then the hook can be used as a standalone script:
<hook-name> <arguments> ...
You can display the help message for each script with the command:
<hook-name> --help