pre-commit hooks在python项目中的使用
在使用pre-commit hooks之前,需要先安装pre-commit
pip install pre-commit
一、新建.pre-commit-config.yaml文件,并在里面配置你所需要的验证规则
default_stages: [commit] repos: - repo: https://github.com/yingzi113/pre-commit-hooks rev: 5863e162f1bed1f63eeb716e77d622ff8e3d9af9 hooks: - id: check-case-conflict - repo: https://github.com/pre-commit/mirrors-autopep8 rev: v1.4.4 hooks: - id: autopep8 args: [-i, --global-config=.flake8, -v] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.4.0 hooks: - id: flake8
二、install pre-commit
进入虚拟环境,安装pre-commit
pre-commit install
安装结果如下:
查看安装的pre-commit
cd .git/hooks
ls -l
安装成功!
三、运行所配置的文件规则
pre-commit run --all-files
运行结果如图所示。