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 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:
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:
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/commit_hook.py”, 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:
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!!
Get the latest insights on Biomolecular data and ML