#!/usr/bin/env python3 """Shoal check for continuityunification. 判据(三条,缺一不算通过): 1. 提交里有 Lean 工程(lakefile + lean-toolchain),五个定理名在源码里出现; 2. 源码里没有 `sorry` / `axiom`; 3. 能 `lake build` 通过(本机没有 lake 时只做前两项,并在输出里写明"未编译")。 用法:python3 checks/check.py <提交目录> 退出码:0 = 通过,1 = 不通过。 """ import os import re import shutil import subprocess import sys REQUIRED = [ "dead_matter", # 死物 "chemistry", # 化学 "star", # 恒星 "biology", # 生物 "mathematics", # 数学 ] FORBIDDEN = re.compile(r"\b(sorry|admit)\b") AXIOM = re.compile(r"^\s*axiom\b", re.M) def lean_files(root): for dirpath, _, names in os.walk(root): for n in names: if n.endswith(".lean"): yield os.path.join(dirpath, n) def main() -> int: if len(sys.argv) < 2: print("usage: check.py ") return 1 root = sys.argv[1] if not os.path.isdir(root): print(f"FAIL: not a directory: {root}") return 1 files = list(lean_files(root)) if not files: print("FAIL: no .lean files found") return 1 src = "\n".join(open(f, encoding="utf-8", errors="replace").read() for f in files) missing = [n for n in REQUIRED if n not in src] if missing: print("FAIL: missing theorem names: " + ", ".join(missing)) return 1 hits = FORBIDDEN.findall(src) if hits: print(f"FAIL: {len(hits)} 'sorry'/'admit' occurrence(s)") return 1 if AXIOM.search(src): print("FAIL: 'axiom' declaration found") return 1 lakefile = any( os.path.exists(os.path.join(root, n)) for n in ("lakefile.toml", "lakefile.lean") ) if not lakefile: print("FAIL: no lakefile (treat as not a Lean project)") return 1 lake = shutil.which("lake") if lake is None: print("PASS (structural only): five theorems present, no sorry/axiom; " "lake not installed, so NOT compiled") return 0 r = subprocess.run([lake, "build"], cwd=root, capture_output=True, text=True) print(r.stdout[-4000:]) print(r.stderr[-4000:]) if r.returncode != 0: print("FAIL: lake build returned", r.returncode) return 1 print("PASS: five theorems present, no sorry/axiom, lake build ok") return 0 if __name__ == "__main__": sys.exit(main())