summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xbin/git-pre-commit-hook22
-rwxr-xr-xbin/style-check6
3 files changed, 29 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 56ec8b13..c81e2a98 100644
--- a/Makefile
+++ b/Makefile
@@ -49,4 +49,4 @@ version:
.PHONY: style
style:
- flake8 . --count --max-complexity=10 --max-line-length=150 --statistics --exclude=pyembroidery,__init__.py,electron,build,src,dist
+ bash -x bin/style-check
diff --git a/bin/git-pre-commit-hook b/bin/git-pre-commit-hook
new file mode 100755
index 00000000..2a65775a
--- /dev/null
+++ b/bin/git-pre-commit-hook
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# copy (DO NOT SYMLINK) this file to .git/hooks/pre-commit
+# to check style on all modified files before allowing the commit to complete
+#
+# DO NOT SYMLINK
+# DO NOT SYMLINK
+# DO NOT SYMLINK (why? security risk)
+
+cd $(dirname "$0")/../..
+
+IFS=$'\n'
+files=( $(git diff-index --cached --name-only --diff-filter=AMCR HEAD) )
+
+if [ "${#files}" -gt 0 ]; then
+ errors=$(bin/style-check "${files[@]}" 2>&1)
+
+ if [ "$?" != "0" ]; then
+ echo "$errors"
+ exit 1
+ fi
+fi
diff --git a/bin/style-check b/bin/style-check
new file mode 100755
index 00000000..ead4d553
--- /dev/null
+++ b/bin/style-check
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Checks Python coding style based on our project's preferences. Checks the
+# files passed on the command-line or everything if no files are passed.
+
+flake8 --count --max-complexity=10 --max-line-length=150 --statistics --exclude=pyembroidery,__init__.py,electron,build,src,dist "${@:-.}"