by Raaisa (firstname.lastname@example.org)
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:
pylint test_some.py –disable=missing-docstring
The git-pylint-commit-hook library says append –pylint-params PYLINT_PARAMS to your pre-commit file. A snip from the document:
For our case this translates to:
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:
Here no quotation marks are to be added but this example will give error,
Traceback (most recent call last):
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/bin/git-pylint-commit-hook", line 69, in
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'
if the pre-commit file has only the following statement:
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:
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!!