(script: str, timeout: int = 30)
| 190 | |
| 191 | |
| 192 | def _python_probe(script: str, timeout: int = 30) -> dict[str, Any]: |
| 193 | try: |
| 194 | result = subprocess.run( |
| 195 | [sys.executable, "-c", script], |
| 196 | cwd=PROJECT_DIR, |
| 197 | capture_output=True, |
| 198 | text=True, |
| 199 | timeout=timeout, |
| 200 | ) |
| 201 | except (OSError, subprocess.TimeoutExpired) as exc: |
| 202 | return {"available": False, "error": str(exc)} |
| 203 | |
| 204 | if result.returncode != 0: |
| 205 | return {"available": False, "error": (result.stderr or result.stdout).strip()} |
| 206 | |
| 207 | output_lines = [line for line in result.stdout.splitlines() if line.strip()] |
| 208 | if not output_lines: |
| 209 | return {"available": False, "error": "Probe returned no output."} |
| 210 | |
| 211 | try: |
| 212 | return json.loads(output_lines[-1]) |
| 213 | except json.JSONDecodeError: |
| 214 | return {"available": False, "error": result.stdout.strip()} |
| 215 | |
| 216 | |
| 217 | def _torch_info() -> dict[str, Any]: |
no test coverage detected