Better Code Quality with Python, PyCharm & Pylint
Have less bugs and better code style in Python with Pylint static code analysis- This is how to do that (With PyCharm IDE):
Install pylint: pip install pylint
Use pylint as an external tool- unfortunately PyCharm doesn’t support changing its python linter:
Go to Pycharm > Preferences > Tools > External Tools > Add (“+” sign) > Fill in the details of pylint:
Pay attention I am not calling the pylint program, but a script I have. This script is in order to have one centralized place that holds the pylint run configuration, able to run on a single file or on a complete dir tree and finally it knows to work inside your python virtualenv (to be able to validate import
s):
run_pylint_validation.sh:
#!/bin/bash# No files argument will run on all dir tree
FILES=${1:-"*.py"}# Should get path from inside the virtualenv
PYLINT_PATH=${2:-"pylint"}# Disable common bugs with pylint 1.6.4
find . -type f -name "$FILES" | xargs $PYLINT_PATH --reports=n --disable=C0111,E0401,W0621,E1129,E0202 --rcfile=~/.pylintrc
One final very useful thing to be able to shoot up the pylint validation on the file currently active on PyCharm is to link it to a keystroke:
That’s it! Now you can mark your code on the editor > right click > tools > pylint. This will show you a report of the errors.
Happy coding :)