Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| def _looks_like_json(s: str) -> bool: | |
| s = (s or "").strip() | |
| return s.startswith("{") and s.endswith("}") | |
| def resolve_json_or_path(env_name: str, default_path: Path, out_path: Path) -> Path: | |
| raw = (os.environ.get(env_name) or "").strip() | |
| if not raw: | |
| return default_path | |
| if _looks_like_json(raw): | |
| out_path.parent.mkdir(parents=True, exist_ok=True) | |
| out_path.write_text(raw, encoding="utf-8") | |
| return out_path | |
| return Path(raw) | |