Herramientas de usuario

Herramientas del sitio


wiki2:python:flake8

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:

  • --count to print the number of errors.
  • --select=E4,E51,W234 to select which errors analyse.
  • --ignore=E4,E51,W234 to select which errors ignore.
  • --show-source to show the code where the error was found.
  • --output-file=OUTPUT_FILE to redirect the output to a text file.
  • --config=CONFIG to select the config file.
  • --statistics to show statistics about errors and warnings.

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.

wiki2/python/flake8.txt · Última modificación: 2020/05/09 09:25 (editor externo)