# Installation
To ensure black, ruff, mypy, and the tests are run on every commit, you can set up pre-commit hooks.
```
poetry add --group dev pre-commit
poetry install
git commit -a -m "Added pre-commit to dev."
```
# Configuration
Now create your configuration in `.pre-commit-config.yaml`, for example, via
```
poetry run pre-commit sample-config > .pre-commit-config.yaml
```
A more targeted setup might be (adjust `default_language_version` if relevant):
```yaml
cat << PRECOMMIT > .pre-commit-config.yaml
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
hooks:
- id: pyupgrade
args:
- --py3-plus
- --keep-runtime-typing
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.275
hooks:
- id: ruff
args:
- --fix
- --show-fixes
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
hooks:
- id: prettier
exclude: ^poetry.lock
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
- repo: https://github.com/pycqa/bandit
rev: 1.7.5
hooks:
- id: bandit
name: bandit
exclude: ^tests/
args:
- -r
- src
- repo: local
hooks:
- id: pytest
name: pytest
entry: poetry run pytest
language: system
types: [python]
pass_filenames: false
PRECOMMIT
```
# Setup
After you set up the configuration YAML file, you need to install the hooks via:
```
poetry run pre-commit install --install-hooks --overwrite
```
FInally, add the pre-commit configuration to your index:
```
git add .pre-commit-config.yaml
git commit -m "Added pre-commit config."
```