summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2019-01-03 21:00:32 +0000
committerMagnus Hagander2019-01-03 21:00:32 +0000
commitf668603f0091089ff0e4e3f0fd4f1cff3871ba04 (patch)
tree50bead42fb6ac17440870f30a0badd6e1202d5b6
parent1632a546c63b8cfadafbb26bd5a394b50ba0d5dd (diff)
Add pep8 commit hook and config filepy3
-rw-r--r--setup.cfg5
-rwxr-xr-xtools/githook/pre-commit37
2 files changed, 42 insertions, 0 deletions
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..5e3912a
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[pycodestyle]
+statistics=True
+exclude=loader/legacy/*
+ignore=E402,E501,E741
+;max-line-length=120
diff --git a/tools/githook/pre-commit b/tools/githook/pre-commit
new file mode 100755
index 0000000..c7dec86
--- /dev/null
+++ b/tools/githook/pre-commit
@@ -0,0 +1,37 @@
+#!/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 $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
+