Buckets:
| """Canonical naming for task output directories.""" | |
| from __future__ import annotations | |
| import os | |
| import re | |
| from datetime import datetime, timezone, timedelta | |
| from pathlib import Path | |
| # The project runs in Shanghai (UTC+8) but project owners consume outputs | |
| # in UTC-7. We default to UTC-7 so the sortable prefix matches the wall | |
| # clock the human sees. Override by exporting ``SPATIAL_MMCOT_TZ_OFFSET=-7``, | |
| # ``-8``, etc. before calling. | |
| DEFAULT_TZ_OFFSET = int(os.environ.get("SPATIAL_MMCOT_TZ_OFFSET", "-7")) | |
| _TIMESTAMPED_NAME = re.compile(r"^\d{8}-\d{6}_.+") | |
| def project_root() -> Path: | |
| """Return the live artifact/data root, distinct from a source snapshot.""" | |
| return Path( | |
| os.environ.get( | |
| "SPATIAL_MMCOT_PROJECT_ROOT", Path(__file__).resolve().parents[2] | |
| ) | |
| ).resolve() | |
| def _now_in_tz(offset_hours: int = DEFAULT_TZ_OFFSET) -> datetime: | |
| """Current wall clock viewed from ``offset_hours`` east of UTC.""" | |
| return datetime.now(timezone(timedelta(hours=offset_hours))) | |
| def timestamped_run_name(name: str, *, now: datetime | None = None) -> str: | |
| """Prefix a run name with a sortable UTC-7 timestamp. | |
| Set ``SPATIAL_MMCOT_TZ_OFFSET`` to override the default (-7). | |
| """ | |
| if not name or Path(name).name != name or name in {".", ".."}: | |
| raise ValueError("run name must be one non-empty path component") | |
| if _TIMESTAMPED_NAME.fullmatch(name): | |
| return name | |
| stamp_src = now if now is not None else _now_in_tz() | |
| timestamp = stamp_src.strftime("%Y%m%d-%H%M%S") | |
| return f"{timestamp}_{name}" | |
| def is_timestamped_run_name(name: str) -> bool: | |
| """Return whether *name* follows the canonical task-run convention.""" | |
| return bool(_TIMESTAMPED_NAME.fullmatch(name)) | |
Xet Storage Details
- Size:
- 1.76 kB
- Xet hash:
- 3a8828780d2e1a7fee5288b33410b89c5781680e71449a667f0b40cd9b80caa0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.