module documentation

The command line: opensmi-ros2 serve machine.toml and python -m opensmi.ros2.

Both call main, which reads the file with ~opensmi.ros2.server.loader.load_machine, builds opensmi's Server, adds the Machine and serves until Ctrl+C or SIGTERM.

opensmi-ros2 serve machine.toml
opensmi-ros2 serve machine.toml --server-config other-server.toml

rclpy is imported only once the whole file has been validated, so --help and a file with mistakes work on a machine without ROS2.

[server] config = "server.toml" in the machine file and --server-config PATH point to an opensmi server configuration (endpoint, users, logging). The command line wins. A path in the file is relative to the file, a path on the command line to the working directory.

Exit status: 0 after a clean stop, 1 when the file or a configuration cannot be used (each mistake is printed to stderr, one per line, and nothing has been started), 2 for a command line argparse refuses.

Function main Run the command line and return its exit status.
Async Function serve Serve a Machine in an opensmi Server until stop is set, then shut the server down.
Constant PROG Undocumented
Exception _UnusableError Something the user gave cannot be used; the message is what to tell them.
Function _parser Undocumented
Function _refuse Say on stderr why nothing was started, and return the exit status for it.
Function _require_file Refuse a --server-config that is not a file, before anything is built.
Async Function _run Serve until SIGINT or SIGTERM, where the loop can listen for them.
def main(argv: Sequence[str] | None = None, *, runtime_factory: Callable[[ROS2Config], RuntimeInterface] | None = None) -> int:

Run the command line and return its exit status.

Parameters
argv:Sequence[str] | NoneThe arguments after the program name; None reads sys.argv.
runtime_factory:Callable[[ROS2Config], RuntimeInterface] | NonePassed to load_machine; None builds the real Runtime, which needs rclpy. A test passes one that returns its fake.
Returns
intUndocumented
async def serve(machine: ConfiguredMachine, *, server_config: Path | None, stop: asyncio.Event):

Serve a Machine in an opensmi Server until stop is set, then shut the server down.

Parameters
machine:ConfiguredMachineThe Machine to serve.
server_config:Path | NoneAn opensmi server configuration file, or None for opensmi's defaults.
stop:asyncio.EventSet to ask for a clean stop. Cancelling the task stops it as well.
Raises
_UnusableErrorWhen the server configuration cannot be read.
PROG: str =

Undocumented

Value
'opensmi-ros2'
def _parser() -> argparse.ArgumentParser:

Undocumented

def _refuse(message: str) -> int:

Say on stderr why nothing was started, and return the exit status for it.

def _require_file(given: Path | None):

Refuse a --server-config that is not a file, before anything is built.

async def _run(machine: ConfiguredMachine, server_config: Path | None):

Serve until SIGINT or SIGTERM, where the loop can listen for them.