feat(client): spec-style wm (names and wildcards, runs dev.wm)
CI for csaxs_bec / test (push) Successful in 3m49s
CI for csaxs_bec / test (pull_request) Successful in 3m45s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mirko HollerandClaude Opus 5.5 committed 2026-11-23 16:50:22 +01:00
1 parent 6e84ad3c73
commit c39f3f5ff0
3 files changed
+33 -3

No files matched your search

@@ -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)
@@ -145,7 +145,7 @@ def _check_account_mismatch():
if _args.session.lower() == "lamni" or _args.session.lower() == "flomni" or _args.session.lower() == "omny":
_check_account_mismatch()
# 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
@@ -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*"])