Spaces:
Runtime error
Runtime error
File size: 553 Bytes
029948d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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)
|