flake8 PEP8 quick start

less than 1 minute read

PEP8 code style is essential for good code readability. flake8 is the prime tool to check for PEP8 compliance, as well as catch syntax errors in unexecuted code that could be a security or stability issue. That is, a CI with less than 100% code coverage will miss issues that end users may see. Thus, flake8 should be part of your continuous integration.

Install

pip install flake8

Usage

in the top directory of the particular Python package type:

flake8

Configuration

flake8 is configured via the [flake8] section of setup.cfg, which may look like:

[flake8]
max-line-length = 132
exclude = .git,__pycache__,doc/,docs/,build/,dist/,archive/

Exemption pragma

Sometimes there are lines that violate PEP8, but they must remain as is. Individual lines can be exempted from PEP8 with noqa pragma like

3==1+2  # noqa: E225

Leave a Comment