#!/usr/bin/env python import os import glob import subprocess import sys def run(cmd, f): global ERRORS args = { "ormolu": ["--mode", "check"], "hlint": [], "black": ["--quiet", "--check"], "pylint": [], } ret = subprocess.run([cmd, *args[cmd], f], stdout=subprocess.PIPE) if ret.returncode != 0: ERRORS += 1 msg = ret.stdout.decode("utf-8").strip() print(f"lint error: {cmd} on {f}") if msg: print(msg) def find_files(bizroot, extensions): ret = {k: [] for k in extensions} for root, dirs, files in os.walk(bizroot, topdown=True): (dirs.remove(d) for d in dirs if d.startswith(("_", "."))) for ext in extensions: for f in files: if f.endswith(ext): ret[ext].append(os.path.join(root, f)) return ret if __name__ == "__main__": ERRORS = 0 files = find_files(os.getenv("BIZ_ROOT"), [".hs", ".py"]) for hs in files[".hs"]: run("ormolu", hs) run("hlint", hs) for py in files[".py"]: run("black", py) run("pylint", py) sys.exit(ERRORS)