Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:check_python_code [2013/05/20 12:57] – Added flake8 dregadhowtos:check_python_code [2018/08/07 15:51] (current) – add new way of using pylint craynic
Line 4: Line 4:
  
  
-===== Using pep8 and pylint =====+===== Using pycodestyle and pylint =====
  
-The following steps enable you to check your code with Pylint, Pyflakes and Pep8.+The following steps enable you to check your code with Pylint, Pyflakes and Pycodestyle (formerly known as pep8).
  
  
Line 18: Line 18:
 #!/bin/sh #!/bin/sh
  
-echo "======  pep8  ======" +echo "======  pycodestyle  ======" 
-pep8 $1+pycodestyle $1
 echo "======  pyflakes  ======" echo "======  pyflakes  ======"
 pyflakes $1 pyflakes $1
 echo "======  pylint  ======" echo "======  pylint  ======"
-pylint --output-format=parseable $1+pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" --reports=n $1 
 +pylint -f parseable -r n $1
 </file> </file>
  
Line 34: Line 35:
 export PYTHONPATH="$PYTHONPATH:/home/username/.pylint.d" export PYTHONPATH="$PYTHONPATH:/home/username/.pylint.d"
 </code> </code>
 +
  
  
Line 40: Line 42:
 {{ :howtos:images:check_python_code.png?direct&300|}} {{ :howtos:images:check_python_code.png?direct&300|}}
  
-Open a Python file in Geany or simply create a new file and set the filetype to +  - Open a Python file in Geany or simply create a new file and set the filetype to Python. 
-Python. Then open the "Set Build Commandsdialog in the Build menu. +  - Open the //Set Build Commands// dialog in the Build menu. 
-Set for second build command a label, e.g. "Check" and the following command:+  - Setup the custom command 
 +    * Set a label, e.g. "Check" 
 +    * Set the Command field to <code> 
 +check_python_code %f 
 +</code> 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`  
 +  - Paste the following text in the "Error regular expression" field. <code> 
 +([^:]+):([0-9]+):([0-9:]+)? .* 
 +</code> This is used by Geany to parse the output of build commands for errors to be highlighted in the editor.
  
-<code>check_python_code %f</code> 
  
-This assumes that you saved the above mentioned helper script into a path +==== Using pylint on Windows ====
-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.+
  
-Then use the following regular expression for the "Error regular expression+Gösta Ljungdahl mentioned, the following little batch script is useful to use pylint on Windows with Geany: 
-fieldThis regular expression is used by Geany to parse the output of build + 
-commands for errors to be highlighted in the editor.+<code dos pylint.bat> 
 +@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 
 +</code>
  
-<code>([^:]+):([0-9]+):([0-9:]+)? .*</code>+Of course, you need to tweak the paths to the config file and pylint.exe. 
 +The rest should be similar to the explainations above.
  
  
Line 90: Line 101:
  
  
-{{tag>howto python pep8 pyflakes python flake8}}+{{tag>howto python pep8 pycodestyle pyflakes python flake8}}
  
Print/export