zoukankan      html  css  js  c++  java
  • python后端项目编码规范检查——pre-commit的使用

    1、安装pre-commit

    python3 -m pip install pre-commit
    

    2、在项目根目录下,创建一文件—— .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
    

    3、install pre-commit

    进入Python虚拟环境,安装pre-commit

    pre-commit install
    

    4、每次在代码发生变动需要add并commit时,会执行该commit hooks,做代码规范检测,没通过的话,会自动更改格式,然后才会通过,最后commit进仓库。

    git add .
    
    git commit -m "update"
    
    

    参考:

    https://www.cnblogs.com/wangyingblock/p/11984463.html

    以上。

  • 相关阅读:
    leetcode-剑指10-OK
    leetcode-剑指22-OK
    vue组件引入
    vue项目单页
    vue-cli脚手架创建vue项目
    vue生命周期
    ES6 DEMO
    ES6
    记录一个天坑
    CentOS 7防火墙快速开放端口配置方法
  • 原文地址:https://www.cnblogs.com/lovebkj/p/14991016.html
Copyright © 2011-2022 走看看