"""Resolve paths relative to the backend package root (not process cwd).""" from __future__ import annotations from pathlib import Path _BACKEND_DIR = Path(__file__).resolve().parents[1] def backend_dir() -> Path: return _BACKEND_DIR def resolve_backend_relative_path(raw: str | None, default: Path | None = None) -> str: """Resolve env paths like ``data/foo`` or legacy ``backend/data/foo``.""" value = (raw or "").strip() if not value: if default is None: raise ValueError("path is required when no default is provided") return str(default.resolve()) path = Path(value) if path.is_absolute(): return str(path.resolve()) normalized = value.replace("\\", "/") if normalized.startswith("backend/"): return str((_BACKEND_DIR / normalized[len("backend/") :]).resolve()) return str((_BACKEND_DIR / value).resolve())