|
| 1 | +"""Runtime validation for TiGL/TiXI native dependencies.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import shutil |
| 6 | +import sys |
| 7 | + |
| 8 | + |
| 9 | +CONDA_INSTALL_CMD = ( |
| 10 | + "conda install -c dlr-sc -c conda-forge tigl3 tixi3 python-tigl3 python-tixi3" |
| 11 | +) |
| 12 | + |
| 13 | +DOCKER_BUILD_CMD = "docker build -t tigl-mcp:dev ." |
| 14 | + |
| 15 | +INSTALL_GUIDE = f"""\ |
| 16 | +TiGL/TiXI native bindings are not available in this Python environment. |
| 17 | +
|
| 18 | +To install, choose one of the following options: |
| 19 | +
|
| 20 | + 1. Conda (recommended): |
| 21 | + {CONDA_INSTALL_CMD} |
| 22 | +
|
| 23 | + 2. Conda environment file (ships with this repo): |
| 24 | + conda env create -f environment.yml |
| 25 | + conda activate tigl-mcp |
| 26 | +
|
| 27 | + 3. Docker (includes TiGL + Gmsh + SU2): |
| 28 | + {DOCKER_BUILD_CMD} |
| 29 | +
|
| 30 | + 4. Pre-built binaries from DLR: |
| 31 | + https://github.com/DLR-SC/tigl/releases |
| 32 | +
|
| 33 | +The server will still start in stub mode (synthetic geometry) without |
| 34 | +these bindings, but real STEP/STL export requires the native runtime. |
| 35 | +""" |
| 36 | + |
| 37 | + |
| 38 | +def check_tigl_runtime() -> dict[str, object]: |
| 39 | + """Probe the environment for TiGL and TiXI availability. |
| 40 | +
|
| 41 | + Returns a dict suitable for printing or returning as a tool response. |
| 42 | + """ |
| 43 | + results: dict[str, object] = { |
| 44 | + "python": sys.version, |
| 45 | + "platform": sys.platform, |
| 46 | + } |
| 47 | + |
| 48 | + # TiXI |
| 49 | + try: |
| 50 | + from tixi3 import tixi3wrapper # type: ignore[import-untyped] |
| 51 | + |
| 52 | + tixi_h = tixi3wrapper.Tixi3() |
| 53 | + results["tixi3"] = {"available": True, "version": getattr(tixi_h, "version", "unknown")} |
| 54 | + except Exception as exc: |
| 55 | + results["tixi3"] = {"available": False, "error": str(exc)} |
| 56 | + |
| 57 | + # TiGL |
| 58 | + try: |
| 59 | + from tigl3 import tigl3wrapper # type: ignore[import-untyped] |
| 60 | + |
| 61 | + results["tigl3"] = {"available": True, "module": tigl3wrapper.__name__} |
| 62 | + except Exception as exc: |
| 63 | + results["tigl3"] = {"available": False, "error": str(exc)} |
| 64 | + |
| 65 | + # OpenCASCADE (used for watertight STEP export) |
| 66 | + try: |
| 67 | + from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid # type: ignore[import-untyped] # noqa: F401 |
| 68 | + |
| 69 | + results["opencascade"] = {"available": True} |
| 70 | + except Exception as exc: |
| 71 | + results["opencascade"] = {"available": False, "error": str(exc)} |
| 72 | + |
| 73 | + # Gmsh (used for meshing in the pipeline) |
| 74 | + gmsh_bin = shutil.which("gmsh") |
| 75 | + try: |
| 76 | + import gmsh as _gmsh # type: ignore[import-untyped] # noqa: F401 |
| 77 | + |
| 78 | + results["gmsh"] = { |
| 79 | + "available": True, |
| 80 | + "python_api": True, |
| 81 | + "cli": gmsh_bin or "not on PATH", |
| 82 | + } |
| 83 | + except Exception: |
| 84 | + results["gmsh"] = { |
| 85 | + "available": gmsh_bin is not None, |
| 86 | + "python_api": False, |
| 87 | + "cli": gmsh_bin or "not on PATH", |
| 88 | + } |
| 89 | + |
| 90 | + all_ok = all( |
| 91 | + isinstance(v, dict) and v.get("available", False) |
| 92 | + for v in results.values() |
| 93 | + if isinstance(v, dict) |
| 94 | + ) |
| 95 | + results["all_ok"] = all_ok |
| 96 | + |
| 97 | + return results |
| 98 | + |
| 99 | + |
| 100 | +def print_runtime_report() -> None: |
| 101 | + """Print a human-readable runtime diagnostics report.""" |
| 102 | + report = check_tigl_runtime() |
| 103 | + |
| 104 | + print("=" * 60) |
| 105 | + print(" TiGL MCP Runtime Check") |
| 106 | + print("=" * 60) |
| 107 | + print(f" Python: {report['python']}") |
| 108 | + print(f" Platform: {report['platform']}") |
| 109 | + print() |
| 110 | + |
| 111 | + for name in ("tixi3", "tigl3", "opencascade", "gmsh"): |
| 112 | + info = report.get(name, {}) |
| 113 | + if not isinstance(info, dict): |
| 114 | + continue |
| 115 | + ok = info.get("available", False) |
| 116 | + status = "OK" if ok else "MISSING" |
| 117 | + marker = "+" if ok else "x" |
| 118 | + line = f" [{marker}] {name:15s} {status}" |
| 119 | + if not ok and "error" in info: |
| 120 | + line += f" ({info['error'][:80]})" |
| 121 | + if ok and "version" in info: |
| 122 | + line += f" (v{info['version']})" |
| 123 | + if "cli" in info: |
| 124 | + line += f" [cli: {info['cli']}]" |
| 125 | + print(line) |
| 126 | + |
| 127 | + print() |
| 128 | + if report.get("all_ok"): |
| 129 | + print(" All dependencies found. Full TiGL geometry export is available.") |
| 130 | + else: |
| 131 | + print(" Some dependencies are missing. The server will run in stub mode.") |
| 132 | + print() |
| 133 | + print(INSTALL_GUIDE) |
| 134 | + |
| 135 | + print("=" * 60) |
0 commit comments