Virtual container¶
CallbackType
module-attribute
¶
Type alias for document callback functions.
ProviderKey
module-attribute
¶
A typed key identifying an object shared through the container.
SignalCache
module-attribute
¶
Cache type for storing signal instances registered from component classes.
SlotThread
module-attribute
¶
Thread a slot is delivered on, as accepted by psygnal.
RedSunConfig
¶
Bases: TypedDict
Base configuration schema for Redsun applications.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
Required[float]
|
Plugin schema version. |
frontend |
Required[str]
|
Frontend toolkit identifier (e.g. |
session |
NotRequired[str]
|
Session display name. If not provided, default is |
metadata |
NotRequired[dict[str, Any]]
|
Additional session-specific metadata to include in the configuration. |
Source code in src/redsun/virtual/_config.py
VirtualContainer
¶
Bases: DynamicContainer, Loggable
Data exchange and dependency injection layer.
VirtualContainer is a DynamicContainer
that also acts as a runtime signal bus and data sharing layer for an application.
Source code in src/redsun/virtual/_container.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
schema_version
property
¶
The plugin schema version specified in the configuration.
metadata
property
¶
The session metadata specified in the configuration.
callbacks
property
¶
The currently registered document callbacks.
subscriptions
property
¶
The device-signal subscriptions made through this container.
unconnected
property
¶
Ports of the built components that no connection reaches.
The complement of connections and subscriptions: what a component
offers and nothing uses. A forgotten connection leaves no trace
anywhere else, since a port that is never named cannot fail.
Returns:
| Type | Description |
|---|---|
Unconnected
|
The unreached signal and slot paths, as |
Raises:
| Type | Description |
|---|---|
WiringError
|
If a component exposes two signals under one port name. |
provide
¶
Bind value to key for this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
ProviderKey[T]
|
The key consumers resolve. |
required |
value
|
T
|
The object to share. Rebinding an already bound key replaces it. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not an instance of the key's |
Source code in src/redsun/virtual/_container.py
require
¶
Resolve key, which must be bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
ProviderKey[T]
|
The key to resolve. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The bound value. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If nothing bound key. Providers are bound during
|
Source code in src/redsun/virtual/_container.py
try_require
¶
Resolve key, or return None if nothing bound it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
ProviderKey[T]
|
The key to resolve. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The bound value, or |
Source code in src/redsun/virtual/_container.py
register_signals
¶
register_signals(
owner: HasName,
name: str | None = None,
only: Iterable[str] | None = None,
) -> None
Cache the signals owner declares.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
HasName
|
The component whose class signals are cached. |
required |
name
|
str | None
|
Registry key. Defaults to |
None
|
only
|
Iterable[str] | None
|
Signal names to cache. Defaults to every
|
None
|
Source code in src/redsun/virtual/_container.py
register_callbacks
¶
register_callbacks(
owner: HasName,
name: str | None = None,
callback_map: dict[str, CallbackType] | None = None,
) -> None
Register one or more document callbacks.
A callback is an event_model.DocumentRouter or any object callable
as (name, doc).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
owner
|
HasName
|
The component registering callbacks, and the callback itself when
callback_map is |
required |
name
|
str | None
|
Registry key for owner. Defaults to |
None
|
callback_map
|
dict[str, CallbackType] | None
|
Several callbacks from one owner, each registered under its own key. owner is then not registered itself. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If a callback is not callable or its signature is incompatible
with |
Source code in src/redsun/virtual/_container.py
connect
¶
connect(
signal: SignalInstance,
slot: Callable[..., Any],
*,
thread: SlotThread = None,
) -> Connection
Connect a signal to a slot and record the link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
SignalInstance
|
The emitting signal. |
required |
slot
|
Callable[..., Any]
|
A bound method marked with |
required |
thread
|
SlotThread
|
Delivery thread. Defaults to the affinity the slot declares, then to the one its class declares. |
None
|
Returns:
| Type | Description |
|---|---|
Connection
|
The recorded link. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If slot is not marked as connectable, or if psygnal rejects the two signatures. |
Source code in src/redsun/virtual/_container.py
subscribe
¶
subscribe(
signal: SignalR[Any],
slot: Callable[..., Any],
*,
thread: SlotThread = None,
) -> Subscription
Subscribe a slot to an ophyd-async device signal and record it.
Delivery is marshalled through a psygnal signal, so thread behaves as
it does for connect. This is the only way a device signal can reach a
slot with a thread affinity: ophyd-async calls its subscribers on
whatever thread produced the reading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
SignalR[Any]
|
The device signal to observe. |
required |
slot
|
Callable[..., Any]
|
A bound method marked with |
required |
thread
|
SlotThread
|
Delivery thread. Defaults to the affinity the slot declares, then to the one its class declares. |
None
|
Returns:
| Type | Description |
|---|---|
Subscription
|
The recorded subscription. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If slot is not marked as connectable. |
Source code in src/redsun/virtual/_container.py
connect_paths
¶
Connect two ports addressed as component.port.
The string form of connect, used by the wiring section of a
configuration file. A signal port is the signal's attribute name, or the
member name when it belongs to a signal group; a slot port is the name
the slot declares.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Path of the emitting signal. |
required |
target
|
str
|
Path of the consuming slot. |
required |
thread
|
SlotThread
|
Delivery thread, overriding the slot and its class. |
None
|
Returns:
| Type | Description |
|---|---|
Connection
|
The recorded link. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If either path is malformed, names a component that was not built, or names a port that component does not expose. The message lists what does exist. |
Source code in src/redsun/virtual/_container.py
disconnect_all
¶
Undo every connection and subscription made through this container.
Source code in src/redsun/virtual/_container.py
HasShutdown
¶
IsInjectable
¶
IsProvider
¶
Connection
dataclass
¶
A recorded link between a signal and a slot.
Attributes:
| Name | Type | Description |
|---|---|---|
publisher |
str
|
|
publisher_port |
str
|
|
consumer |
str
|
|
consumer_port |
str
|
|
thread |
SlotThread
|
|
Source code in src/redsun/virtual/_wiring.py
Ports
dataclass
¶
The connectable surface of a component.
Attributes:
| Name | Type | Description |
|---|---|---|
signals |
dict[str, SignalInstance]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
slots |
dict[str, Callable[..., Any]]
|
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2) |
Source code in src/redsun/virtual/_wiring.py
Subscription
dataclass
¶
A recorded subscription to a device signal.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
str
|
|
consumer |
str
|
|
consumer_port |
str
|
|
thread |
SlotThread
|
|
Source code in src/redsun/virtual/_wiring.py
Unconnected
dataclass
¶
Ports of the built components that no connection reaches.
Each entry is a component.port path. A signal listed here emits into
nothing; a slot listed here is never called.
Attributes:
| Name | Type | Description |
|---|---|---|
signals |
list[str]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
slots |
list[str]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
Source code in src/redsun/virtual/_wiring.py
WiringError
¶
Bases: RuntimeError
Raised when a connection between two components cannot be made.
ports
¶
Return the signals and slots component exposes, by port name.
A signal is a public Signal attribute, or a member of a
SignalGroup the component holds, in which case the
member name is the port name. A slot is a method marked with slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
object
|
The built component to inspect. |
required |
Returns:
| Type | Description |
|---|---|
Ports
|
Its signals and slots, keyed by port name. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If two signals claim the same port name, which would leave the component unaddressable. |
Source code in src/redsun/virtual/_wiring.py
slot
¶
slot(
fn: F | None = None,
/,
*,
name: str | None = None,
thread: SlotThread = None,
) -> F | Callable[[F], F]
Mark a method as connectable to a signal.
A marked method is public API: its name and signature are what other
components are connected against, and an unmarked method cannot be
connected at all. async def methods may be marked too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Port name a configuration file addresses the method by. Defaults to the method name without leading underscores. |
None
|
thread
|
SlotThread
|
Delivery thread, overriding the affinity the class declares. |
None
|