From b0c43b17d621a5f1fdd69b9fd0e9df6afa3e879f Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 3 Jan 2026 10:53:02 +0100 Subject: Add check.py This is one script which checks the code quality of Python and Dart sources. It can be symlinked as `.git/hooks/pre-commit` to guard commits of questionable quality. --- check.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 check.py 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() -- cgit v1.2.3-70-g09d2