In every software development project adhering to coding standards is a must (even if the code will be read and used by a single author). Python is not the exception, there are coding guidelines that cover all the relevant pieces, and those are all included in the Python Enhancement Proposal 8
Sometimes is hard to keep track of all those guidelines, and to help with this, a Python tool called Pylint has been developed.
This article will guide you step-by-step on how to configure Pylint in the Eclipse IDE in order to do auto-formatting and inspect your code for continuous improvement.
- Install PyLint:
py -3 -m pip install pylint - Launch Eclipse
- Go to Window->Preferences
- Go to PyDev->Editor->Code Analysis->PyLint
- Check "Use PyLint"
- Check "Redirect PyLint output to console?"
- Select "Specify Location"
- Browse to your Python/Script folder, and select pylint[.exe]
- Set the following configuration:
FATAL: Error
ERRORS: Error
WARNINGS: Warning
CONVENTIONS: Ignore
REFACTOR: Ignore - In the argument text area, enter:
--max-line-length=120 - If required, configure any of your project folder as a source folder.
- Go to Project->Properties
- Select PyDev - PYTHONPATH
- Click on "Add Source Folder"
- Select the project.
- Click "OK"
- Click on "Add Source Folder"
- Select the folder.
- Click "OK"
- Click "Apply and Close"
Now, every time you save the file you're editing, Eclipse will execute pylint to inspect the code. You should expect to see:
- Code format automatically updated.
- Indicators about the error tolerance of your code in the 'Console' view.
This will give you enough to play and improve your coding skills.