diff options
| author | xengineering <me@xengineering.eu> | 2026-01-03 10:53:02 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-01-03 11:03:59 +0100 |
| commit | b0c43b17d621a5f1fdd69b9fd0e9df6afa3e879f (patch) | |
| tree | 750405aad81e313809e614348122ece4cd3ac19f | |
| parent | 32583ee93f00a878b99c55ab7e4a11fb4c099f75 (diff) | |
| download | sia-app-b0c43b17d621a5f1fdd69b9fd0e9df6afa3e879f.tar sia-app-b0c43b17d621a5f1fdd69b9fd0e9df6afa3e879f.tar.zst sia-app-b0c43b17d621a5f1fdd69b9fd0e9df6afa3e879f.zip | |
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.
| -rwxr-xr-x | check.py | 89 |
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() |
