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
Florian Rathgeber b049912317 Pass current directory as paths to pep8 StyleGuide
Instead of setting parse_argv to True, which fails if no config files
are present, we pass the current directory as the paths keyword
argument when creating the pep8 StyleGuide. This causes pep8 to parse
local config files as expected and works also if none are present.

Requires pep8 68d72a5d or newer.
2014-03-23 18:52:00 +00:00
bin Update this to deal with Marc and Bruno's names 2013-05-21 23:37:35 -04:00
docs Minor improvement to docs 2013-07-03 23:40:50 -04:00
flake8 Pass current directory as paths to pep8 StyleGuide 2014-03-23 18:52:00 +00:00
.hgignore Ignore .orig files 2013-01-22 09:29:07 -05:00
.hgtags Release v2.1.0 2013-10-26 15:23:55 -05:00
CHANGES.rst Changes for 2.1.0 2013-10-26 15:23:24 -05:00
CONTRIBUTORS.txt Add option parsing to setuptools integration 2013-04-17 10:33:08 -04:00
dev-requirements.txt Re-add mock since I forgot it was actively being used 2013-10-12 21:29:19 -05:00
LICENSE Remove broken and useless tests. Update LICENSE 2013-07-04 13:46:28 -04:00
MANIFEST.in Fix recursive-include pattern in MANIFEST.in 2013-03-29 19:19:21 -04:00
README.rst we want those links in the doc 2013-06-19 11:48:22 +02:00
run_tests.py Start new tests 2013-07-04 13:47:01 -04:00
setup.py Re-add mock since I forgot it was actively being used 2013-10-12 21:29:19 -05: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.

Questions or Feedback
=====================

If you have questions you'd like to ask the developers, or feedback you'd like
to provide, feel free to use the mailing list: code-quality@python.org We
would love to hear from you. Additionally, if you have a feature you'd like to
suggest, the mailing list would be the best place for it.

.. _links:

Links
=====

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

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