"""Data path resolution for the capstone project.""" from __future__ import annotations import os from pathlib import Path def get_data_root(explicit: str | Path | None = None) -> Path: """Return the MedMNIST data root, creating it if it does not exist.""" if explicit is not None: root = Path(explicit) elif env_root := os.environ.get("CAPSTONE_DATA_ROOT"): root = Path(env_root) else: root = _find_repo_root() / "data" / "medmnist" root.mkdir(parents=True, exist_ok=True) return root def _find_repo_root() -> Path: current = Path(__file__).resolve().parent for directory in (current, *current.parents): if (directory / "pyproject.toml").is_file(): return directory msg = "Could not find repository root (no pyproject.toml found)" raise RuntimeError(msg)