在使用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 hooks在python项目中的使用

 

 查看安装的pre-commit

cd .git/hooks

ls -l

pre-commit hooks在python项目中的使用

 安装成功!

三、运行所配置的文件规则

pre-commit run --all-files

pre-commit hooks在python项目中的使用

运行结果如图所示。 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-09-29
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2021-08-18
  • 2021-12-25
  • 2023-03-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案