provinans / src /endopath /paths.py
reversely's picture
Upload folder using huggingface_hub
4b059c7 verified
Raw History Blame Contribute Delete
2.41 kB
"""Where the app reads its data, in one place and overridable per deployment.
Sixteen modules under `src/endopath/` and `scripts/` each computed the checkout root, and fifteen
rooted data at a bare `Path("data")` that resolves against the working directory rather than the
checkout, so the same call read a different file depending on where the process started. Nothing but
the embeddings directory could be pointed elsewhere, so a second registry could not be loaded and a
deployment could not separate its data from its code.
Every root here reads an environment variable first and falls back to the checkout, so a deployment
points the app at its own data without editing source, and a test points it at a fixture directory.
Standard library only, so this module sits below every other one in the import graph. Importing it
through the package still pulls pydantic, because `endopath/__init__.py` imports `schema`. A script
that builds its own environment from a PEP 723 dependency list therefore declares pydantic, as
`scripts/scrape_barcodes.py` does.
"""
from __future__ import annotations
import os
from pathlib import Path
#: The checkout. Every default below hangs off it, and no module should recompute it.
REPO_ROOT = Path(__file__).resolve().parents[2]
def _rooted(env_var: str, *default: str) -> Path:
"""The directory `env_var` names, or the checkout-relative default. A relative override resolves
against the working directory, so a deployment may pass either shape."""
override = os.environ.get(env_var, "").strip()
return Path(override).expanduser().resolve() if override else REPO_ROOT.joinpath(*default)
#: The corpus and the registry. `ENDOPATH_DATA_DIR` moves both at once.
DATA_DIR = _rooted("ENDOPATH_DATA_DIR", "data")
#: The taxonomy registry the engine loads. Pointing this at another directory loads another registry,
#: which is what a second domain pack needs (#131).
TAXONOMY_DIR = _rooted("ENDOPATH_TAXONOMY_DIR", "data", "taxonomy")
DOCS_DIR = _rooted("ENDOPATH_DOCS_DIR", "docs")
RAW_DIR = DATA_DIR / "raw"
IMAGE_DIR = DATA_DIR / "images"
INTERIM_DIR = DATA_DIR / "interim"
EMBEDDINGS_DIR = _rooted("ENDOPATH_EMBEDDINGS_DIR", "data", "embeddings")
METADATA_DIR = DATA_DIR / "tcga_metadata"
DEMO_CORPUS_DIR = DATA_DIR / "demo_corpus"
REPORTS_CSV_PATH = RAW_DIR / "TCGA_Reports.csv"
PDF_DIR = RAW_DIR / "pdfs"
TAXONOMY_DOC_PATH = DOCS_DIR / "taxonomy.md"