"""Check that every backtick path / script name referenced in a DOC markdown file exists, and the version token matches the change history. usage: python check_doc_refs.py """ import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] doc = ROOT / "DOC" / sys.argv[1] s = doc.read_text(encoding="utf-8") code = ROOT / "Code" / "교각모델링" missing = [] for ref in sorted(set(re.findall(r"`([^`]+)`", s))): if ref.endswith(".py"): if not (code / ref).exists(): missing.append(ref) elif "/" in ref and not any(ch in ref for ch in "*<>~") and re.search(r"\.(md|3dm|json)$|/$", ref): if not (ROOT / ref).exists(): missing.append(ref) scripts = sorted({r for r in re.findall(r"`([a-z_]+\.py)`", s)}) ver = re.search(r"_v(\d+\.\d+\.\d+)\.md$", doc.name).group(1) hist = [l for l in s.splitlines() if l.startswith("| v")][-1].split("|")[1].strip() print("scripts referenced", len(scripts), "missing refs", missing, "version", ver, "history", hist, "OK" if hist == "v" + ver else "MISMATCH")