Skip to content

Commit 192237f

Browse files
cli-precedence (#857)
* cli-precedence * allow passing global config to build * shorter Former-commit-id: ec3e850 [formerly ad9e527] Former-commit-id: c7afdb5
1 parent c2ab722 commit 192237f

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

dimos/core/blueprints.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,16 @@ def _connect_rpc_methods(self, module_coordinator: ModuleCoordinator) -> None:
268268
requested_method_name, rpc_methods_dot[requested_method_name]
269269
)
270270

271-
def build(self, global_config: GlobalConfig | None = None) -> ModuleCoordinator:
271+
def build(
272+
self,
273+
global_config: GlobalConfig | None = None,
274+
cli_config_overrides: Mapping[str, Any] | None = None,
275+
) -> ModuleCoordinator:
272276
if global_config is None:
273277
global_config = GlobalConfig()
274-
global_config = global_config.model_copy(update=self.global_config_overrides)
278+
global_config = global_config.model_copy(update=dict(self.global_config_overrides))
279+
if cli_config_overrides:
280+
global_config = global_config.model_copy(update=dict(cli_config_overrides))
275281

276282
self._check_requirements()
277283
self._verify_no_name_conflicts()

dimos/core/test_blueprints.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
autoconnect,
2828
)
2929
from dimos.core.core import rpc
30-
from dimos.core.global_config import GlobalConfig
3130
from dimos.core.module import Module
3231
from dimos.core.module_coordinator import ModuleCoordinator
3332
from dimos.core.rpc_client import RpcCall
@@ -162,7 +161,7 @@ def test_build_happy_path() -> None:
162161

163162
blueprint_set = autoconnect(module_a(), module_b(), module_c())
164163

165-
coordinator = blueprint_set.build(GlobalConfig())
164+
coordinator = blueprint_set.build()
166165

167166
try:
168167
assert isinstance(coordinator, ModuleCoordinator)
@@ -298,7 +297,7 @@ class TargetModule(Module):
298297
assert ("color_image", Data1) not in blueprint_set._all_name_types
299298

300299
# Build and verify connections work
301-
coordinator = blueprint_set.build(GlobalConfig())
300+
coordinator = blueprint_set.build()
302301

303302
try:
304303
source_instance = coordinator.get_instance(SourceModule)
@@ -351,7 +350,7 @@ def test_future_annotations_autoconnect() -> None:
351350

352351
blueprint_set = autoconnect(FutureModuleOut.blueprint(), FutureModuleIn.blueprint())
353352

354-
coordinator = blueprint_set.build(GlobalConfig())
353+
coordinator = blueprint_set.build()
355354

356355
try:
357356
out_instance = coordinator.get_instance(FutureModuleOut)

dimos/robot/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ Configuration values can be set from multiple places in order of precedence (lat
5353
- Default value defined on GlobalConfig. (`simulation = False`)
5454
- Value defined in `.env` (`SIMULATION=true`)
5555
- Value in the environment variable (`SIMULATION=true`)
56-
- Value coming from the CLI (`--simulation` or `--no-simulation`)
5756
- Value defined on the blueprint (`blueprint.global_config(simulation=True)`)
57+
- Value coming from the CLI (`--simulation` or `--no-simulation`)
5858

5959
For environment variables/`.env` values, you have to prefix the name with `DIMOS_`.
6060

dimos/robot/cli/dimos.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from enum import Enum
1616
import inspect
1717
import sys
18-
from typing import Optional, get_args, get_origin
18+
from typing import Any, Optional, get_args, get_origin
1919

2020
import typer
2121

@@ -89,8 +89,7 @@ def create_dynamic_callback(): # type: ignore[no-untyped-def]
8989

9090
def callback(**kwargs) -> None: # type: ignore[no-untyped-def]
9191
ctx = kwargs.pop("ctx")
92-
overrides = {k: v for k, v in kwargs.items() if v is not None}
93-
ctx.obj = GlobalConfig().model_copy(update=overrides)
92+
ctx.obj = {k: v for k, v in kwargs.items() if v is not None}
9493

9594
callback.__signature__ = inspect.Signature(params) # type: ignore[attr-defined]
9695

@@ -111,22 +110,23 @@ def run(
111110
"""Start a robot blueprint"""
112111
setup_exception_handler()
113112

114-
config: GlobalConfig = ctx.obj
113+
cli_config_overrides: dict[str, Any] = ctx.obj
115114
pubsub.lcm.autoconf() # type: ignore[attr-defined]
116115
blueprint = get_blueprint_by_name(robot_type.value)
117116

118117
if extra_modules:
119118
loaded_modules = [get_module_by_name(mod_name) for mod_name in extra_modules] # type: ignore[attr-defined]
120119
blueprint = autoconnect(blueprint, *loaded_modules)
121120

122-
dimos = blueprint.build(global_config=config)
121+
dimos = blueprint.build(cli_config_overrides=cli_config_overrides)
123122
dimos.loop()
124123

125124

126125
@main.command()
127126
def show_config(ctx: typer.Context) -> None:
128127
"""Show current config settings and their values."""
129-
config: GlobalConfig = ctx.obj
128+
cli_config_overrides: dict[str, Any] = ctx.obj
129+
config = GlobalConfig().model_copy(update=cli_config_overrides)
130130

131131
for field_name, value in config.model_dump().items():
132132
typer.echo(f"{field_name}: {value}")

0 commit comments

Comments
 (0)