The following steps enable you to check your Python code for syntax errors, coding style and standards (PEP 8)
The following steps enable you to check your code with Pylint, Pyflakes and Pycodestyle (formerly known as pep8).
You need a little helper script to combine the above (and maybe other) tools to be run at once. Save this script somewhere into your $PATH or at some other location of your choice and make it executable.
#!/bin/sh echo "====== pycodestyle ======" pycodestyle $1 echo "====== pyflakes ======" pyflakes $1 echo "====== pylint ======" pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" --reports=n $1 pylint -f parseable -r n $1
You can also set environment variables like PYTHONPATH to extend or reduce the path for Python to look for modules in this script, e.g. by simply exporting the variable:
export PYTHONPATH="$PYTHONPATH:/home/username/.pylint.d"
check_python_code %f
Note: this assumes that you saved the above mentioned helper script into a path in your $PATH environment variable. If not, just specify the full path to the script. %f is a placeholder replaced by Geany on execution with the filename of the current file in the editor. OR You can also use each command i.e. `pep8`, `pyflakes` or `pylint` directly in place of `check_python_code`
([^:]+):([0-9]+):([0-9:]+)? .*
This is used by Geany to parse the output of build commands for errors to be highlighted in the editor.
Gösta Ljungdahl mentioned, the following little batch script is useful to use pylint on Windows with Geany:
@echo off set configfile=c:\cygwin64\home\gostal\.pylintrc echo "====== pylint ======" c:\Anaconda\envs\python3\Scripts\pylint.exe --rcfile=%configfile% --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" %1
Of course, you need to tweak the paths to the config file and pylint.exe. The rest should be similar to the explainations above.
Flake8 is a wrapper around several tools (PyFlakes, pep8 and Ned Batchelder's McCabe script), which also allows integration with plugins.
Using it offers a convenient and simple alternative to using the Helper Script approach described earlier in this document.
pip install flake8 pep8-naming
flake8 --show-source "%f"
After saving the helper script and setting up Geany's build commands, you are ready to use this by simply pressing F9 or using the menu Build → Check to trigger the execution of the helper script and so let the tools check your code.
All errors and warnings reported by the tools are sent to the Compiler tab in the messages windows at the bottom of the Geany window. You can see the errors for review, click on them to jump to the corresponding code line and Geany will also mark the reported code lines directly in the editor with red squiggly underlines.
Ideally, you won't see much errors in your code :). Good luck.