日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

git+pylint实现python提交代码格式校验

發(fā)布時間:2025/3/11 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 git+pylint实现python提交代码格式校验 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

環(huán)境:win10(64),python3.7.1,git2.7.2,pylint-2.3.1,git_pylint_commit_hook-2.5.1

以上為當期搭建所用到的版本,有異常時方便查找問題。

安裝pylint,pylint是一個單獨可以對python文件進行格式校驗的模塊,https://www.pylint.org/?官網(wǎng)地址有各個電腦環(huán)境的安裝說明,Windows下,使用:

pip install pylint

安裝完成之后,就可以直接使用pylint對python文件進行格式的檢查了,要檢查的文件如下:

  • print("啦啦啦")

  • def func():

  • print("do something special")

  • ?
  • def func1():

  • print("sdfsd")

  • 執(zhí)行結(jié)果如下:?

  • $ 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函數(shù)說明"""

  • print("do something special")

  • ?
  • def func1():

  • """func1函數(shù)說明"""

  • print("sdfsd")

  • 看最后的輸出rated at 4.00/10。就是所有代碼滿分是10分,當前代碼得分為4分,以上會說明缺少那些操作,把相應(yīng)的操作補上,分數(shù)就會漲上去,這章就不具體解釋缺少操作的含義。

    previous run:4.00/10,+0.00。上次得分和相對上次得分的漲幅或扣分,沒有就和當前得分一樣。

    以上的最低分可以通過配置進行設(shè)置,下面會講到如何設(shè)置。

    但是,這樣操作的話,需要開發(fā)人員自覺去遵守執(zhí)行,確保代碼全都符合條件了再提交上去,但是人無完人,項目任務(wù)繁重的時候難免會忘記,而且這種做法本身也比較low。本著科技為第一生成力,我們希望在git commit的時候,就進行代碼檢查,通過的代碼將會提交成功,進而才能push到服務(wù)端。沒通過的代碼,將打印出得分、修改的相關(guān)信息、位置直到開發(fā)人員完畢通過檢查為止。

    接下來的配置將滿足以上需求。

    有幸找到一遍軟文,介紹如何操作?https://kirankoduru.github.io/python/pylint-git-hooks.html?,但是其中有些坑,由于該文章沒有透露它的環(huán)境相關(guān)信息,我照著操作了一遍,并不好使,花了一些時間去排除,所以還是以本篇文章為準。

    安裝 git-pylint-commit-hook,如果使用的是python版本和我一致,就別指定版本為2.0.7

  • #pip install git-pylint-commit-hook==2.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 以外的內(nèi)容全部刪除,如果不刪除的話,提交的代碼檢查不通過,也會被提交!(第二個坑)

    這個其實文章里有說明,當時操作的時候沒注意,如果以后有需求的話,可以先做個備份。

    往pre-commit添加內(nèi)容,最后其中的所有內(nèi)容為

  • #!/bin/sh

  • git-pylint-commit-hook

  • 到現(xiàn)在,上面的完整的需求就滿足了,趕緊拿一個python項目進行測試看看。

    最后說一些額外的配置

    最低分設(shè)置:--limit,下面將最低分設(shè)置為9分

  • #!/bin/sh

  • git-pylint-commit-hook --limit=9.0

  • 其他很多設(shè)置:可以通過設(shè)置配置文件,設(shè)置其他的參數(shù),留給大家去探索。

  • #!/bin/sh

  • git-pylint-commit-hook --limit=9.0 --pylintrc=.pylintrc

  • .pylintrc和pre-commit同一級目錄即可,.pylintrc的內(nèi)容如下,參考鏈接:

  • # PyLint configuration file for the project pymvpa.

  • #

  • # Agreed formatting (per yoh+michael 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 can't 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-msg=R0903,W0142,W0105,W0212,W0613,E1101,R0904

  • ?
  • [REPORTS]

  • ?
  • # set the output format. Available formats are text, parseable, colorized and

  • # html

  • output-format=parseable

  • ?
  • # Include message's id in output

  • include-ids=yes

  • ?
  • # Tells wether to display a full report or only the messages

  • # reports=no

  • ?
  • [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

  • notes=FIXME,TODO,XXX,YYY

  • ?
  • [MASTER]

  • ignore=tests

  • disable-msg=R0904,R0903,E1101,R21

  • ?

    創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

    總結(jié)

    以上是生活随笔為你收集整理的git+pylint实现python提交代码格式校验的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 国产精品.com| av在线超碰 | 亚洲妇女无套内射精 | 77777av| 国产成人片 | 2017天天干 | 日韩国产电影 | 午夜爱 | 久久亚洲av午夜福利精品一区 | 亚洲中文字幕无码一区二区三区 | 欧美性xxxxx| 久久久久久久久影院 | 久久精品一区二区三区不卡牛牛 | 在线国产视频一区 | 久久久久久人妻一区二区三区 | 黄色片网站免费 | 久久久久亚洲av无码专区桃色 | 国产精品无码专区 | 中文字幕国产精品 | 国产美女一区二区三区 | 电影一区二区三区 | 婷婷在线视频 | 久久亚洲热 | 少妇熟女视频一区二区三区 | 国产成人精品片 | 国产剧情一区 | 自拍偷拍视频在线观看 | 青青草国产在线播放 | 久久精品国产亚洲av久 | 欧美成人三级视频 | 亚洲av无码潮喷在线观看 | 婷婷影院在线观看 | 日本一区视频 | 午夜性色福利影院 | 亚洲成人高清在线 | 国产对白羞辱绿帽vk | 天天色影综合网 | 日韩黄色免费观看 | 制服.丝袜.亚洲.中文.综合懂 | 中文字幕精品一区久久久久 | 成人av免费在线看 | 91看片在线播放 | 久久久中文网 | 国产短视频一区 | 韩国日本美国免费毛片 | 日韩欧美国产视频 | 欧美一区二区三区国产 | 美女脱了裤子让男人桶 | 欧美日韩精品久久久 | 国产精品二区视频 | 人妻妺妺窝人体色www聚色窝 | 乱淫的女高中暑假调教h | 欧美一区二区三区在线视频 | 日本黄色a视频 | 中文字母av | 国产成人在线电影 | 蜜臀av性久久久久蜜臀av麻豆 | 青青草在线观看视频 | 国产日韩欧美激情 | 国产又粗又黄又爽视频 | 色综合色综合网色综合 | 日韩黄片一区二区三区 | 9色视频| 中文字幕一区二区三区在线视频 | 女女高潮h冰块play失禁百合 | 日韩一二三四五区 | 懂色av,蜜臀av粉嫩av | 欧美高清一区 | 香蕉视频在线观看免费 | www.久久成人 | 免费操人视频 | 国产一区精品视频 | 人人爱人人澡 | 中文字幕一区二区三区人妻 | 精品一区二区三区免费毛片 | 国产精品久久久久久精 | 久草麻豆| 小早川怜子久久精品中文字幕 | 日韩欧美一区二区三区在线 | 成人午夜久久 | 俄罗斯女人裸体性做爰 | 国产精品第四页 | 国产成人精品一区二区三区福利 | 99久久国产视频 | 台湾综合色 | 欧美精品观看 | 毛片123 | 羞羞的视频网站 | 国产区在线 | 国产精品12区 | 最新日韩精品 | 春色网站 | 四虎影城库| 老司机午夜在线 | 男插女视频在线观看 | 久久久久国产精品无码免费看 | 久久久久亚洲av无码网站 | 宝贝乖h调教灌尿穿环 | 久久看视频 |