SPB Git forge

spb/wp15_uqo

Public MIT
3commits 1branches 1releases
7.6 MBsize
maindefault branch
4 h agolast push
TeX 53.6% Python 46.2%
1.1 KB · 40 lines python
Raw Blame History
1"""Repo-relative path resolution. No absolute user paths in committed code."""23from __future__ import annotations45import os6from functools import lru_cache7from pathlib import Path89import yaml101112@lru_cache(maxsize=1)13def repo_root() -> Path:14    """Walk up from this file until a directory containing pyproject.toml."""15    p = Path(__file__).resolve()16    for parent in p.parents:17        if (parent / "pyproject.toml").exists():18            return parent19    raise RuntimeError("repo root not found (no pyproject.toml above package)")202122@lru_cache(maxsize=1)23def path_config() -> dict:24    with open(repo_root() / "config" / "paths.yaml") as f:25        return yaml.safe_load(f)262728def get(key: str) -> Path:29    """Resolve a named path from config/paths.yaml, honoring IFRAG_DATA_ROOT."""30    rel = path_config()[key]31    override = os.environ.get("IFRAG_DATA_ROOT")32    if override and (rel == "data" or rel.startswith("data/")):33        return Path(override) / rel[len("data"):].lstrip("/")34    return repo_root() / rel353637def base_config() -> dict:38    with open(repo_root() / "config" / "base.yaml") as f:39        return yaml.safe_load(f)40