Configuration: a generic dataclass loader, and the ROS2 settings an application injects.
ROS2 settings are their own TOML file and dataclass, not a [ros2] table in the opensmi server
configuration, because that tree is closed and refuses keys it does not know. The application loads
ROS2Config itself and hands it to the Runtime and the Machine mixin.
A setting lives here and not on a declaration when it is true of the Machine (one ROS2 Domain ID)
and not of one object on it. TransformConfig is the case: the transform topics and the TF
poll period look like Binding keywords, but one Domain ID has one frame network and one poll. Such a
value declared per object is refused and named here instead.
The two settings dataclasses raise ~opensmi.ros2.server.errors.DeclarationError on
contradictory values. The loader raises ValueError and TypeError only.
The loader is one function over any dataclass and also reads the Binding TOML of
opensmi.ros2.server.bindings. It behaves like opensmi.core.config.load_dataclass, including
ValueError on an unknown key, with two differences:
- It converts a TOML array into a tuple when the field asks for one, since the declarations are frozen and a list would make them unhashable.
- A TOML file can name no Python class. A field whose type is not a string, number, boolean, time or a
container of those (enums and nested dataclasses are built from them) is refused a value, so an
editable file cannot run code. Custom implementation classes and callables are Python-side keywords
only. The machine file (
opensmi.ros2.server.loader) reaches a few by importing a named path and handing the object in through supplied.
| Class | |
The ROS2 settings of one Machine, which is the unit of one Domain ID. |
| Class | |
Where this Machine reads TF from, and how often the frame network is sampled. |
| Exception | |
A TOML value does not fit the field it was written under. |
| Function | declarable |
Return the fields of a dataclass that a TOML table can set, in declaration order. |
| Function | from |
Build a dataclass instance from a TOML table. |
| Function | load |
Load a TOML file into a dictionary. |
| Function | python |
Return the fields of a dataclass that a TOML table cannot set: the complement of declarable_keys. |
| Constant | TF |
How many seconds pass between polls of the frame network, unless a deployment says otherwise. |
| Constant | TF |
How many seconds a frame may go unpublished before it is quiet, by default. |
| Class | _ |
The annotation of a field that cannot be evaluated at run time, so no TOML value fits it. |
| Function | _as |
Return a TOML array or table as the read-only container a frozen declaration annotates. |
| Function | _as |
Return the enum member a TOML value names, or say which ones exist. |
| Function | _as |
Return a TOML array as the tuple a frozen declaration holds. |
| Function | _convert |
Convert one TOML value into the type its field declares. |
| Function | _convert |
Convert a table key, which TOML always spells as a string, into the type the field wants. |
| Function | _expressible |
Return whether a TOML document can produce a value of one field's declared type. |
| Function | _file |
Return the members of a union a file can write: not None, and not type beside a name. |
| Function | _hints |
Return the type hints of a dataclass, field by field where they cannot be had at once. |
| Function | _require |
Refuse a key whose field is not something a TOML document can produce a value for. |
| Function | _require |
Return a value after checking it is the TOML scalar its field declares. |
| Constant | _TOML |
Every Python type a TOML document can produce a value of. |
| Type Variable | _T |
Undocumented |
Return the fields of a dataclass that a TOML table can set, in declaration order.
The complement stays Python-side: a callable or a class has no TOML spelling.
type[ _T], data: Mapping[ str, Any], *, supplied: Mapping[ str, Any] | None = None) -> _T:
¶
Build a dataclass instance from a TOML table.
| Parameters | |
datatype[ | Undocumented |
data:Mapping[ | Undocumented |
supplied:Mapping[ | Values for fields a TOML table cannot produce a value of (a class or a callable), which the caller has obtained some other way. They are passed to the constructor as they are. A name in both data and here is the caller's mistake. |
| Returns | |
_T | Undocumented |
| Raises | |
TypeError | When the target is not a dataclass, or a table was expected and something else arrived. |
FieldError | When a value does not fit its field: the wrong TOML type, an enum member
that does not exist, a nested table that is not one. A ValueError and a
TypeError, naming the field. |
ValueError | When the table carries a key the dataclass does not declare, or a key whose field a TOML file cannot produce a value for (a string would otherwise sit where a callable belongs). |
Return the fields of a dataclass that a TOML table cannot set: the complement of declarable_keys.
A caller that lets a file name one by import path passes the imported object to from_dict
as supplied.
How many seconds pass between polls of the frame network, unless a deployment says otherwise.
| Value |
|
How many seconds a frame may go unpublished before it is quiet, by default.
This has to clear the slowest publisher on the robot: a diagnostic frame republished every two seconds is healthy. A deployment that knows its publishers can tighten it.
| Value |
|
Return a TOML array or table as the read-only container a frozen declaration annotates.
An array becomes a tuple and a table a dict, with its keys converted to the key type.
Return a TOML array as the tuple a frozen declaration holds.
tuple[str, ...] converts element by element, a fixed-length tuple position by position.
Return whether a TOML document can produce a value of one field's declared type.
object takes any TOML value as it was read, for a field that checks its own shape later.
Return the members of a union a file can write: not None, and not type beside a name.
A class alternative (str | type) is the Python spelling of what the file writes as a name.
Return the type hints of a dataclass, field by field where they cannot be had at once.
A field annotated with a type-checker-only alias maps to _Unresolved, a Python-side keyword.
Refuse a key whose field is not something a TOML document can produce a value for.
| Raises | |
ValueError | When the field's type is not a TOML scalar, an enum, a dataclass, or a container of those (a callable or class would arrive as a string). |
Return a value after checking it is the TOML scalar its field declares.
Only bool, int, float and str are checked. An int may stand where a float is wanted, and a bool is never a number.
Every Python type a TOML document can produce a value of.
| Value |
|