zoukankan      html  css  js  c++  java
  • pre-commit 在python项目中新建hooks

    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]
  • 相关阅读:
    第13篇-通过InterpreterCodelet存储机器指令片段
    第12篇-认识CodeletMark
    第11篇-认识Stub与StubQueue
    第10篇-初始化模板表
    第9篇-字节码指令的定义
    Java虚拟机漫漫学习路,我终于悟了
    Unity真机连接profiler
    提取图片中文字方法
    登录锁定个人收藏代码
    java判断密码是否为复杂类型(同时包含大小写和数字)
  • 原文地址:https://www.cnblogs.com/wangyingblock/p/11984617.html
Copyright © 2011-2022 走看看