Skip to content

Commit 07be477

Browse files
committed
Add dry run behaviour
Signed-off-by: Maria Teresa Ortega <teresa.ortega0903@gmail.com>
1 parent cd71b24 commit 07be477

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

examples/beluga/beluga_benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
@lambkin.option("--clock-rate", default=100.0)
2626
@lambkin.option("--sensor-topic", default="/scan")
27+
@lambkin.option("--dry-run", default=False)
2728
def nominal(ctx):
2829
"""Run a nominal Beluga AMCL benchmark across sensor models and particle counts.
2930
@@ -39,6 +40,7 @@ def nominal(ctx):
3940
print(f"sensor_topic: {ctx.options.sensor_topic}")
4041
print(f"source: {ctx.source}")
4142
print("---")
43+
ctx.shell = lambkin.ShellProxy(dry_run=ctx.options.dry_run)
4244
ctx.shell.ros2.launch(
4345
ctx.source.path.parent / "beluga.launch.xml",
4446
f"sensor_model:={ctx.variant.sensor_model}",

src/lambkin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
from lambkin.common import named_product
1818
from lambkin.core.decorators import benchmark, option
19+
from lambkin.core.shell.proxy import ShellProxy
1920

2021
__all__ = [
2122
"benchmark",
2223
"named_product",
2324
"option",
25+
"ShellProxy",
2426
]

src/lambkin/core/shell/proxy.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
class _CommandProxy:
2828
"""Builds a shell command lazily by chaining attribute access and calls."""
2929

30-
def __init__(self, parts: list[str]) -> None:
30+
def __init__(self, parts: list[str], dry_run: bool = False) -> None:
3131
"""Initialize the proxy with the command words accumulated so far."""
3232
self._parts = parts
33+
self._dry_run = dry_run
3334

3435
def __getattr__(self, name: str) -> _CommandProxy:
3536
"""Append a new word to the command and return a new proxy."""
36-
return _CommandProxy(self._parts + [name])
37+
return _CommandProxy(self._parts + [name], self._dry_run)
3738

3839
def __call__(self, *args: Any, **kwargs: Any) -> None:
3940
"""Finalize and print the command.
@@ -59,12 +60,19 @@ def __call__(self, *args: Any, **kwargs: Any) -> None:
5960
extra.extend([flag, shlex.quote(str(value))])
6061

6162
command = " ".join(self._parts + extra)
62-
print(f"[CMD]: {command}")
63+
64+
if self._dry_run:
65+
# TODO: extend to dispatch commands to BackgroundProcess for real execution.
66+
print(f"[CMD]: {command}")
6367

6468

6569
class ShellProxy:
6670
"""Dry-run mock shell that prints commands instead of executing them."""
6771

72+
def __init__(self, dry_run: bool = False) -> None:
73+
"""Initialize the ShellProxy with the given dry_run flag."""
74+
self._dry_run = dry_run
75+
6876
def __getattr__(self, name: str) -> _CommandProxy:
6977
"""Start building a new command from the given top-level tool name."""
70-
return _CommandProxy([name])
78+
return _CommandProxy([name], self._dry_run)

0 commit comments

Comments
 (0)