Skip to content

Official Codebase of 3DCodeVerse

Python

imports: get_settings is imported once per module, at the top — twenty function-scope copies go

gaoypeng83ebf5dca585
diff --git a/harness/codeverse3d/addons/calibration.py b/harness/codeverse3d/addons/calibration.py
index 18003dfd..5ab08cfa 100644
--- a/harness/codeverse3d/addons/calibration.py
+++ b/harness/codeverse3d/addons/calibration.py
@@ -30,6 +30,7 @@ from pydantic import BaseModel, Field
from codeverse3d.addons import select
from codeverse3d.cli._judge import build_judge_input, make_judge, rubric_for
+from codeverse3d.config import get_settings
from codeverse3d.contracts.artifacts import Judgment, RenderSet
from codeverse3d.contracts.run import RoundRecord, RunRecord
from codeverse3d.contracts.spec import Spec
@@ -262,8 +263,6 @@ def calibrate(
``fixed_order`` sends every sample the same montage order, so ``mean_std`` becomes the
model's own re-judge σ instead of its order-permutation σ (see ``VlmJudge.fixed_order``).
"""
- from codeverse3d.config import get_settings
-
model_id = model_id or get_settings().default_judge
out = Path(out_dir) if out_dir else Path.cwd()
out.mkdir(parents=True, exist_ok=True)
diff --git a/harness/codeverse3d/addons/gallery/viewer.py b/harness/codeverse3d/addons/gallery/viewer.py
index 0f6de8bc..c524f9b4 100644
--- a/harness/codeverse3d/addons/gallery/viewer.py
+++ b/harness/codeverse3d/addons/gallery/viewer.py
@@ -14,6 +14,7 @@ from pathlib import Path
from codeverse3d.addons.gallery.model import RunEntry
from codeverse3d.addons.gallery.theme import esc, footer, page_shell, top_bar
from codeverse3d.addons.gallery.urls import PathError, UrlMaker, safe_join
+from codeverse3d.config import get_settings
#: URL prefix → path under node_modules/three
VENDOR_MAP = {"three/build/": "build/", "three/examples/jsm/": "examples/jsm/"}
@@ -88,8 +89,6 @@ addEventListener('resize', () => {
def three_root(runtime_js: Path | str | None = None) -> Path | None:
"""``runtime_js/node_modules/three`` when the vendored copy is installed."""
if runtime_js is None:
- from codeverse3d.config import get_settings
-
runtime_js = get_settings().runtime_js_dir()
p = Path(runtime_js) / "node_modules" / "three"
return p if (p / "build" / "three.module.js").is_file() else None
diff --git a/harness/codeverse3d/cli/cost_cmd.py b/harness/codeverse3d/cli/cost_cmd.py
index 52278ee5..941ce9f9 100644
--- a/harness/codeverse3d/cli/cost_cmd.py
+++ b/harness/codeverse3d/cli/cost_cmd.py
@@ -24,6 +24,7 @@ import typer
from typer.core import TyperGroup
from codeverse3d.cli._common import console, ok, runs_root, warn
+from codeverse3d.config import get_settings
#: a price row older than this needs re-checking against the provider's page
STALE_AFTER_DAYS = 90
@@ -212,7 +213,6 @@ def cache(
@cost_app.command("profiles")
def profiles() -> None:
"""The economy / balanced / quality dial and what each is measured to cost."""
- from codeverse3d.config import get_settings
from codeverse3d.cost.profiles import profile_table
header = ("profile", "generator", "judge", "shape", "$/run", "measured quality")
diff --git a/harness/codeverse3d/cli/flywheel_cmd.py b/harness/codeverse3d/cli/flywheel_cmd.py
index 2e959b38..425d68cc 100644
--- a/harness/codeverse3d/cli/flywheel_cmd.py
+++ b/harness/codeverse3d/cli/flywheel_cmd.py
@@ -12,6 +12,7 @@ from rich.markup import escape
from codeverse3d.addons.dataset.pairs import MIN_PREFERENCE_DELTA, build_pairs
from codeverse3d.cli import _common as C
from codeverse3d.cli._common import console, kv_table, ok, warn
+from codeverse3d.config import get_settings
flywheel_app = typer.Typer(no_args_is_help=True)
@@ -102,7 +103,6 @@ def caption_cmd(
"""Caption run(s): {detailed, instruction, factory} via a chat model."""
from codeverse3d.addons.dataset.captions import CaptionError, caption_sample
from codeverse3d.addons.dataset.export import load_captions
- from codeverse3d.config import get_settings
from codeverse3d.cost.instrument import run_ledger
from codeverse3d.proc import RunLocked, exclusive
from codeverse3d.record.record import iter_runs, load_record
diff --git a/harness/codeverse3d/models/anthropic.py b/harness/codeverse3d/models/anthropic.py
index 20b94ce9..3fe486b1 100644
--- a/harness/codeverse3d/models/anthropic.py
+++ b/harness/codeverse3d/models/anthropic.py
@@ -15,6 +15,7 @@ import json
import time
from typing import Any
+from codeverse3d.config import get_settings
from codeverse3d.contracts.chat import (
ChatMessage,
ChatRequest,
@@ -184,7 +185,6 @@ class AnthropicModel(SdkModel):
def _make_client(self) -> Any:
import anthropic
- from codeverse3d.config import get_settings
key = get_settings().anthropic_api_key
if not key:
diff --git a/harness/codeverse3d/models/gemini.py b/harness/codeverse3d/models/gemini.py
index 5085b118..53181d26 100644
--- a/harness/codeverse3d/models/gemini.py
+++ b/harness/codeverse3d/models/gemini.py
@@ -27,6 +27,7 @@ from google.genai import errors as genai_errors
from google.genai import types
from PIL import Image
+from codeverse3d.config import Rate, get_settings
from codeverse3d.contracts.chat import (
ChatMessage,
ChatRequest,
@@ -211,8 +212,6 @@ def shared_pool(keys: list[str], *, max_in_flight: int | None = None) -> KeyPool
"""One ``KeyPool`` per distinct (key list, in-flight cap) per process; an unset cap comes
from ``Settings.rate.max_in_flight``. Its slots are machine-wide: every process draws
from the same ``<cache_dir>/slots/gemini/NN.lock`` files (``retry.Slots``, COST §23)."""
- from codeverse3d.config import get_settings
-
cap = _rate().max_in_flight if max_in_flight is None else max_in_flight
sig = (*keys, f"|{cap}")
with _registry_lock:
@@ -225,8 +224,6 @@ def shared_pool(keys: list[str], *, max_in_flight: int | None = None) -> KeyPool
def _rate() -> Any:
- from codeverse3d.config import Rate, get_settings
-
try:
return get_settings().rate
except Exception: # pragma: no cover - settings must never break a model call
@@ -234,8 +231,6 @@ def _rate() -> Any:
def _default_timeout_s() -> float:
- from codeverse3d.config import get_settings
-
try:
return float(get_settings().model_timeout_s)
except Exception: # pragma: no cover - settings must never break a model call
@@ -243,8 +238,6 @@ def _default_timeout_s() -> float:
def _default_keys() -> list[str]:
- from codeverse3d.config import get_settings
-
return list(get_settings().gemini_api_keys)
@@ -300,8 +293,6 @@ def _ipv4_client_args() -> dict[str, Any]:
— the WSL2 IPv6 path drops these silently and a buffered read then holds the
socket for the whole attempt budget. ``C3D_IPV4=off`` restores the default
(dual-stack) resolution."""
- from codeverse3d.config import get_settings
-
return {"transport": httpx.HTTPTransport(local_address="0.0.0.0")} if get_settings().ipv4 else {}
@@ -491,7 +482,6 @@ class GeminiModel:
warnings: list[str],
) -> ChatResponse:
client = _client_for(key, self.timeout_s, self._client_factory)
- from codeverse3d.config import get_settings
if not get_settings().stream: # C3D_STREAM=off: the buffered call
with Stopwatch() as sw:
diff --git a/harness/codeverse3d/models/openai.py b/harness/codeverse3d/models/openai.py
index 839f0384..2124ecba 100644
--- a/harness/codeverse3d/models/openai.py
+++ b/harness/codeverse3d/models/openai.py
@@ -11,6 +11,7 @@ import logging
import time
from typing import Any
+from codeverse3d.config import get_settings
from codeverse3d.contracts.chat import (
ChatMessage,
ChatRequest,
@@ -153,7 +154,6 @@ class OpenAIModel(SdkModel):
def _make_client(self) -> Any:
import openai
- from codeverse3d.config import get_settings
s = get_settings()
key = s.openai_api_key
diff --git a/harness/codeverse3d/record/telemetry.py b/harness/codeverse3d/record/telemetry.py
index d8f068d4..b631e77b 100644
--- a/harness/codeverse3d/record/telemetry.py
+++ b/harness/codeverse3d/record/telemetry.py
@@ -23,6 +23,7 @@ import json
import logging
from typing import Any
+from codeverse3d.config import get_settings
from codeverse3d.contracts.common import TRACK_INFO
from codeverse3d.contracts.run import (
CostSummary,
@@ -113,8 +114,6 @@ def settings_snapshot(record: RunRecord) -> SettingsSnapshot:
limits: dict[str, Any] = {}
keys = 0
try:
- from codeverse3d.config import get_settings
-
s = get_settings()
render = s.render.model_dump(mode="json")
limits = s.limits.model_dump(mode="json")
diff --git a/harness/codeverse3d/skills/__init__.py b/harness/codeverse3d/skills/__init__.py
index 09f2c751..9c03df3b 100644
--- a/harness/codeverse3d/skills/__init__.py
+++ b/harness/codeverse3d/skills/__init__.py
@@ -30,6 +30,7 @@ import logging
from collections.abc import Iterator
from pathlib import Path
+from codeverse3d.config import get_settings
from codeverse3d.skills.model import (
SKILL_FILE,
Skill,
@@ -43,8 +44,6 @@ log = logging.getLogger(__name__)
def skills_dir() -> Path:
"""The bundle root: this package's directory, as for prompts and rubrics
(``C3D_SKILLS_DIR`` points it elsewhere, read at call time)."""
- from codeverse3d.config import get_settings
-
override = get_settings().skills_dir
if override:
return override.expanduser()
diff --git a/harness/codeverse3d/tracks/depth.py b/harness/codeverse3d/tracks/depth.py
index fdc38f67..8186f5d7 100644
--- a/harness/codeverse3d/tracks/depth.py
+++ b/harness/codeverse3d/tracks/depth.py
@@ -37,6 +37,7 @@ from collections.abc import Sequence
from dataclasses import dataclass
from typing import Any
+from codeverse3d.config import get_settings
from codeverse3d.conventions import MAX_TRIS_OBJECT, to_pascal, to_snake
log = logging.getLogger(__name__)
@@ -108,8 +109,6 @@ DEFAULT_PARTS_PER_SCOPE = 3
def scoped_generation_enabled() -> bool:
"""``C3D_SCOPED_PARTS=off`` turns per-part scoped baselines off (A/B, debugging)."""
- from codeverse3d.config import get_settings
-
return get_settings().scoped_parts
diff --git a/harness/codeverse3d/tracks/generation.py b/harness/codeverse3d/tracks/generation.py
index 1d3f34fc..5d1077a4 100644
--- a/harness/codeverse3d/tracks/generation.py
+++ b/harness/codeverse3d/tracks/generation.py
@@ -41,6 +41,7 @@ from typing import Any
from pydantic import BaseModel, Field
+from codeverse3d.config import get_settings
from codeverse3d.contracts.agent import AgentJob, AgentResult, FileChange
from codeverse3d.contracts.chat import ChatMessage, ChatRequest, ImagePart
from codeverse3d.contracts.common import (
@@ -263,8 +264,6 @@ def agent_max_turns(default: int = DEFAULT_AGENT_MAX_TURNS) -> int:
``0`` means *no cap*: the caller leaves ``AgentJob.max_turns`` at the backend's
own default. That is the measured default (docs/COST.md §17)."""
- from codeverse3d.config import get_settings
-
return get_settings().limits.agent_max_turns or max(0, int(default))
diff --git a/harness/codeverse3d/tracks/planner.py b/harness/codeverse3d/tracks/planner.py
index 70c1819e..529933ec 100644
--- a/harness/codeverse3d/tracks/planner.py
+++ b/harness/codeverse3d/tracks/planner.py
@@ -32,6 +32,7 @@ from typing import Any, TypeVar
from pydantic import BaseModel, ValidationError
+from codeverse3d.config import get_settings
from codeverse3d.contracts.chat import ChatMessage, ChatRequest, ImagePart
from codeverse3d.contracts.common import Language, Track, Usage
from codeverse3d.contracts.plan import AcceptanceItem, EngineeringBrief
@@ -56,15 +57,11 @@ BRIEF_TEMPLATE = "tracks/brief_object.j2"
# ----------------------------------------------------------------------------- brief
def brief_enabled(spec: Spec) -> bool:
"""Whether to expand the brief for this spec (``C3D_PLAN_BRIEF``; object tracks only)."""
- from codeverse3d.config import get_settings
-
return get_settings().plan_brief and spec.track in BRIEF_TRACKS
def brief_cache_dir() -> Path:
"""``Settings.cache_dir``/briefs: ``C3D_CACHE_DIR`` AND the config file's ``cache_dir:``."""
- from codeverse3d.config import get_settings
-
return get_settings().cache_dir / "briefs"
@@ -692,8 +689,6 @@ def restart_note(raw: Any, missing: list[str], budget: PlanBudget) -> str:
def restart_enabled() -> bool:
"""Kill switch for the degenerate-plan restart (``C3D_PLAN_RESTART``, ON; docs/COST.md §30)."""
- from codeverse3d.config import get_settings
-
return get_settings().plan_restart
diff --git a/harness/codeverse3d/tracks/skills_hook.py b/harness/codeverse3d/tracks/skills_hook.py
index d9a02505..83db743e 100644
--- a/harness/codeverse3d/tracks/skills_hook.py
+++ b/harness/codeverse3d/tracks/skills_hook.py
@@ -17,6 +17,7 @@ import logging
from collections.abc import Sequence
from typing import Any
+from codeverse3d.config import get_settings
from codeverse3d.contracts.artifacts import GateReport
from codeverse3d.contracts.run import SkillsUsage
from codeverse3d.tracks.common import RunContext
@@ -30,7 +31,6 @@ def attach_for_round(ctx: RunContext, *, index: int, kind: str, findings: Sequen
"""Route + materialise this round's skills. Returns the ``SkillsMaterialized``.
``findings``: the previous round's gates — the input no CLI's own loader can see."""
- from codeverse3d.config import get_settings
from codeverse3d.skills import attach_skills
# drop the previous round's set first: a failure below must not leave this round