magscope.scripting#
Utilities for registering and executing scripted automation flows.
This module provides the runtime that powers MagScope’s lightweight
automation system. Users describe a sequence of actions in a script file
by instantiating Script and adding IPC Command instances.
The resulting steps are validated against ScriptRegistry to ensure
that each call is valid before being executed by ScriptManager.
Only methods decorated with register_script_command() are exposed to the
script environment. Script execution runs in its own manager process and
communicates with other parts of the application through the standard IPC
mechanism.
Attributes#
Classes#
Structured representation of a single scripted action. |
|
Metadata binding a script-visible method to its IPC command type. |
|
Container that records the steps of a user-authored script. |
|
Tracks scriptable methods that managers expose to the scripting API. |
|
Lifecycle stages of a script managed by |
|
Process that coordinates script execution and forwards IPC messages. |
Module Contents#
- class magscope.scripting.ScriptCommandRegistration[source]#
Metadata binding a script-visible method to its IPC command type.
- command_type: type[magscope.ipc_commands.Command][source]#
- class magscope.scripting.Script[source]#
Container that records the steps of a user-authored script.
- steps: list[ScriptStep] = [][source]#
- append(command: magscope.ipc_commands.Command, *, wait: bool = False)[source]#
Append an IPC command to the script.
- class magscope.scripting.ScriptRegistry[source]#
Tracks scriptable methods that managers expose to the scripting API.
- _methods: dict[type[magscope.ipc_commands.Command], ScriptCommandRegistration][source]#
- __call__(command_type: type[magscope.ipc_commands.Command]) ScriptCommandRegistration[source]#
Return the registered callable for
command_type.- Raises:
ValueError: If
command_typehas not been registered.
- register_class_methods(cls)[source]#
Inspect
clsfor scriptable methods and add them to the registry.
- check_script(script: Iterable[ScriptStep], *, command_registry=None)[source]#
Validate a compiled script before it is executed.
Checks include verifying that the method exists, arguments bind against the callable signature, and that reserved flags such as
waithave the correct types. Whencommand_registryis provided, the command must also map to a registered IPC handler so that ScriptManager can dispatch it.
- class magscope.scripting.ScriptStatus[source]#
Bases:
enum.StrEnumLifecycle stages of a script managed by
ScriptManager.
- class magscope.scripting.ScriptManager[source]#
Bases:
magscope.processes.ManagerProcessBaseProcess that coordinates script execution and forwards IPC messages.
- _script: list[ScriptStep] = [][source]#
- _script_status: ScriptStatus[source]#
- setup()[source]#
Initialise process state.
Currently no special setup is required, but the hook is retained for symmetry with other
ManagerProcessBaseimplementations.
- load_script(path)[source]#
Load and validate a script from
path.The script file is executed in an isolated namespace. Exactly one
Scriptinstance must be created in that file; its recorded steps are copied locally after validation.
- _execute_script_step(step: ScriptStep)[source]#
Dispatch a single script step to its owning manager.
- _send_script_step_update(current_step: int | None, *, description: str | None = None)[source]#
Notify the GUI of the current script position.
- static _format_script_step(step: ScriptStep) str[source]#
Return a user-friendly description of a script step.