Decoder2704/python-chatbot-jay
0
1#!/usr/bin/env python32"""3Run the data/artifact build pipeline in order (subprocess, sequential).4 5Steps:6 1. build_answers_v2.py7 2. build_final_dataset.py8 3. build_retrieval_artifacts.py9"""10 11from __future__ import annotations12 13import subprocess14import sys15from pathlib import Path16 17_BACKEND_DIR = Path(__file__).resolve().parent.parent18if str(_BACKEND_DIR) not in sys.path:19 sys.path.insert(0, str(_BACKEND_DIR))20 21from app.paths import ARTIFACTS_DIR, DATA_DIR, SCRIPTS_DIR22 23_STEPS: list[tuple[str, Path]] = [24 ("build_answers_v2.py", SCRIPTS_DIR / "build_answers_v2.py"),25 ("build_final_dataset.py", SCRIPTS_DIR / "build_final_dataset.py"),26 ("build_retrieval_artifacts.py", SCRIPTS_DIR / "build_retrieval_artifacts.py"),27]28 29 30def _list_files(root: Path, label: str) -> None:31 print(f"\n--- Files under {label} ({root}) ---")32 if not root.exists():33 print(" (directory does not exist)")34 return35 if not root.is_dir():36 print(" (not a directory)")37 return38 files = sorted(p for p in root.rglob("*") if p.is_file())39 if not files:40 print(" (no files)")41 return42 for f in files:43 print(f" {f}")44 45 46def main() -> int:47 print(f"Backend directory: {_BACKEND_DIR}")48 print("Running build steps sequentially (subprocess)...\n")49 50 for i, (name, script_path) in enumerate(_STEPS, start=1):51 if not script_path.is_file():52 print(f"[{i}/3] FAIL: script not found: {script_path}", file=sys.stderr)53 return 154 55 print(f"[{i}/3] Running {name} ...")56 print(f" command: {sys.executable} {script_path}")57 result = subprocess.run(58 [sys.executable, str(script_path)],59 cwd=str(_BACKEND_DIR),60 )61 if result.returncode != 0:62 print(63 f"[{i}/3] FAIL: {name} exited with code {result.returncode}",64 file=sys.stderr,65 )66 return result.returncode67 68 print(f"[{i}/3] OK: {name}\n")69 70 print("All build steps completed successfully.\n")71 _list_files(DATA_DIR, "backend/data/")72 _list_files(ARTIFACTS_DIR, "backend/artifacts/")73 return 074 75 76if __name__ == "__main__":77 raise SystemExit(main())78 