File size: 917 Bytes
99589b3
 
8e87280
99589b3
8e87280
 
99589b3
8e87280
 
 
 
 
 
 
 
 
 
99589b3
8e87280
 
 
 
 
 
 
99589b3
 
8e87280
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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"]