From d8a8c2458461fb0fc035d0c9a606cf76f7757057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 13 Jul 2016 12:07:03 +0100 Subject: [PATCH 1/2] pre-commit: fix warnings and errors Properly print warnings to stderr. Also, use : instead of 'echo' as a fallback as the latter spits out garbage to stdout. Examples without pep8 installed. Before: $ ./hooks/pre-commit ./hooks/pre-commit: line 97: WARNING:: command not found ERROR: pep8 tests failed! After: $ ./hooks/pre-commit WARNING: pep8 is not installed, using dummy placeholder! --- hooks/pre-commit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 1929ee91..662e5787 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -59,12 +59,12 @@ fi PEP8_IGNORE="E123,E501,W503" err() { - echo ERROR: "$@" + echo >&2 ERROR: "$@" exit 1 } warn() { - echo WARNING: "$@" + echo >&2 WARNING: "$@" } cmd_exists() { @@ -81,7 +81,7 @@ find_command() { fi done warn "$1 is not installed, using dummy placeholder!" - echo -n echo + echo -n : } PYFLAKES=$(find_command pyflakes) From b53e56916c23133788216589e47ddb1aac899a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 13 Jul 2016 12:14:19 +0100 Subject: [PATCH 2/2] pre-commit: pep8 is now pycodestyle See https://github.com/PyCQA/pycodestyle/issues/466. --- hooks/pre-commit | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 662e5787..45a5b052 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -72,20 +72,21 @@ cmd_exists() { } find_command() { - local name=$1 - for suff in "3" "-python3" ""; do - cmd=${1}${suff} - if cmd_exists $cmd; then - echo $cmd - return 0 - fi + for name in $@; do + for suff in "3" "-python3" ""; do + cmd=${name}${suff} + if cmd_exists $cmd; then + echo $cmd + return 0 + fi + done done warn "$1 is not installed, using dummy placeholder!" - echo -n : + echo : } PYFLAKES=$(find_command pyflakes) -PEP8=$(find_command pep8) +PEP8=$(find_command pycodestyle pep8) if [ "$PY_FILES $PY_TEST_FILES" != " " ]; then if ! $PYFLAKES $PY_FILES $PY_TEST_FILES; then