Spaces:
Running
Running
File size: 6,765 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | """hub λμ νμ β ν κ³³ (κ³ν 2026-09-27 L6 Β§2.3 Β· D-L6-1 Β· D-L6-10 Β· C-L6-8 Β· C-L6-9).
`resolve_target(cfg, project)` μ `Target` μ΄λ `Skip(code)` λ₯Ό λλ €μ€λ€. 쑰건(μμλλ‘):
1. `cfg.repo_root` μμ β `is_repo_managed` λ κ±°μ§μ΄λ©΄ `standalone`(μ‘°μ©ν), μ°Έμ΄λ©΄ `no_repo_root`.
2. `is_repo_managed(project)` κ±°μ§ β `not_repo_managed`(λ²μΒ·μμ½ λ±).
3. `project_contexts(cfg.projects_dir, cfg.repo_root, only=[project])` κ° case λ₯Ό λͺ» μ€λ€ β `case_unmapped`.
4. resolve ν `cfg.projects_dir` β resolve ν `data_home()/solar-eval-projects` β `data_home_mismatch`(κ²ν F4 β
`cfg.projects_dir` λ resolve λμ§ μμ κ²½λ‘λ€. μ¬λ³Όλ¦ λ§ν¬ νμ μμͺ½μ νμ΄ κ°λ€).
5. ν
μ΄ **μ§μ ** μ°λ 루νΈ(`hub_reports_dir()` β μ κΈΒ·μν νμΌΒ·μμΈ ν€)κ° λ ν¬(λ§ν¬λ μν¬νΈλ¦¬λ©΄ λ©μΈ μμ
νΈλ¦¬λ) μ β
`data_home_inside_repo`(κ²ν F10 β PB λ―Έλ¬Β·μ¬μ΄λμΉ΄ μ°κΈ°λ PB κ° λ§μ§λ§ μ΄ μ
μ PB κ²μ¬λ₯Ό κ±°μΉμ§ μλλ€).
`poc_bundle` μ ν¨μ μμμλ§ import νλ€(D-L6-14 β `solar-eval --help` κ° λ°±νΒ·λ―Έλ¬λ₯Ό λ‘λ©νμ§ μκ²).
"""
from __future__ import annotations
from collections.abc import Mapping
from pathlib import Path
from typing import TYPE_CHECKING, Any
from solar_eval.hub_hook.types import (
PROJECTS_DIRNAME,
SKIP_CASE_UNMAPPED,
SKIP_DATA_HOME_INSIDE_REPO,
SKIP_DATA_HOME_MISMATCH,
SKIP_NO_REPO_ROOT,
SKIP_NOT_REPO_MANAGED,
SKIP_STANDALONE,
Skip,
Target,
)
if TYPE_CHECKING:
from solar_eval.cli.config import CLIConfig
#: pnpm μν¬μ€νμ΄μ€ νμ β `workspace_root` κ° μ½λ 체ν¬μμ 루νΈλ₯Ό μ°Ύλλ€(C-L6-9).
WORKSPACE_MARKER = "pnpm-workspace.yaml"
#: ν
μ°κΈ° μμΉκ° λ ν¬ μμΈμ§ λ³Ό λ `require_outside_repo` μ μ£Όλ μ΄λ¦ν.
HOOK_WRITE_LABEL = "hook state"
def resolve_target(
cfg: CLIConfig, project: str, env: Mapping[str, str] | None = None
) -> Target | Skip:
"""hub λμ case μΈκ°(Β§2.3). λ κ±°μ μ μ¬λ μ΄λ κ²°κ³Όμμλ λΆλ₯΄μ§ μλλ€(D-M2-4 (b))."""
repo_root = cfg.repo_root
if repo_root is None:
return Skip(SKIP_NO_REPO_ROOT if cfg.is_repo_managed(project) else SKIP_STANDALONE)
if not cfg.is_repo_managed(project):
return Skip(SKIP_NOT_REPO_MANAGED)
context = _project_context(cfg.projects_dir, repo_root, project)
if context is None or context.case_ref is None:
return Skip(SKIP_CASE_UNMAPPED)
mismatch = _data_home_mismatch(cfg.projects_dir, env)
if mismatch is not None:
return mismatch
inside = _hook_root_inside_repo(repo_root, env)
if inside is not None:
return inside
return Target(
project=project,
account=context.account,
case=context.case,
context=context,
repo_root=Path(repo_root),
projects_dir=Path(cfg.projects_dir),
# μ€μ νμΌ `hub:` μ β opt-in ν΄μμ `hook.gated_hub_leg` β `optin.resolve_hub_optin`(L10 Β§2.6).
hub_config=getattr(cfg, "hub", None),
)
def _project_context(projects_dir: Path, repo_root: Path, project: str) -> Any | None:
from poc_bundle.census.scan import project_contexts
contexts = project_contexts(Path(projects_dir), Path(repo_root), only=[project])
return contexts[0] if contexts else None
def _data_home_mismatch(projects_dir: Path, env: Mapping[str, str] | None) -> Skip | None:
from poc_bundle.home import data_home
actual = Path(projects_dir).expanduser().resolve()
expected = (data_home(env) / PROJECTS_DIRNAME).resolve()
if actual == expected:
return None
return Skip(SKIP_DATA_HOME_MISMATCH, {"projects_dir": str(actual), "expected": str(expected)})
def _hook_root_inside_repo(repo_root: Path, env: Mapping[str, str] | None) -> Skip | None:
from poc_bundle.home import HomeError, hub_reports_dir, require_outside_repo
from poc_bundle.mirror import linked_main_work_tree
root = hub_reports_dir(env)
main = linked_main_work_tree(Path(repo_root))
for tree in (Path(repo_root),) if main is None else (Path(repo_root), main):
try:
require_outside_repo(root, tree, HOOK_WRITE_LABEL)
except HomeError:
return Skip(SKIP_DATA_HOME_INSIDE_REPO, {"hub_reports_dir": str(root)})
return None
def case_ref_hint(cfg: CLIConfig, project: str) -> str | None:
"""`--no-ingest` μλ΄μ© case μ΄λ¦ β `poc_bundle` μμ΄ config λλ ν 리 λͺ¨μ(`accounts/<a>/<c>/03-evaluation`)μμ.
νμ μ΄ μλλΌ λ¬Έκ΅¬μ©μ΄λ€. λ ν¬λ₯Ό λͺ¨λ₯΄λ©΄ None.
"""
if cfg.repo_root is None:
return None
config_dir = cfg.config_dirs.get(project)
if config_dir is None:
return None
case_dir = Path(config_dir).parent
return f"{case_dir.parent.name}/{case_dir.name}"
def workspace_root() -> Path | None:
"""pnpm μ λ릴 **μ½λ 체ν¬μμ** λ£¨νΈ β `solar_eval` ν¨ν€μ§ νμΌμμ μλ‘ `pnpm-workspace.yaml`(C-L6-9).
hub μ `--repo` λ config λ£¨νΈ `cfg.repo_root` λ€ β ν©μ± λ ν¬(`SOLAR_EVAL_CONFIG_ROOT`)λ pnpm μν¬μ€νμ΄μ€κ° μλλ€.
"""
import solar_eval
for parent in Path(solar_eval.__file__).resolve().parents:
if (parent / WORKSPACE_MARKER).is_file():
return parent
return None
def is_smoke_run(source: Any) -> bool:
"""`--limit` μ€λͺ¨ν¬ run μΈκ°(D-L6-10).
`source` λ `RunPlan`(`.selection.limit` β `runs start`)μ΄λ run.json λ§€ν(`dataset.selection.limit` β `runs resume`).
μμ μ μ limit λ§ μ€λͺ¨ν¬λ€(λΆλ¦¬μΈΒ·μμΒ·λ¬Έμμ΄μ μλλ€).
"""
if isinstance(source, Mapping):
dataset = source.get("dataset")
selection = dataset.get("selection") if isinstance(dataset, Mapping) else None
limit = selection.get("limit") if isinstance(selection, Mapping) else None
else:
selection = getattr(source, "selection", None)
limit = getattr(selection, "limit", None)
return isinstance(limit, int) and not isinstance(limit, bool) and limit > 0
def snapshot_evaluator_type(run_json: Mapping[str, Any]) -> str | None:
"""run.json μ€λ
μ· `config.evaluator_config.config.type` β λͺ¨μμ΄ νλλΌλ λ€λ₯΄λ©΄ None(D-L6-8).
`poc_bundle.legacy_run._snapshot_evaluator_type` κ³Ό κ°μ κ²½λ‘λ€(λΉκ³΅κ° ν¨μλΌ import νμ§ μκ³ κ°μ κ·μΉμ λλ€).
"""
node: Any = run_json.get("snapshot")
for key in ("config", "evaluator_config", "config", "type"):
if not isinstance(node, Mapping):
return None
node = node.get(key)
return node if isinstance(node, str) and node else None
|