| @@ -0,0 +1,91 @@ |
| 1 | + |
| 2 | +"""Shoal check for continuityunification. |
| 3 | + |
| 4 | +判据(三条,缺一不算通过): |
| 5 | +1. 提交里有 Lean 工程(lakefile + lean-toolchain),五个定理名在源码里出现; |
| 6 | +2. 源码里没有 `sorry` / `axiom`; |
| 7 | +3. 能 `lake build` 通过(本机没有 lake 时只做前两项,并在输出里写明"未编译")。 |
| 8 | + |
| 9 | +用法:python3 checks/check.py <提交目录> |
| 10 | +退出码:0 = 通过,1 = 不通过。 |
| 11 | +""" |
| 12 | +import os |
| 13 | +import re |
| 14 | +import shutil |
| 15 | +import subprocess |
| 16 | +import sys |
| 17 | + |
| 18 | +REQUIRED = [ |
| 19 | + "dead_matter", |
| 20 | + "chemistry", |
| 21 | + "star", |
| 22 | + "biology", |
| 23 | + "mathematics", |
| 24 | +] |
| 25 | + |
| 26 | +FORBIDDEN = re.compile(r"\b(sorry|admit)\b") |
| 27 | +AXIOM = re.compile(r"^\s*axiom\b", re.M) |
| 28 | + |
| 29 | + |
| 30 | +def lean_files(root): |
| 31 | + for dirpath, _, names in os.walk(root): |
| 32 | + for n in names: |
| 33 | + if n.endswith(".lean"): |
| 34 | + yield os.path.join(dirpath, n) |
| 35 | + |
| 36 | + |
| 37 | +def main() -> int: |
| 38 | + if len(sys.argv) < 2: |
| 39 | + print("usage: check.py <submission-dir>") |
| 40 | + return 1 |
| 41 | + root = sys.argv[1] |
| 42 | + if not os.path.isdir(root): |
| 43 | + print(f"FAIL: not a directory: {root}") |
| 44 | + return 1 |
| 45 | + |
| 46 | + files = list(lean_files(root)) |
| 47 | + if not files: |
| 48 | + print("FAIL: no .lean files found") |
| 49 | + return 1 |
| 50 | + |
| 51 | + src = "\n".join(open(f, encoding="utf-8", errors="replace").read() for f in files) |
| 52 | + |
| 53 | + missing = [n for n in REQUIRED if n not in src] |
| 54 | + if missing: |
| 55 | + print("FAIL: missing theorem names: " + ", ".join(missing)) |
| 56 | + return 1 |
| 57 | + |
| 58 | + hits = FORBIDDEN.findall(src) |
| 59 | + if hits: |
| 60 | + print(f"FAIL: {len(hits)} 'sorry'/'admit' occurrence(s)") |
| 61 | + return 1 |
| 62 | + |
| 63 | + if AXIOM.search(src): |
| 64 | + print("FAIL: 'axiom' declaration found") |
| 65 | + return 1 |
| 66 | + |
| 67 | + lakefile = any( |
| 68 | + os.path.exists(os.path.join(root, n)) for n in ("lakefile.toml", "lakefile.lean") |
| 69 | + ) |
| 70 | + if not lakefile: |
| 71 | + print("FAIL: no lakefile (treat as not a Lean project)") |
| 72 | + return 1 |
| 73 | + |
| 74 | + lake = shutil.which("lake") |
| 75 | + if lake is None: |
| 76 | + print("PASS (structural only): five theorems present, no sorry/axiom; " |
| 77 | + "lake not installed, so NOT compiled") |
| 78 | + return 0 |
| 79 | + |
| 80 | + r = subprocess.run([lake, "build"], cwd=root, capture_output=True, text=True) |
| 81 | + print(r.stdout[-4000:]) |
| 82 | + print(r.stderr[-4000:]) |
| 83 | + if r.returncode != 0: |
| 84 | + print("FAIL: lake build returned", r.returncode) |
| 85 | + return 1 |
| 86 | + print("PASS: five theorems present, no sorry/axiom, lake build ok") |
| 87 | + return 0 |
| 88 | + |
| 89 | + |
| 90 | +if __name__ == "__main__": |
| 91 | + sys.exit(main()) |