Spaces:
Sleeping
Sleeping
| # app/paths.py | |
| import os | |
| from pathlib import Path | |
| # Repo root (parent of /app) | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def _dir_from_env(key: str, default: Path) -> Path: | |
| raw = os.getenv(key, "") | |
| if not raw: | |
| p = default | |
| else: | |
| p = Path(raw.strip()).expanduser() | |
| # If env var is relative (e.g., "data/index"), anchor it to ROOT | |
| if not p.is_absolute(): | |
| p = ROOT / p | |
| return p.resolve() | |
| # Canonical data paths | |
| DATA_DIR = _dir_from_env("DATA_DIR", ROOT / "data") | |
| DOCSTORE_DIR = _dir_from_env("DOCSTORE_DIR", DATA_DIR / "docstore") | |
| INDEX_DIR = _dir_from_env("INDEX_DIR", DATA_DIR / "index") | |
| EXPORT_DIR = _dir_from_env("EXPORT_DIR", DATA_DIR / "exports") | |
| # Ensure they exist | |
| for p in (DATA_DIR, DOCSTORE_DIR, INDEX_DIR, EXPORT_DIR): | |
| p.mkdir(parents=True, exist_ok=True) | |
| __all__ = ["ROOT", "DATA_DIR", "DOCSTORE_DIR", "INDEX_DIR", "EXPORT_DIR"] | |