added a git hook - fixes #8

This commit is contained in:
Tarek Ziade 2012-02-14 14:20:51 +01:00
parent 6eb3405dd0
commit e439682c85
2 changed files with 68 additions and 9 deletions

45
README
View file

@ -37,7 +37,7 @@ To run flake8 just invoke it against any directory or Python module::
The output of PyFlakes *and* pep8 is merged and returned.
flake8 offers an extra option: --max-complexity, which will emit a warning if the
McCabe complexityu of a function is higher that the value. By default it's
McCabe complexityu of a function is higher that the value. By default it's
deactivated::
$ bin/flake8 --max-complexity 12 flake8
@ -50,7 +50,7 @@ deactivated::
coolproject/mod.py:1204:1: '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.
that goes beyond 10 is too complex.
See https://en.wikipedia.org/wiki/Cyclomatic_complexity.
@ -72,27 +72,56 @@ like this::
If *strict* option is set to **1**, any warning will block the commit. When
*strict* is set to **0**, warnings are just displayed in the standard output.
*complexity* defines the maximum McCabe complexity allowed before a warning
*complexity* defines the maximum McCabe complexity allowed before a warning
is emited. If you don't specify it it's just ignored. If specified, must
be a positive value. 12 is usually a good value.
Git hook
========
To use the Git hook on any *commit*, add a **pre-commit** file in the
*.git/hooks* directory containing::
#!/usr/bin/python
import sys
from flake8.run import git_hook
COMPLEXITY = 10
STRICT = False
if __name__ == '__main__':
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT))
If *strict* option is set to **True**, any warning will block the commit. When
*strict* is set to **False** or omited, warnings are just displayed in the
standard output.
*complexity* defines the maximum McCabe complexity allowed before a warning
is emited. If you don't specify it or set it to **-1**, it's just ignored.
If specified, it must be a positive value. 12 is usually a good value.
Also, make sure the file is executable and adapt the shebang line so it
point to your python interpreter.
Buildout integration
=====================
In order to use Flake8 inside a buildout, edit your buildout.cfg and add this::
[buildout]
parts +=
...
flake8
[flake8]
recipe = zc.recipe.egg
eggs = flake8
${buildout:eggs}
entry-points =
flake8=flake8.run:main
flake8=flake8.run:main
Original projects
=================
@ -111,7 +140,9 @@ CHANGES
1.2 - ?
-------
?
- added a git hook
-
1.1 - 2012-02-14
----------------