Official Codebase of 3DCodeVerse
Python
languages: the GL and threejs runtimes read plan.json through tool_common.plan_or_none — one plan-loading rule (shape → model) instead of two tolerant copies
gaoypeng6d91a559aa70
diff --git a/harness/codeverse3d/languages/_gl_common.py b/harness/codeverse3d/languages/_gl_common.pyindex bcdb1e0d..d51ac9a8 100644--- a/harness/codeverse3d/languages/_gl_common.py+++ b/harness/codeverse3d/languages/_gl_common.py@@ -33,6 +33,7 @@ from codeverse3d.spatial.gl_render import (write_contact_sheet,write_gif,)+from codeverse3d.spatial.tool_common import plan_or_nonefrom codeverse3d.workspace import WorkspaceJUDGE_TIMES: tuple[float, ...] = (0.0, 1.0, 2.5, 4.0, 6.0)@@ -70,13 +71,9 @@ def make_host(override: GlHost | None = None, timeout_s: float | None = None) ->def load_plan(ws: Workspace) -> GraphicsPlan | None:- p = ws.plan_path- if not p.is_file():- return None- try:- return GraphicsPlan.model_validate(json.loads(p.read_text()))- except Exception: # noqa: BLE001 — not a graphics plan (or invalid) → defaults- return None+ """The run's GraphicsPlan; ``None`` (→ defaults) without one."""+ plan = plan_or_none(ws.plan_path)+ return plan if isinstance(plan, GraphicsPlan) else Nonedef resolution_for(plan: GraphicsPlan | None, *, fallback: tuple[int, int] = DEFAULT_RESOLUTION) -> tuple[int, int]:diff --git a/harness/codeverse3d/languages/threejs/__init__.py b/harness/codeverse3d/languages/threejs/__init__.pyindex 5f59ca1e..2d6ffd0f 100644--- a/harness/codeverse3d/languages/threejs/__init__.py+++ b/harness/codeverse3d/languages/threejs/__init__.py@@ -24,8 +24,8 @@ from codeverse3d.languages._js_lint import (node_check_syntax as check_syntax, # module-level name: tests monkeypatch it)from codeverse3d.languages.base import RuntimeLayout-from codeverse3d.proc import read_json_or_nonefrom codeverse3d.spatial.node import NodeError, NodeResult, run_node, runtime_js_dir+from codeverse3d.spatial.tool_common import plan_or_nonefrom codeverse3d.workspace import Workspace# ===================================================================== templates@@ -197,16 +197,6 @@ def _exports(src: str) -> set[str]:return names-def _load_plan(ws: Workspace) -> StaticPlan | None:- data = read_json_or_none(ws.plan_path)- if data is None or "parts" not in data or "joints" in data:- return None- try:- return StaticPlan.model_validate(data)- except ValueError:- return None--def lint_workspace(ws: Workspace) -> GateReport:"""Run every static check and return the ``lint:threejs`` GateReport."""t0 = time.time()@@ -250,8 +240,8 @@ def lint_workspace(ws: Workspace) -> GateReport:findings.append(GateFinding(gate=GATE, severity=Severity.WARN, target=_rel(ws, p),message=f"{_rel(ws, p)} is not imported by any module (dead part file?)", fix_hint="import and add it in src/object.js or delete it"))- plan = _load_plan(ws)- if plan is not None:+ plan = plan_or_none(ws.plan_path)+ if type(plan) is StaticPlan: # an articulated plan's parts are not threejs part filesfor part in plan.parts:pf = ws.src / "parts" / f"{to_snake(part.name)}.js"if not pf.is_file():diff --git a/harness/codeverse3d/spatial/tool_common.py b/harness/codeverse3d/spatial/tool_common.pyindex c9faf61c..be4adae8 100644--- a/harness/codeverse3d/spatial/tool_common.py+++ b/harness/codeverse3d/spatial/tool_common.py@@ -109,6 +109,15 @@ def load_plan(path: Path) -> Plan:raise ToolUsageError(f"plan.json is not a valid {model.__name__}: {e}") from e+def plan_or_none(path: Path) -> Plan | None:+ """:func:`load_plan` for a caller with defaults: ``None`` when plan.json is absent,+ unreadable or not a valid plan (the runtimes: resolution, skeleton hints)."""+ try:+ return load_plan(path)+ except (ToolUsageError, OSError, ValueError, TypeError):+ return None++# --------------------------------------------------------------------------- viewsdef resolve_views(names: Sequence[str]) -> list[ViewPreset]:"""Map view names → presets; unknown names are a usage error listing the options."""