"""Backend Loader — discovers and validates all Python backend modules.""" import importlib import os import sys # Ensure project root is importable. _PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) if _PROJECT_ROOT not in sys.path: sys.path.insert(0, _PROJECT_ROOT) # Registry of expected backend modules: (dotted_path, class_name) BACKEND_MODULES = [ ("TIA.worker", "TIAWorker"), ("citadel.primeSchema", "PrimeSchema"), ("citadel.holo3d.ui.commandCentre", "CommandCentre"), ("citadel.lineage", "Lineage"), ("citadel.peace_vortex", "PeaceVortex"), ("citadel.alpha_nex", "AlphaNex"), ("harvester.washed_harvest", "WashedHarvest"), ("bio.vessel_firewall", "VesselFirewall"), ] def load_all(): """Import every registered backend module and return a status dict. Returns: dict mapping ``"module.Class"`` to either the class object or an error string. """ results = {} for mod_path, cls_name in BACKEND_MODULES: key = f"{mod_path}.{cls_name}" try: mod = importlib.import_module(mod_path) cls = getattr(mod, cls_name) results[key] = {"status": "loaded", "class": cls} except Exception as exc: results[key] = {"status": "error", "error": str(exc)} return results def print_report(): """Print a human-readable status report for all backend modules.""" results = load_all() print("\n=== TIA Backend Loader Report ===\n") for key, info in results.items(): mark = "\u2705" if info["status"] == "loaded" else "\u274c" detail = "" if info["status"] == "loaded" else f' ({info["error"]})' print(f" {mark} {key}{detail}") loaded = sum(1 for v in results.values() if v["status"] == "loaded") total = len(results) print(f"\n {loaded}/{total} modules loaded successfully.\n") return results if __name__ == "__main__": print_report()