flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code. https://flake8.pycqa.org
Find a file
2013-02-23 14:36:08 -05:00
bin Add git-patch-to-hg-export.py 2012-11-26 09:14:13 -05:00
docs Forgot to include the extension docs in the toctree 2013-02-23 14:36:08 -05:00
flake8 Get ready for 2.0 2013-02-22 23:33:36 -05:00
scripts added cmd script (and scripts subfolder) 2012-09-05 17:59:29 -04:00
.hgignore Ignore .orig files 2013-01-22 09:29:07 -05:00
.hgtags Release 1.7.0 2012-12-21 17:50:52 -05:00
CHANGES.rst Fix the RTD URL 2013-02-23 14:34:56 -05:00
CONTRIBUTORS.txt Add Ian and me as contributors 2013-02-20 18:39:54 +01:00
LICENSE Do not copy the licenses for the dependencies 2013-02-21 23:56:35 +01:00
MANIFEST.in Include the *.rst files in MANIFEST.in 2013-02-21 23:59:41 +01:00
README.rst Re-use the README to avoid duplication with the documentation 2013-02-23 13:19:12 +01:00
setup.py Upgrade requirements to pep8 1.4.3 and mccabe 0.2 2013-02-22 08:30:37 +01:00

======
Flake8
======

Flake8 is a wrapper around these tools:

- PyFlakes
- pep8
- Ned Batchelder's McCabe script

Flake8 runs all the tools by launching the single ``flake8`` script.
It displays the warnings in a per-file, merged output.

It also adds a few features:

- files that contain this line are skipped::

    # flake8: noqa

- lines that contain a ``# noqa`` comment at the end will not issue warnings.
- a Git and a Mercurial hook.
- a McCabe complexity checker.
- extendable through ``flake8.extension`` entry points.


QuickStart
==========

::

    pip install flake8

To run flake8 just invoke it against any directory or Python module::

    $ flake8 coolproject
    coolproject/mod.py:97:1: F401 'shutil' imported but unused
    coolproject/mod.py:625:17: E225 missing whitespace around operato
    coolproject/mod.py:729:1: F811 redefinition of function 'readlines' from line 723
    coolproject/mod.py:1028:1: F841 local variable 'errors' is assigned to but never used

The outputs of PyFlakes *and* pep8 (and the optional plugins) are merged
and returned.

flake8 offers an extra option: --max-complexity, which will emit a warning if
the McCabe complexity of a function is higher than the value.  By default it's
deactivated::

    $ flake8 --max-complexity 12 coolproject
    coolproject/mod.py:97:1: F401 'shutil' imported but unused
    coolproject/mod.py:625:17: E225 missing whitespace around operator
    coolproject/mod.py:729:1: F811 redefinition of unused 'readlines' from line 723
    coolproject/mod.py:939:1: C901 'Checker.check_all' is too complex (12)
    coolproject/mod.py:1028:1: F841 local variable 'errors' is assigned to but never used
    coolproject/mod.py:1204:1: C901 'selftest' is too complex (14)

This feature is quite useful to detect over-complex code.  According to McCabe,
anything that goes beyond 10 is too complex.
See https://en.wikipedia.org/wiki/Cyclomatic_complexity.


.. _links:

Links
=====

* `flake8 documentation <http://flake8.readthedocs.org/en/latest/>`_

* `pep8 documentation <http://pep8.readthedocs.org/en/latest/>`_