Minor fixes for pep8, and add hook to validate pep8
authorMagnus Hagander <magnus@hagander.net>
Sat, 9 Feb 2019 21:50:47 +0000 (22:50 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sat, 9 Feb 2019 21:50:47 +0000 (22:50 +0100)
code/pgeusite/cmutuel/management/commands/cmscrape.py
tools/githook/pre-commit [new file with mode: 0755]

index fe4cf8611ad2110242e0586a6c8f790d48509b36..66d39a79fcbaade586e38f5991958c0b942505fa 100755 (executable)
@@ -10,7 +10,6 @@ from django.conf import settings
 
 import requests
 import io
-import urllib.request, urllib.parse, urllib.error
 import datetime
 import csv
 import sys
@@ -71,7 +70,7 @@ class Command(BaseCommand):
     help = 'Scrape the CM website for list of recent transactions'
 
     class ScheduledJob:
-        scheduled_times=[datetime.time(9,12), datetime.time(14,12), datetime.time(19,12)]
+        scheduled_times = [datetime.time(9, 12), datetime.time(14, 12), datetime.time(19, 12)]
 
         @classmethod
         def should_run(self):
@@ -113,7 +112,7 @@ class Command(BaseCommand):
         if verbose:
             self.stdout.write("Downloading form...")
 
-        r= sess.get('https://www.creditmutuel.fr/cmidf/en/banque/compte/telechargement.cgi')
+        r = sess.get('https://www.creditmutuel.fr/cmidf/en/banque/compte/telechargement.cgi')
         if r.status_code != 200:
             raise CommandError("Supposed to receive 200, got %s" % r.status_code)
 
diff --git a/tools/githook/pre-commit b/tools/githook/pre-commit
new file mode 100755 (executable)
index 0000000..caa0788
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+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
+      if [[ $F == code/* ]]; then
+       P=$(git show ":$F" | python3 -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 --config=code/setup.cfg -)
+       if [ "$?" != "0" ]; then
+           echo "Errors in $F"
+           echo "$R"
+           E=1
+       fi
+     fi
+    done
+    if [ "$E" != "0" ]; then
+       exit 1
+    fi
+
+    echo Basic python checks passed.
+fi
+