Spaces:
Running
Running
File size: 2,817 Bytes
3dfc93b | 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 | """์ฌ์ฑ์ ๋ฒ๋ค์ด ๋์ผ ๊ณณ (๊ณํ 2026-09-26 L3b ยง2.1 "๋ฏธ๋ฌ ๋ฃจํธ ์ธต").
- ๋ฏธ๋ฌ ์์ญ = `<mirror_root>/<bucket>/accounts/<a>/<c>/eval/<area>` โ `mirror_root` ๋ **๋ฒํท์ ๋ถ๋ชจ**(`poc_bundle.mirror.mirror_bundle(root=)`
์ ๊ฐ์ ๋ป, ๊ธฐ๋ณธ `blob_mirror_root()`). ๊ฒฝ๋ก ์กฐ๊ฐ์ `poc_bundle.data.layout` ์ ๊ท์น์ผ๋ก๋ง ๋ง๋ ๋ค(์ฌ๋ฌ๊ทธ ๊ฒ์ฌ ํฌํจ).
- `<run_bundle_dir>` ๋ชจ๋ ๊ธฐ๋ณธ ์ถ๋ ฅ: ๋ฒ๋ค์ด `โฆ/eval/bundles/<id>` ์ ์์ผ๋ฉด `โฆ/eval/evaluations`(eval-wrap ๊ณผ ๊ฐ์ ๊ท์น),
์๋๋ฉด ํธ์ถ์๊ฐ `--out` ์ ์ค์ผ ํ๋ค.
"""
from __future__ import annotations
from pathlib import Path
from poc_bundle.data.errors import DataConfigError
from poc_bundle.data.layout import SUBPREFIX, case_prefix
from poc_bundle.home import blob_mirror_root
from poc_bundle.mirror import DEFAULT_BUCKET
BUNDLES_AREA = "bundles"
EVALUATIONS_AREA = "evaluations"
class RescorePathError(ValueError):
"""์ฌ์ฑ์ ์
๋ ฅยท์ถ๋ ฅ ์์น๋ฅผ ์ ํ ์ ์๋ค(์๋ชป๋ case ์ฌ๋ฌ๊ทธยท๊ธฐ๋ณธ ์ถ๋ ฅ ์์น ์์)."""
def parse_case_key(case_key: str) -> tuple[str, str]:
"""`a/c` โ (account, case). ์ฌ๋ฌ๊ทธ ๊ท์น์ `case_prefix` ๊ฐ ๋ณธ๋ค."""
parts = case_key.split("/") if isinstance(case_key, str) else []
if len(parts) != 2:
raise RescorePathError(f"case must be <account>/<case>, got {case_key!r}")
account, case = parts
try:
case_prefix(account, case)
except DataConfigError as exc:
raise RescorePathError(str(exc)) from exc
return account, case
def mirror_area_dir(
mirror_root: Path | None, account: str, case: str, area: str, *, bucket: str = DEFAULT_BUCKET
) -> Path:
"""๋ฏธ๋ฌ์ ํ case ์์ญ ๋๋ ํ ๋ฆฌ(`bundles` ๋๋ `evaluations`)."""
if area not in (BUNDLES_AREA, EVALUATIONS_AREA):
raise RescorePathError(f"unknown mirror area {area!r}")
try:
prefix = case_prefix(account, case)
except DataConfigError as exc:
raise RescorePathError(str(exc)) from exc
return resolve_mirror_root(mirror_root) / bucket / prefix / SUBPREFIX[area]
def resolve_mirror_root(mirror_root: Path | None) -> Path:
"""๋ฏธ๋ฌ ๋ฒํท์ ๋ถ๋ชจ ์ ๋ ๊ฒฝ๋ก โ None ์ด๋ฉด ๋ฐ์ดํฐ ํ์ `blob-mirror`."""
return blob_mirror_root() if mirror_root is None else Path(mirror_root).expanduser().resolve()
def default_evaluations_dir(run_bundle_dir: Path) -> Path | None:
"""`โฆ/eval/bundles/<id>` โ `โฆ/eval/evaluations`. ๊ทธ ๋ชจ์์ด ์๋๋ฉด None(ํธ์ถ์๊ฐ `--out` ์ ์๊ตฌํ๋ค)."""
resolved = Path(run_bundle_dir).resolve()
parent = resolved.parent
if parent.name == Path(SUBPREFIX[BUNDLES_AREA]).name and parent.parent.name == "eval":
return parent.parent / Path(SUBPREFIX[EVALUATIONS_AREA]).name
return None
|