Skip to main content

the modular source code checker: pep8, pyflakes and co

Project description

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.

CHANGES

2.2.1 - 2014-06-30

  • Turn off multiple jobs by default. To enable automatic use of all CPUs, use --jobs=auto. Fixes #155 and #154.

2.2.0 - 2014-06-22

  • New option doctests to run Pyflakes checks on doctests too

  • New option jobs to launch multiple jobs in parallel

  • Turn on using multiple jobs by default using the CPU count

  • Add support for python -m flake8 on Python 2.7 and Python 3

  • Fix Git and Mercurial hooks: issues #88, #133, #148 and #149

  • Fix crashes with Python 3.4 by upgrading dependencies

  • Fix traceback when running tests with Python 2.6

  • Fix the setuptools command python setup.py flake8 to read the project configuration

2.1.0 - 2013-10-26

  • Add FLAKE8_LAZY and FLAKE8_IGNORE environment variable support to git and mercurial hooks

  • Force git and mercurial hooks to repsect configuration in setup.cfg

  • Only check staged files if that is specified

  • Fix hook file permissions

  • Fix the git hook on python 3

  • Ignore non-python files when running the git hook

  • Ignore .tox directories by default

  • Flake8 now reports the column number for PyFlakes messages

2.0.0 - 2013-02-23

  • Pyflakes errors are prefixed by an F instead of an E

  • McCabe complexity warnings are prefixed by a C instead of a W

  • Flake8 supports extensions through entry points

  • Due to the above support, we require setuptools

  • We publish the documentation

  • Fixes #13: pep8, pyflakes and mccabe become external dependencies

  • Split run.py into main.py, engine.py and hooks.py for better logic

  • Expose our parser for our users

  • New feature: Install git and hg hooks automagically

  • By relying on pyflakes (0.6.1), we also fixed #45 and #35

1.7.0 - 2012-12-21

  • Fixes part of #35: Exception for no WITHITEM being an attribute of Checker for Python 3.3

  • Support stdin

  • Incorporate @phd’s builtins pull request

  • Fix the git hook

  • Update pep8.py to the latest version

1.6.2 - 2012-11-25

  • fixed the NameError: global name ‘message’ is not defined (#46)

1.6.1 - 2012-11-24

  • fixed the mercurial hook, a change from a previous patch was not properly applied

  • fixed an assumption about warnings/error messages that caused an exception to be thrown when McCabe is used

1.6 - 2012-11-16

  • changed the signatures of the check_file function in flake8/run.py, skip_warning in flake8/util.py and the check, checkPath functions in flake8/pyflakes.py.

  • fix --exclude and --ignore command flags (#14, #19)

  • fix the git hook that wasn’t catching files not already added to the index (#29)

  • pre-emptively includes the addition to pep8 to ignore certain lines. Add # nopep8 to the end of a line to ignore it. (#37)

  • check_file can now be used without any special prior setup (#21)

  • unpacking exceptions will no longer cause an exception (#20)

  • fixed crash on non-existent file (#38)

1.5 - 2012-10-13

  • fixed the stdin

  • make sure mccabe catches the syntax errors as warnings

  • pep8 upgrade

  • added max_line_length default value

  • added Flake8Command and entry points if setuptools is around

  • using the setuptools console wrapper when available

1.4 - 2012-07-12

  • git_hook: Only check staged changes for compliance

  • use pep8 1.2

1.3.1 - 2012-05-19

  • fixed support for Python 2.5

1.3 - 2012-03-12

  • fixed false W402 warning on exception blocks.

1.2 - 2012-02-12

  • added a git hook

  • now Python 3 compatible

  • mccabe and pyflakes have warning codes like pep8 now

1.1 - 2012-02-14

  • fixed the value returned by –version

  • allow the flake8: header to be more generic

  • fixed the “hg hook raises ‘physical lines’” bug

  • allow three argument form of raise

  • now uses setuptools if available, for ‘develop’ command

1.0 - 2011-11-29

  • Deactivates by default the complexity checker

  • Introduces the complexity option in the HG hook and the command line.

0.9 - 2011-11-09

  • update pep8 version to 0.6.1

  • mccabe check: gracefully handle compile failure

0.8 - 2011-02-27

  • fixed hg hook

  • discard unexisting files on hook check

0.7 - 2010-02-18

  • Fix pep8 initialization when run through Hg

  • Make pep8 short options work when run through the command line

  • Skip duplicates when controlling files via Hg

0.6 - 2010-02-15

  • Fix the McCabe metric on some loops

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-2.2.1.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8-2.2.1-py2.py3-none-any.whl (19.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file flake8-2.2.1.tar.gz.

File metadata

  • Download URL: flake8-2.2.1.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for flake8-2.2.1.tar.gz
Algorithm Hash digest
SHA256 b658b1bb414abc5a014c6030e4d8c7c4d05df15dc96194c3c7b28e831a046c36
MD5 213ddab1d44d654cbae61aacad73ae18
BLAKE2b-256 4d28434cfa0a0dfdf8df4e3ef07ff765ef98c4a4f5fa2ae24b7afefa49bbd836

See more details on using hashes here.

File details

Details for the file flake8-2.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8-2.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 289959a38419a0e466b89a0b2aeb90cc36be8ac1b402db6bac18b1113e416124
MD5 79c014a12d727e007453d7af3e5b13ad
BLAKE2b-256 11e5e9eb85c1c285c0fa39f3cfc4f5440ba82127bcdcdd16443236a73787f442

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page