From 0bf5d7484d7b35ae122925ae8ff393370d96d1d4 Mon Sep 17 00:00:00 2001 From: Mirko Holler Date: Mon, 23 Nov 2026 16:50:22 +0100 Subject: [PATCH] feat(client): spec-style wm (names and wildcards, runs dev.wm) Co-Authored-By: Claude Opus 5.5 --- .../plugins/tool_box/spec_commands.py | 19 +++++++++++++++++-- .../startup/post_startup.py | 2 +- .../test_spec_commands.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/tool_box/spec_commands.py b/csaxs_bec/bec_ipython_client/plugins/tool_box/spec_commands.py index 2dfefbeb..12444ffc 100644 --- a/csaxs_bec/bec_ipython_client/plugins/tool_box/spec_commands.py +++ b/csaxs_bec/bec_ipython_client/plugins/tool_box/spec_commands.py @@ -14,6 +14,10 @@ Scans (the number is spec's *intervals*, so 10 intervals = 11 points): ascan, dscan and ct print the BEC command before running it. +Positions: + wm samx samy -> wm("samx", "samy") runs dev.wm(["samx", "samy"]) + wm sam* / wm sam[xy] -> wildcards, as in dev.wm + Only single-line input with the exact word layout above is rewritten; every value must be one word (no spaces). Anything else (umv(...), umv = ..., umv?, loops, function bodies) passes unchanged. @@ -22,8 +26,9 @@ loops, function bodies) passes unchanged. import builtins import re -_CMD = re.compile(r"^(\s*)(umvr?|mvr?|ascan|dscan|ct)(?:\s+(?![(=,.?])(.*?))?\s*$") +_CMD = re.compile(r"^(\s*)(umvr?|mvr?|ascan|dscan|ct|wm)(?:\s+(?![(=,.?])(.*?))?\s*$") _NAME = re.compile(r"^(dev\.)?[A-Za-z_][A-Za-z0-9_]*$") +_WM_NAME = re.compile(r"^(dev\.)?[A-Za-z_*?\[][A-Za-z0-9_*?\[\]]*$") _CT_DEFAULT = 1.0 @@ -49,6 +54,10 @@ def shell_moves(lines): if len(words) > 1 or not all(map(_is_value, words)): return lines args = words + elif cmd == "wm": + if not words or not all(_WM_NAME.match(w) for w in words): + return lines + args = [repr(w.removeprefix("dev.")) for w in words] elif cmd in ("ascan", "dscan"): if len(words) != 5 or not _NAME.match(words[0]) or not all(map(_is_value, words)): return lines @@ -97,9 +106,15 @@ def ct(exp_time=_CT_DEFAULT): return _scans().acquire(exp_time=exp_time) +def wm(*devices): + """spec wm: show readback, setpoint and limits; names, devices or wildcards.""" + names = [d if isinstance(d, str) else d.name for d in devices] + return builtins.__dict__["dev"].wm(names) + + def register(ip): """Install the transformer and the commands once (safe to call again).""" tr = ip.input_transformers_cleanup if not any(getattr(t, "__name__", "") == "shell_moves" for t in tr): tr.append(shell_moves) - ip.user_ns.update(ascan=ascan, dscan=dscan, ct=ct) + ip.user_ns.update(ascan=ascan, dscan=dscan, ct=ct, wm=wm) diff --git a/csaxs_bec/bec_ipython_client/startup/post_startup.py b/csaxs_bec/bec_ipython_client/startup/post_startup.py index d7bb85c6..3a86e35b 100644 --- a/csaxs_bec/bec_ipython_client/startup/post_startup.py +++ b/csaxs_bec/bec_ipython_client/startup/post_startup.py @@ -151,7 +151,7 @@ if _args.session.lower() == "lamni" or _args.session.lower() == "flomni" or _arg from csaxs_bec.bec_ipython_client.startup.beamline_states import set_default_beamline_states set_default_beamline_states(bec, session=_args.session.lower()) -# SPEC-STYLE COMMANDS (umv samx 1, umvr, mv, mvr, ascan, dscan, ct) +# SPEC-STYLE COMMANDS (umv samx 1, umvr, mv, mvr, ascan, dscan, ct, wm) try: from csaxs_bec.bec_ipython_client.plugins.tool_box.spec_commands import register as _register_spec_commands diff --git a/tests/tests_bec_ipython_client/test_spec_commands.py b/tests/tests_bec_ipython_client/test_spec_commands.py index 3e97e400..229829bb 100644 --- a/tests/tests_bec_ipython_client/test_spec_commands.py +++ b/tests/tests_bec_ipython_client/test_spec_commands.py @@ -9,6 +9,7 @@ from csaxs_bec.bec_ipython_client.plugins.tool_box.spec_commands import ( dscan, register, shell_moves, + wm, ) @@ -37,6 +38,13 @@ from csaxs_bec.bec_ipython_client.plugins.tool_box.spec_commands import ( ("ct 1 2\n", None), ("ct = 3\n", None), ("ct?\n", None), + ("wm samx samy\n", "wm('samx', 'samy')\n"), + ("wm dev.samx, sam*\n", "wm('samx', 'sam*')\n"), + ("wm sam[xy]\n", "wm('sam[xy]')\n"), + ("wm\n", None), + ("wm samx 1\n", None), + ("wm(dev.samx)\n", None), + ("wm?\n", None), ], ) def test_shell_moves(src, want): @@ -109,3 +117,10 @@ def test_ct(bec_scans, capsys): ] out = capsys.readouterr().out assert "scans.acquire(exp_time=0.5)" in out and "scans.acquire(exp_time=1.0)" in out + + +def test_wm_passes_names_to_dev_wm(): + dev = mock.MagicMock() + with mock.patch.dict(builtins.__dict__, {"dev": dev}): + wm("samx", _motor("samy"), "sam*") + dev.wm.assert_called_once_with(["samx", "samy", "sam*"])