| 12345678910111213141516171819202122232425262728293031323334353637 |
- """Project path routing: relative paths are resolved from the repository root (this file's directory).
- 中文「路由」在此指:把 ``input/screenshot.png`` 等相对路径统一映射到仓库根下的绝对路径。
- Example::
- from routing import REPO_ROOT, route, INPUT_DIR, OUTPUT_DIR
- shot = route(\"input/screenshot.png\")
- same = INPUT_DIR / \"screenshot.png\"
- assert shot.resolve() == same.resolve()
- """
- from __future__ import annotations
- from pathlib import Path
- REPO_ROOT: Path = Path(__file__).resolve().parent
- INPUT_DIR: Path = REPO_ROOT / "input"
- OUTPUT_DIR: Path = REPO_ROOT / "output"
- def route(path: str | Path) -> Path:
- """Resolve ``path`` under ``REPO_ROOT`` when relative; absolute paths stay absolute."""
- p = Path(path)
- return p.resolve() if p.is_absolute() else (REPO_ROOT / p).resolve()
- repo_path = route
- __all__ = [
- "REPO_ROOT",
- "INPUT_DIR",
- "OUTPUT_DIR",
- "route",
- "repo_path",
- ]
|