Git hooks to be shared across Connecterra projects
Ensure your system has pre-commit framework installed. Get it from:
pipenv install pre-commit / pip install pre-commit.
In repo's already setup for pre-commit with a .pre-commit-config.yaml and the setup-hooks.sh script, you should simply run ./setup-hooks.sh.
Otherwise, create a .pre-commit-config.yaml. A minimal example is:
repos:
- repo: https://github.com/Connecterra/git-hooks
rev: 0.1.0 # Tag of this repo. Can also be main as branch name.
hooks:
- id: check-branch-name
- id: prepare-commit-msgBecause pre-commit install doesn't install hooks for all stages, the below command is a shortcut:
#!/bin/bash
echo "Installing all git hooks..."
pre-commit install --hook-type pre-commit --hook-type commit-msg --hook-type prepare-commit-msg
echo "Done!"Add other hooks if needed, and ensure they get registered in the .pre-commit-hooks.yaml file.
Update the git tag with the right version.
The hooks provided in this repo are useful, but far from covering all best practices to the code base. For reference, here is a reference with a more complete list of hooks to be added to python projects:
repos:
- repo: https://github.com/Connecterra/git-hooks
rev: 0.1.0 # Tag of this repo. Can also be main as branch name.
hooks:
- id: check-branch-name
- id: prepare-commit-msg
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/hadialqattan/pycln
# Removes all unused import statements
rev: v2.4.0
hooks:
- id: pycln
args: [--all]
- repo: https://github.com/pycqa/isort
# Sorts all import statements by common conventions
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
# Code formatter
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
# Linter
rev: "7.1.1"
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
# Allows running mypy. Depending on the project, extra dependencies might be needed.
rev: "v1.11.2"
hooks:
- id: mypy
args: [--ignore-missing-imports]
additional_dependencies:
- types-python-dateutil==2.8.1