Passing pylint parameters with git-pylint-commit-hook

by Raaisa (raaisa@elucidata.io)
PEP8 guidelines state ‘a code is read much more often than it is written’. Writing a clean code is as important as writing a working code and maintaining code cleanliness can get tough when ignored for long.

If you are a git user, a pylint fan and too lazy to run pylint manually each time, git-pylint-commit-hook might help.
As the name says, it’s a pre-commit git-hook for pylint. One can find other examples of git pylint hooks.
I worked with the library as it could be installed easily with pip. The documentation could be found here.
The documentation helped me setup the hook but I was stuck while passing some extra pylint parameters. Figured it out finally, thanks to google and here it is. I wanted to disable missing-docstring message for test files. If run directly via pylint this could be done by:

[code lang=text]
pylint test_some.py –disable=missing-docstring

[/code]

The git-pylint-commit-hook library says append –pylint-params PYLINT_PARAMS to your pre-commit file. A snip from the document:

Screen_Shot_2016-04-22_at_5.25.41_pm

For our case this translates to:

[code lang=text]
git-pylint-commit-hook –pylint-params='–disable=missing-docstring'

[/code]

in the pre-commit file. Works for git-pylint-commit-hook V 2.1.1.

The latest version also supports .pylintrc. I tried adding the above pylint parameters through .pylintrc. Our example can be run by writing in the .pylintrc file:

[code lang=text]
[pre-commit-hook]
params=–disable=missing-docstring

[/code]

Here no quotation marks are to be added but this example will give error,

[code lang=text]
Traceback (most recent call last):
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/bin/git-pylint-commit-hook", line 69, in
main()
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/bin/git-pylint-commit-hook", line 62, in main
args.limit, args.pylint, args.pylintrc, args.pylint_params, args.suppress_report)
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/lib/python2.7/site-packages/git_pylint_commit_hook/commit_hook.py", line 177, in check_repo
pylint_params += ' ' + conf.get('pre-commit-hook', 'params')
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

[/code]

if the pre-commit file has only the following statement:

[code lang=text]
git-pylint-commit-hook

[/code]

This is probably a bug in the library. Till resolved try the following. Instead of just git-pylint-commit-hook, add –pylint-params to it:

[code lang=text]
git-pylint-commit-hook –pylint-params=’some_pylint_parameter’

[/code]

It should work now. It will consider both pre-commit file parameters and .pylintrc parameters.
And last but not the least, you might not want to always run pylint when committing a code. There is always –no-verify for that!!

Vipul Jain Written by:

One Comment

  1. November 23, 2018
    Reply

    That’s a knowing answer to a difficult question

Leave a Reply

Your email address will not be published. Required fields are marked *