1.Install pre-commit
pip install pre-commit
2. Add a pre-commit configuration
create a file named .pre-commit-config.yaml
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: '^(.*/migrations/.*)$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- id: flake8
args:
- --ignore=E501
additional_dependencies:
- flake8-bugbear
- pep8-naming
- repo: https://github.com/ambv/black
rev: 18.9b0
hooks:
- id: black
- repo: https://github.com/sqlalchemyorg/zimports
rev: 618d03090c232a05d605d3f1099e1b3ec5097587
hooks:
- id: zimports
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.670
hooks:
- id: mypy
default_stages:
- push
3. Install the git hook scripts
执行 pre-commit install --install-hooks -t pre-push
安装 pre-push 钩子
4. (optional) Run against all the files
pre-commit run --all-files