Spaces:
Sleeping
Sleeping
File size: 2,547 Bytes
78d2329 | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import os
import sys
from pathlib import Path
from optgs.misc.io import CustomPath
_PKG_DIR = CustomPath(__file__).resolve().parent # .../optgs (the package)
_REPO_ROOT = _PKG_DIR.parent # repo root (source) OR site-packages (installed)
# Source checkout iff a project marker sits next to the package dir.
_IS_SOURCE_CHECKOUT = (_REPO_ROOT / "pyproject.toml").exists() or (_REPO_ROOT / ".git").exists()
# Working root for run outputs (checkpoints/results/figures) and datasets.
# source checkout : the repo root (preserves existing behaviour)
# installed : $OPTGS_HOME if set, else the current working directory
if _IS_SOURCE_CHECKOUT:
PROJECT_DIR = CustomPath(str(_REPO_ROOT))
else:
PROJECT_DIR = CustomPath(str(os.environ.get("OPTGS_HOME", Path.cwd())))
SRC_DIR = CustomPath(str(_PKG_DIR)) # importable package dir (always correct)
CKPT_DIR = PROJECT_DIR / "checkpoints"
RESULTS_DIR = PROJECT_DIR / "results"
FIGURES_DIR = PROJECT_DIR / "figures"
DATA_DIR = PROJECT_DIR / "datasets"
DL3DV_480P_DIR = DATA_DIR / "dl3dv-480p-chunks"
DL3DV_COLMAP_SfM_DIR = DATA_DIR / "dl3dv-colmap-sfm"
# Eval-index / font assets are NOT bundled in the wheel (they are data, like
# datasets). Resolution order: $OPTGS_ASSETS, else <repo>/assets in a source
# checkout. See README / DATASETS.md.
ASSETS_DIR = (
CustomPath(str(os.environ["OPTGS_ASSETS"]))
if os.environ.get("OPTGS_ASSETS")
else (PROJECT_DIR / "assets")
)
def asset_path(rel) -> CustomPath:
"""Resolve an asset file (eval-index JSON, font, ...).
Absolute or already-existing paths pass through unchanged. A leading
``assets/`` is stripped so callers may pass either ``assets/x.json`` or
``x.json``. The base dir is ``$OPTGS_ASSETS`` (recommended for installed
use), else ``<repo>/assets`` in a source checkout.
"""
p = Path(str(rel))
if p.is_absolute() or p.exists():
return CustomPath(str(p))
s = str(rel)
if s.startswith("assets/"):
s = s[len("assets/"):]
return CustomPath(str(ASSETS_DIR)) / s
# Auto-create the figures dir only in a source checkout (preserves dev
# behaviour). When installed, importing the library must not create
# directories in the user's CWD — callers create output dirs lazily.
if _IS_SOURCE_CHECKOUT:
try:
FIGURES_DIR.mkdir(parents=True, exist_ok=True)
except OSError:
pass
if sys.gettrace() is not None:
print("Running in debug mode")
DEBUG = True
else:
DEBUG = False
|