Add a githook and a config file to run pep8 pre-commit

This commit is contained in:
Magnus Hagander
2019-01-17 21:26:41 +01:00
parent 00ab822ea8
commit f91181fb13
2 changed files with 43 additions and 0 deletions

5
setup.cfg Normal file
View File

@ -0,0 +1,5 @@
[pycodestyle]
statistics=True
exclude=dep/*,pgweb/settings_local.py
ignore=E116,E402,E501,E741
max-line-length=120

38
tools/githook/pre-commit Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
FILES=$(git diff-index --name-only --diff-filter=ACMR --cached $against -- |egrep ".py$")
if [ "$FILES" != "" ]; then
# We want to look at the staged version only, so we have to run it once for
# each file.
E=0
for F in ${FILES}; do
P=$(git show ":$F" | python -c "import sys; compile(sys.stdin.read(), '/dev/null', 'exec')")
if [ "$?" != "0" ]; then
echo "Errors in $F"
echo $P
E=1
continue
fi
R=$(git show ":$F" | pep8 -)
if [ "$?" != "0" ]; then
echo "Errors in $F"
echo "$R"
E=1
fi
done
if [ "$E" != "0" ]; then
exit 1
fi
echo Basic python checks passed.
fi