hooks的新建分为两种情况:远程和本地
一、新建的hooks放在git上,使用时远程下载安装使用参考:https://github.com/pre-commit/pre-commit
1、创建一个文件夹,将你的.py文件放进去
2、创建setup.py、setup.cfg文件,配置setup.cfg文件
[options] packages = find: python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* [options.entry_points] console_scripts = check-commit-message = pre_commit_hooks.check_commit_message:main check-case-conflict = pre_commit_hooks.check_case_conflict:main
3、创建.pre-commit-hooks.yaml文件,并定义相关内容
- id: check-case-conflict name: Check for case conflicts description: Check for files that would conflict in case-insensitive filesystems entry: check-case-conflict language: python - id: check-commit-message name: Check commit message description: Check commit message. entry: check-commit-message language: python types: [python]
4、使用:在.pre-commit-config.yaml
default_stages: [commit] repos: - repo: https://github.com/yingzi113/pre-commit-hooks rev: 5863e162f1bed1f63eeb716e77d622ff8e3d9af9 hooks: - id: check-case-conflict - id: check-commit-message
注:要想拿到rev后面的代码,执行
pre-commit autoupdate
二、本地创建hooks
第一种里创建的文件和配置都需要,但同第一种有两处不同
1、需要安装setup.py
python setup.py build
python setup.py install
2、使用时reop为local,不需要rev
- repo: local hooks: - id: check-commit-message name: Check commit message description: This is deprecated, use pre-commit/mirrors-autopep8 instead. entry: check-commit-message language: system types: [python]