This commit is contained in:
lemke_h committed 2026-09-07 17:11:28 +02:00
1 parent 7af89cdddf
commit dab59611ae
4 files changed
+87 -9

No files matched your search

-8
View File
@@ -1,8 +0,0 @@
"""Throwaway scope module for smoke-testing scripts/eco-box-server end to
end (real subprocess, real network, real box listener) - not part of the
package's public surface, deleted after the smoke test."""
from eco.elements.adjustable import DummyAdjustable
from eco.utilities.config import Namespace
namespace = Namespace(name="smoketest")
namespace.append_obj(DummyAdjustable, name="theta", module_name=None)
+25
View File
@@ -186,6 +186,31 @@ class ControlBox(Assembly):
jogging stutter. "motion: step" forces the stepped behaviour even on
an axis that could jog continuously.
================================================================
RUNNING THIS AS A BACKGROUND SERVICE (no session left open)
================================================================
Everything above works from inside any eco session. If you would
rather not keep an interactive session open just to hold the box
connection, eco.manual_control.box_server does the same thing
(namespace.start_eco_control_box()) as a small standalone process with
its own admin/health HTTP API - mirrors eco-status-server's shape.
eco-box-server start [-b] # foreground, or -b to detach
eco-box-server status # state, box, reason, process stats
eco-box-server disconnect # the safety button
eco-box-server reconnect # offer a session again (box must accept)
eco-box-server restart # re-exec to pick up new device code
eco-box-server gui # Qt monitor/control panel (same actions)
eco-box-server stop
Same env-var-overridable configuration as eco-status-server
(ECO_BOX_SERVER_CHECKOUT/SCOPE/BOX_HOST/BOX_PORT/TOKEN_FILE/...) - see
the script's own header, or `eco-box-server config`.
From a checkout, for quick local testing against uncommitted device
changes: `eco-dev box-server -s bernina` runs the same module in the
foreground against *this* checkout, no wrapper script involved.
================================================================
UPDATING THE SOFTWARE ON THE BOX
================================================================
+54 -1
View File
@@ -68,7 +68,7 @@ _BUILTIN_DEFAULTS = {
"lazy": True,
}
_COMMANDS = ("console", "desktop", "webapp", "jupyterlab")
_COMMANDS = ("console", "desktop", "webapp", "jupyterlab", "box-server")
def _ecorc_path():
@@ -199,6 +199,38 @@ def _run_webapp(args):
)
def _run_box_server(args):
"""Hold this console's connection to the physical manual-control box
as a background service - see eco.manual_control.box_server. Exec's
into that module (like every other _run_* here), so this launcher
stays import-eco-free; -s/--scope picks which instrument namespace to
offer the box (imports eco.<scope>, same as `eco console -s <scope>`).
This is the "run it from a checkout, for quick dev/testing" path -
same module the production `eco-box-server` wrapper script runs, just
without that script's start/stop/systemd/log-file machinery. Runs in
the foreground; Ctrl-C disconnects from the box and exits.
"""
if not args.scope:
sys.exit(
"eco: box-server needs -s/--scope to know which instrument "
"namespace to offer the box, e.g. `eco box-server -s bernina`"
)
cmd = [sys.executable, "-m", "eco.manual_control.box_server", "-s", args.scope]
if args.box_host:
cmd += ["--box-host", args.box_host]
if args.box_port:
cmd += ["--box-port", str(args.box_port)]
if args.token_file:
cmd += ["--token-file", args.token_file]
cmd += ["--host", args.host, "--port", str(args.port)]
_exec(
cmd,
"It ships with eco itself (eco.manual_control.box_server); "
"the admin/health API additionally needs flask (`pip install eco[gui]`).",
)
def _ipython_profile_dir(profile_name):
"""Where IPython keeps a profile's config/startup files -- same
resolution IPython itself uses (~/.ipython, or $IPYTHONDIR if set)."""
@@ -713,6 +745,25 @@ def main(argv=None):
help_off="just open JupyterLab, no separate console (the eco-<scope> kernel is still registered/default if -s is given)",
)
p_box_server = subparsers.add_parser(
"box-server",
help="Hold this console's connection to the physical manual-control "
"box (see eco.manual_control.control_box's manual).",
)
# Same -s/--scope/-l/--set-rcfile as every other subcommand; -l/--lazy is
# accepted but unused (box-server never calls init_all -- see the box's
# own lazy-tree philosophy in control_box.py's manual) so that
# --set-rcfile / .ecorc keep working uniformly across all subcommands.
_add_common_args(p_box_server, defaults, scope_default=defaults["scope"])
p_box_server.add_argument("--box-host", default="ecobox",
help="the box to call (default: %(default)s)")
p_box_server.add_argument("--box-port", type=int, default=8791)
p_box_server.add_argument("--token-file", default="~/.eco/pendant_token")
p_box_server.add_argument("--host", default="0.0.0.0",
help="admin/health HTTP bind address (default: %(default)s)")
p_box_server.add_argument("--port", type=int, default=8092,
help="admin/health HTTP port (default: %(default)s)")
args = parser.parse_args(argv)
if args.set_rcfile is not None:
@@ -730,6 +781,8 @@ def main(argv=None):
_run_webapp(args)
elif args.command == "jupyterlab":
_run_jupyterlab(args)
elif args.command == "box-server":
_run_box_server(args)
if __name__ == "__main__":
+8
View File
@@ -652,3 +652,11 @@ def test_menu_survives_an_adjustable_with_a_broken_memory():
box.set_cursor(names.index("memories"))
box.activate_cursor()
assert any("cannot read memories" in e.name for e in box.entries)
def test_control_box_manual_mentions_the_background_service():
from eco.manual_control.control_box import ControlBox
manual = ControlBox.__doc__
for topic in ["eco-box-server", "eco-dev box-server", "box_server"]:
assert topic in manual, f"manual does not mention {topic!r}"