Tabla de Contenidos

Flake8

Basic usage

Documentation:

Install:

pip install flake8

To use it for a folder:

# for the current path
flake8
# or
python -m flake8
# or
flake8 /the/path

To use it for a file:

flake8 path/to/file.py

The output format is:
file path : line number : column number : error code : short description

Flake8 will exit with code 1 if there are errors. You can change this using the parameter: --exit-zero

Error code prefix:

Configuration

You can configure the flake8 analysis using its command parameters (http://flake8.pycqa.org/en/latest/user/options.html) or placing them in a file named setup.cfg in the project root.

[flake8]
exclude = .git,*migrations*
max-line-length = 119

Ignoring errors

Just add # noqa in the end of the line.

def ready(self):
    import cmdbox.profiles.signals.handlers  # noqa

Or you can pass the specific error code you want to ignore:

import cmdbox.profiles.signals.handlers  # noqa: F401

Using it with...

Interesting usages

Parameters:

Using hooks for version control

http://flake8.pycqa.org/en/latest/user/using-hooks.html

You can stop a commit if flake8 find errors.

Plugins

To see which plugins are enabled:

flake8 --version

To temporally enable disabled plugins: --enabled-extensions=ENABLED_EXTENSIONS.