那里可以做PC28网站的,目录搜索引擎网站,wap网站 微信,做电子杂志的网站环境#xff1a;win10(64)#xff0c;python3.7.1#xff0c;git2.7.2#xff0c;pylint-2.3.1#xff0c;git_pylint_commit_hook-2.5.1
以上为当期搭建所用到的版本#xff0c;有异常时方便查找问题。
安装pylint#xff0c;pylint是一个单独可以对python文件进行格…环境win10(64)python3.7.1git2.7.2pylint-2.3.1git_pylint_commit_hook-2.5.1
以上为当期搭建所用到的版本有异常时方便查找问题。
安装pylintpylint是一个单独可以对python文件进行格式校验的模块Pylint 2.14.0-b1 documentation 官网地址有各个电脑环境的安装说明Windows下使用
pip install pylint
安装完成之后就可以直接使用pylint对python文件进行格式的检查了要检查的文件如下 print(啦啦啦) def func(): print(do something special) def func1(): print(sdfsd)
执行结果如下 $ pylint test1.py ************* Module test1 test1.py:1:0: C0111: Missing module docstring (missing-docstring) test1.py:2:0: C0111: Missing function docstring (missing-docstring) test1.py:5:0: C0111: Missing function docstring (missing-docstring) ------------------------------------------------------------------ Your code has been rated at 4.00/10 (previous run: 4.00/10, 0.00)
修改后满分代码 模块说明 print(啦啦啦) def func(): func函数说明 print(do something special) def func1(): func1函数说明 print(sdfsd)
看最后的输出rated at 4.00/10。就是所有代码满分是10分当前代码得分为4分以上会说明缺少那些操作把相应的操作补上分数就会涨上去这章就不具体解释缺少操作的含义。
previous run4.00/100.00。上次得分和相对上次得分的涨幅或扣分没有就和当前得分一样。
以上的最低分可以通过配置进行设置下面会讲到如何设置。
但是这样操作的话需要开发人员自觉去遵守执行确保代码全都符合条件了再提交上去但是人无完人项目任务繁重的时候难免会忘记而且这种做法本身也比较low。本着科技为第一生成力我们希望在git commit的时候就进行代码检查通过的代码将会提交成功进而才能push到服务端。没通过的代码将打印出得分、修改的相关信息、位置直到开发人员完毕通过检查为止。
接下来的配置将满足以上需求。
有幸找到一遍软文介绍如何操作 https://kirankoduru.github.io/python/pylint-git-hooks.html 但是其中有些坑由于该文章没有透露它的环境相关信息我照着操作了一遍并不好使花了一些时间去排除所以还是以本篇文章为准。
安装 git-pylint-commit-hook如果使用的是python版本和我一致就别指定版本为2.0.7 #pip install git-pylint-commit-hook2.0.7 第一个坑不使用该版本 pip install git-pylint-commit-hook
配置git钩子注意配置是在git客户端操作的。
进到git项目的根目录以根目录为$root$ #进到hooks目录 cd .git/hooks #配置pre-commit文件 mv pre-commit.sample pre-commit
注意将pre-commit中除了#!/bin/sh 以外的内容全部删除如果不删除的话提交的代码检查不通过也会被提交第二个坑
这个其实文章里有说明当时操作的时候没注意如果以后有需求的话可以先做个备份。
往pre-commit添加内容最后其中的所有内容为 #!/bin/sh git-pylint-commit-hook
到现在上面的完整的需求就满足了赶紧拿一个python项目进行测试看看。
最后说一些额外的配置
最低分设置--limit下面将最低分设置为9分 #!/bin/sh git-pylint-commit-hook --limit9.0
其他很多设置可以通过设置配置文件设置其他的参数留给大家去探索。 #!/bin/sh git-pylint-commit-hook --limit9.0 --pylintrc.pylintrc
.pylintrc和pre-commit同一级目录即可.pylintrc的内容如下参考链接 # PyLint configuration file for the project pymvpa. # # Agreed formatting (per yohmichael voice dialog) is camel. # # This pylintrc file will use the default settings except for the # naming conventions, which will allow for camel case naming as found # in Java code or several libraries such as PyQt, etc. # # At some moment it was modified by yoh from the original one # which can be found on debian systems at # /usr/share/doc/pylint/examples/pylintrc_camelcase # # Just place it in ~/.pylintrc for user-wide installation or simply # use within a call to pylint or export environment variable # export PYLINTRC$PWD/doc/misc/pylintrc [BASIC] # Regular expression which should only match correct module names module-rgx([a-z][a-z0-9_]*)$ attr-rgx[a-z_][a-z0-9_]{,30} # Regular expression which should only match correct class names class-rgx[A-Z_][a-zA-Z0-9]$ # Regular expression which should only match correct function names function-rgx[a-z_][a-z0-9_][a-z0-9]*$ # Regular expression which should only match correct method names # Allow upper cases in testFeatureSelection where FeatureSelection # is a class name method-rgx(([a-z_]|__)[a-z0-9_]*(__)?|test[a-zA-Z0-9_]*)$ # Regular expression which should only match correct argument names argument-rgx[a-z][a-z0-9]*_*[a-z0-9]*_*[a-z0-9]*_?$ # Regular expression which should only match correct variable names variable-rgx([a-z_][a-z0-9]*_*[a-z0-9]*_*[a-z0-9]*_?||(__[a-zA-Z0-9_]*__))$||[A-Z] # Regular expression which should only match correct module level names # Default: (([A-Z_][A-Z1-9_]*)|(__.*__))$ const-rgx([a-z_][a-z0-9]*_*[a-z0-9]*_*[a-z0-9]*_?|__[a-zA-Z0-9_]*__)$||[A-Z] [FORMAT] indent-string [DESIGN] # We are capable to follow that many, yes! max-branchs 20 # some base class constructors have quite a few arguments max-args 14 # and due to ClassWithCollections and conditional attributes classes by default have lots # of attributes max-attributes 14 # some sci computation cant be handled efficiently without having #lots of locals max-locals 35 [MESSAGES CONTROL] # Disable the following PyLint messages: # R0903 - Not enough public methods # W0105 - String statement has no effect # often used for after-line doc # W0142 - Used * or ** magic # W0232 - Class has no __init__ method # W0212 - Access to a protected member ... of a client class # W0613 - Unused argument # E1101 - Has no member (countless false-positives) # R0904 - Too many public methods disable-msgR0903,W0142,W0105,W0212,W0613,E1101,R0904 [REPORTS] # set the output format. Available formats are text, parseable, colorized and # html output-formatparseable # Include messages id in output include-idsyes # Tells wether to display a full report or only the messages # reportsno [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. # FIXME -- something which needs fixing # TODO -- future plan # XXX -- some concern # YYY -- comment/answer to above mentioned concern notesFIXME,TODO,XXX,YYY [MASTER] ignoretests disable-msgR0904,R0903,E1101,R21
任何程序错误以及技术疑问或需要解答的请添加