ensure submodule dirs are present and non-empty

This commit is contained in:
sam-paech
2025-10-17 03:49:09 +11:00
parent 9410c4c675
commit 8b4b270806

22
main.py
View File

@@ -21,20 +21,32 @@ sys.path.insert(0, str(ROOT_DIR)) # so "utils" is on sys.path
# ── Hard fail early if required submodules are missing ───────────────────────── # ── Hard fail early if required submodules are missing ─────────────────────────
def _ensure_required_submodules(): def _ensure_required_submodules():
def _dir_nonempty(p: Path) -> bool:
try:
return p.is_dir() and any(p.iterdir())
except Exception:
return False
required = ("slop-forensics", "antislop-vllm") required = ("slop-forensics", "antislop-vllm")
missing = [name for name in required if not (ROOT_DIR / name).is_dir()] missing_or_empty = []
if missing: for name in required:
path = ROOT_DIR / name
if not _dir_nonempty(path):
missing_or_empty.append(name)
if missing_or_empty:
msg = ( msg = (
"Required git submodules are missing: " "Required git submodules are missing or empty: "
+ ", ".join(missing) + ", ".join(missing_or_empty)
+ "\n\nClone the repo with submodules:\n" + "\n\nClone the repo with submodules:\n"
" git clone --recurse-submodules <repo-url>\n\n" " git clone --recurse-submodules <repo-url>\n\n"
"If you already cloned without submodules, run:\n" "If you already cloned without submodules, fix an existing clone:\n"
" git submodule update --init --recursive\n" " git submodule update --init --recursive\n"
) )
print("WARNING: " + msg, file=sys.stderr) print("WARNING: " + msg, file=sys.stderr)
sys.exit(2) sys.exit(2)
_ensure_required_submodules() _ensure_required_submodules()
# ── guarantee NLTK data is present *before* any other project import ─────────── # ── guarantee NLTK data is present *before* any other project import ───────────