Passing pylint parameters with GIT-pylint-commit-hook

Passing pylint parameters with GIT-pylint-commit-hook

July 13, 2016

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 set up 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 –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:

Passing pylint parameters with GIT-pylint-commit-hook

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, inmain()File “/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/bin/git-pylint-commit-hook”, line 62, in mainargs.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/”, line 177, in check_repopylint_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 least, you might not want to always run pylint when committing code. There is always –no-verify for that!!

Try Polly! A data analysis platform, book your demo today!

Subscribe to our newsletter
Only data insights. No spam!
Thank you! Please click on the link to start the download.
Download Now
Oops! Something went wrong while submitting the form.

Blog Categories