Browse Source

Add autoformat task

Getty Ritter 2 years ago
parent
commit
68452106fe
1 changed files with 13 additions and 0 deletions
  1. 13 0
      tasks.py

+ 13 - 0
tasks.py

@@ -1,3 +1,4 @@
+from datetime import datetime
 from invoke import task
 
 @task
@@ -17,3 +18,15 @@ def run(c, port=8080, host='127.0.0.1'):
 def install(c):
     '''Install the listed dependencies into a virtualenv'''
     c.run('poetry install')
+
+@task
+def fmt(c):
+    status = c.run('git status --porcelain', hide='stdout')
+    is_clean = status.stdout.strip() == ''
+    c.run("poetry run black $(find . -name '*.py')")
+
+    if is_clean:
+        date = datetime.now.isoformat()
+        c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
+    else:
+        print('Uncommitted change exist; skipping commit')