thermograph/backend/paths.py
Emi Griffith a4be7066e5 Subtree-merge thermograph-backend (origin/main) into backend/
git-subtree-dir: backend
git-subtree-mainline: 6723fc0326
git-subtree-split: 83c2e05b96
2026-07-22 22:01:11 -07:00

29 lines
1.6 KiB
Python

"""Canonical filesystem locations, resolved once from the repo root.
Every path the backend needs (the climate cache, the accounts DB, logs, the
bundled city data) is derived here from the repository root rather than from
each module's own ``__file__``. That keeps the locations stable no matter how
deep in the package tree a module lives, so moving a module never silently
re-points the cache or the accounts DB.
Callers that support an environment override (e.g. ``THERMOGRAPH_ACCOUNTS_DB``)
keep doing so; these are only the defaults.
"""
import os
REPO_DIR = os.path.dirname(os.path.abspath(__file__))
# Runtime state dirs default under the repo root, but MUST be overridable: after
# the repo split the code lives at the image root (/app), so the Python package
# `data/` and the runtime data dir `<root>/data` collide at the same path. When
# a persistent volume is mounted at that path (as the deploy compose does for
# the parquet cache / notifier.lock / geonames) it shadows and erases the
# `data/*.py` modules, so `import data.climate` fails at boot. Point
# THERMOGRAPH_DATA_DIR (and _LOGS_DIR) at a path OUTSIDE the code tree in the
# container to keep the volume clear of the package.
DATA_DIR = os.environ.get("THERMOGRAPH_DATA_DIR") or os.path.join(REPO_DIR, "data")
LOGS_DIR = os.environ.get("THERMOGRAPH_LOGS_DIR") or os.path.join(REPO_DIR, "logs")
# Bundled reference data shipped alongside the code (generated by gen_cities /
# gen_flavor), not runtime state — hence at the repo root, not data/.
CITIES_JSON = os.path.join(REPO_DIR, "cities.json")
CITIES_FLAVOR_JSON = os.path.join(REPO_DIR, "cities_flavor.json")