summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/check.py b/check.py
new file mode 100755
index 0000000..858309c
--- /dev/null
+++ b/check.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+
+
+import pathlib
+import subprocess
+import shutil
+import sys
+
+
+SCRIPT = pathlib.Path(__file__).resolve()
+ROOT = SCRIPT.parent
+
+
+def main() -> None:
+ print("Checking source files ...")
+
+ success = True
+
+ for check in (mypy, flake8, black, flutter_analyze):
+ print(f"Checking with {check.__name__} ...")
+ try:
+ check()
+ print(f"OK - {check.__name__} succeeded.")
+ except subprocess.CalledProcessError:
+ success = False
+
+ if not success:
+ print("At least one check failed.")
+ sys.exit(1)
+
+ print("Finished without errors.")
+
+
+def mypy() -> None:
+ command = [
+ "mypy",
+ "--strict",
+ ]
+
+ for f in get_python_files():
+ command.append(str(f))
+
+ subprocess.run(command, shell=False, check=True)
+
+
+def flake8() -> None:
+ command = [
+ "flake8",
+ ]
+
+ for f in get_python_files():
+ command.append(str(f))
+
+ subprocess.run(command, shell=False, check=True)
+
+
+def black() -> None:
+ command = [
+ "black",
+ "--check",
+ ]
+
+ for f in get_python_files():
+ command.append(str(f))
+
+ subprocess.run(command, shell=False, check=True)
+
+
+def get_python_files() -> tuple[pathlib.Path, ...]:
+ return tuple(ROOT.glob("*.py"))
+
+
+def flutter_analyze() -> None:
+ maybe_flutter = shutil.which("flutter")
+ if maybe_flutter is None:
+ print("Could not find 'flutter' executable.")
+ sys.exit(1)
+ flutter = str(maybe_flutter)
+
+ command = [
+ flutter,
+ "analyze",
+ ]
+
+ subprocess.run(command, cwd=ROOT, shell=False, check=True)
+
+
+if __name__ == "__main__":
+ main()