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
Ian Cordasco a1154e41df Merge branch 'bug/74' into 'master'
Refactor how we use StyleGuides for better error recovery

In bug 74 we discovered that there are some less than ideal problems
around our use of multiprocessing. This is a first attempt at fixing
74 by using a fake StyleGuide object which proxies to the real one,
and will catch and handle exceptions and then posibly retry the
operation we were trying to perform in the first place.

Currently we're only implementing that logic for StyleGuide.check_files
but we should be careful to implement this in other functions used in
hooks and elsewhere.

Note: there may be a simpler way to fix this with a context manager
that will do the right thing. That may also prove simpler to implement
but that will have a much larger impact on the code-base than this.

Related to bug #74

See merge request !36
2015-08-23 00:59:33 +00:00
bin Update this to deal with Marc and Bruno's names 2013-05-21 23:37:35 -04:00
docs docs: Adding flake8-import-order plugin to the list of available plugins 2015-08-11 08:32:43 +02:00
flake8 Add tests around the OSError retry logic 2015-08-22 19:47:42 -05:00
.gitignore Add a .gitignore file 2014-10-14 13:15:33 -07:00
.hgignore Ignore ./.tox directory 2014-03-30 23:54:36 +02:00
.hgtags Release v2.2.3 2014-08-25 19:03:13 -05:00
.travis.yml Use containers on Travis-CI 2015-07-10 08:47:44 -05:00
CHANGES.rst Update CHANGES for 2.4.1 2015-05-18 18:43:42 -05:00
CONTRIBUTORS.txt Add Corey to the CONTRIBUTORS file 2015-04-30 16:20:02 -05: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.cfg Add setup.cfg to support the wheel format 2014-04-27 00:27:56 +02:00
setup.py Raise upper bound on pyflakes 2015-06-01 07:42:03 -05:00
tox.ini Pin mock for py26 2015-07-10 09:46:57 -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/>`_