Python/pep8

From Omnia
Revision as of 19:21, 10 December 2020 by Kenneth (talk | contribs) (→‎pep8)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

pycodestyle

See Python/pycodestyle

pep8 has been renamed to pycodestyle (GitHub issue #466)
Use of the pep8 tool will be removed in a future release.
Please install and use `pycodestyle` instead.


pep8

Python Package Index : pep8 0.6.1 - http://pypi.python.org/pypi/pep8

Python style guide checker
pep8 is a tool to check your Python code against some of the style conventions in PEP 8.

PEP 8 -- Style Guide for Python Code - http://www.python.org/dev/peps/pep-0008/

This document gives coding conventions for the Python code comprising the

standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.

Apt Installation:

apt-get install pep8

pip install:

pip install pep8

Manual Installation:

mkdir -p ~/.src ; cd ~/.src
wget http://pypi.python.org/packages/source/p/pep8/pep8-0.6.1.tar.gz#md5=49380cdf6ba2e222e8630cb0afe29d66 --no-check-certificate
tar -zvxf pep8-0.6.1.tar.gz
cd pep8-0.6.1
sudo python setup.py install  # requires setuptools

NOTE: Make sure to fix the '#!/usr/bin/python' in /opt/python26/bin/pep8 Executable:

/opt/python26/bin/pep8

Fix python version used:

sudo sed -i 's%#!/usr/bin/python%#!/usr/bin/env python%' /opt/python26/bin/pep8
NOTE: modify first line:
  #!/usr/bin/python
to
  #!/usr/bin/env python

Example usage:

$ pep8 animal.py
animal.py:2:3: E111 indentation is not a multiple of four
animal.py:6:3: E301 expected 1 blank line, found 0
animal.py:139:80: E501 line too long (80 characters)

Options:

 -r, --repeat         show all occurrences of the same error
 --show-source        show source code for each error
 --show-pep8          show text of PEP 8 for each error

Ignore long lines:

pep8 --ignore E501 animal.py

Alias:

alias pep8="pep8 --ignore E501"

Change max line length to 120:

sudo sed -i 's/MAX_LINE_LENGTH = 79/MAX_LINE_LENGTH = 119/g' /opt/python27/lib/python2.7/site-packages/pep8-0.6.1-py2.7.egg/pep8.py
# on other systems
sudo sed -i 's/MAX_LINE_LENGTH = 79/MAX_LINE_LENGTH = 119/g' usr/lib/python2.6/site-packages/pep8.py