Default git hook does not produce expected output
Expected behaviour: When I do a git commit with the default git hook installed, I get a warning.
Actual behaviour in 2.4.0: There is no warning
Actual behaviour in 2.3.0: Same as expected behaviour
2.4.0 (no warning from git commit):
$ flake8 --version
2.4.0 (pep8: 1.5.7, mccabe: 0.3, pyflakes: 0.8.1) CPython 3.4.3 on Linux
$ flake8 --install-hook
$ flake8
./file.py:1:1: F821 undefined name 'my_undefined_variable'
$ git commit -m 'Message'
[master 03f2b9f] Message
1 file changed, 1 insertion(+)
create mode 100644 file.py
2.3.0 (warning from git commit):
$ flake8 --version
2.3.0 (pep8: 1.5.7, mccabe: 0.3, pyflakes: 0.8.1) CPython 3.4.3 on Linux
$ flake8 --install-hook
$ flake8
./file.py:1:1: F821 undefined name 'my_undefined_variable'
$ git commit -m 'Message'
/tmp/tmp_20fnsx7/home/bjwebb/test/flake8/file.py:1:1: F821 undefined name 'my_undefined_variable'
[master b1080db] Message
1 file changed, 1 insertion(+)
create mode 100644 file.py
Differences in the default .git/hooks/pre-commit between 2.3.0 and 2.4.0:
-import os
-from flake8.hooks import git_hook
-
-COMPLEXITY = os.getenv('FLAKE8_COMPLEXITY', 10)
-STRICT = os.getenv('FLAKE8_STRICT', False)
-IGNORE = os.getenv('FLAKE8_IGNORE')
-LAZY = os.getenv('FLAKE8_LAZY', False)
+from flake8.hooks import git_hook, get_git_param
+# `get_git_param` will retrieve configuration from your local git config and
+# then fall back to using the environment variables that the hook has always
+# supported.
+# For example, to set the complexity, you'll need to do:
+# git config flake8.complexity 10
+COMPLEXITY = get_git_param('FLAKE8_COMPLEXITY', 10)
+STRICT = get_git_param('FLAKE8_STRICT', False)
+IGNORE = get_git_param('FLAKE8_IGNORE')
+LAZY = get_git_param('FLAKE8_LAZY', False)
If I manually set IGNORE
to None
in 2.4.0, the git hook produces the expected output.
It seems that IGNORE
is set to '' by default in 2.4.0, because get_git_param returns '' by default - https://gitlab.com/pycqa/flake8/blob/master/flake8/hooks.py#L191). If git_hook is run with ignore=''
then it seems to ignore all files.
In 2.3.0 os.getenv
is used instead, which returns None
by default.