2019.08.01 See below as it is old. ** The story of Python hated by cowboys ** https://qiita.com/mima_ita/items/cabcf014aa08e27c8de7
This document describes how to check for violations of PEP8, the coding style for Python code.
PEP 8 -- Style Guide for Python Code http://legacy.python.org/dev/peps/pep-0008/
Translation: https://dl.dropboxusercontent.com/u/555254/pep-0008.ja.html
PEP8 --Install Python style guide checker https://pypi.python.org/pypi/pep8/
easy_install pep8
Or
pip install pep8
This allows you to run pep8 from the command line.
pep8 test.py
pep8 /test/directory
If you specify a directory, check the subdirectories as well
Option name | Description |
---|---|
--version | Show version |
-h,--help | Get help |
-v,--verbose | Display status messages such as the name of the file being checked.--Debug messages are displayed in vv |
-q,--quiet | Display only the file name.-qq does not display anything. |
--first | In case of the same error, display only at the beginning |
--exclude=patterns | Describe the pattern of file names and directory names to be excluded. You can have more than one by separating them with commas. Default:.svn,CVS,.bzr,.hg,.git,pycache |
--filename=patterns | When searching a directory, only files with the pattern specified here are searched. You can specify multiple items separated by commas. Default: *.py |
--select=errors | Specify errors and warnings Example: E,W6 |
--ignore=errors | Ignore the specified error Example: E,W6 |
--show-source | Show source for each error |
--show-pep8 | Add a description of PEP8 to each error.--You should use it with first |
--statistics | Aggregate the number of errors and warnings and display at the end |
--count | Finally, display the total number of errors and warnings |
--config=path | You can specify the location of the configuration file. |
The value of each option can be specified in the configuration file that can be specified with the config option.
[pep8]
ignore = E111
It can also be used from Python by importing pep8.
import pep8
pep8style = pep8.StyleGuide(quiet=True)
ret = pep8style.check_files(['test.py']);
print ret.total_errors
Aggregation is possible using Violations, a Jenkins plugin.
When executing from a shell script, it is necessary to write "#! / Bin / sh" at the beginning and process that does not return an error code at the end as follows.
#!/bin/sh
pep8 /share/py/test.py > ${WORKSPACE}/test.txt
echo "....finished"
See the page below for the reason why you need to do this. About running the Jenkins shell The settings for Violations are as follows.
There is no need to output in XML.
Recommended Posts