Virtual container¶
CallbackType
module-attribute
¶
A document callback.
ProviderKey
module-attribute
¶
A typed key identifying an object shared through the container.
SignalCache
module-attribute
¶
Signal instances registered by components.
SlotThread
module-attribute
¶
Thread a slot is delivered on, as accepted by psygnal.
RedSunConfig
¶
Bases: TypedDict
Base configuration schema of a redsun application.
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, |
metadata |
NotRequired[dict[str, Any]]
|
Session metadata. |
Source code in src/redsun/virtual/_config.py
VirtualContainer
¶
Bases: DynamicContainer, Loggable
Signal bus, shared data and dependency injection of an application.
A DynamicContainer that
is also the application's signal bus and data exchange.
Source code in src/redsun/virtual/_container.py
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 607 608 609 610 611 612 613 614 615 | |
subscriptions
property
¶
The device-signal subscriptions made through this container.
unconnected
property
¶
Ports of the built components that no connection reaches.
What components offer minus connections and subscriptions. A
forgotten connection shows nowhere else, since an unnamed port 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. Keys are bound in |
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 as |
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
|
Thread the slot runs on. Defaults to the slot's affinity, then its class's. |
None
|
Returns:
| Type | Description |
|---|---|
Connection
|
The recorded link. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If slot is not marked, or |
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.
Readings pass through a psygnal signal, so thread works as in
connect. It is the only way a device signal reaches a slot with a
thread affinity: ophyd-async calls subscribers on whichever 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
|
Thread the slot runs on. Defaults to the slot's affinity, then its class's. |
None
|
Returns:
| Type | Description |
|---|---|
Subscription
|
The recorded subscription. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If slot is not marked. |
Source code in src/redsun/virtual/_container.py
connect_paths
¶
Connect two ports addressed as component.port.
The string form of connect, used by a configuration file's wiring
section. A signal port is the signal's attribute name, or its member
name in 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
|
Thread the slot runs on, overriding the slot and its class. |
None
|
Returns:
| Type | Description |
|---|---|
Connection
|
The recorded link. |
Raises:
| Type | Description |
|---|---|
WiringError
|
If a path is malformed or names a port the component lacks; the message lists the existing ones. |
ComponentNotBuilt
|
If a path names a component that is not there. |
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
¶
Bases: Protocol
A class that shuts down synchronously.
Source code in src/redsun/virtual/_protocols.py
IsInjectable
¶
IsProvider
¶
ComponentNotBuilt
¶
Bases: WiringError
Raised when a port path names a component that is not there.
component is the name in the path, so a caller knowing which components
failed to build can tell those apart from a name never declared.
Source code in src/redsun/virtual/_wiring.py
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 listed signal emits to nothing; a
listed slot 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, named by its
member 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 have the same port name. |
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's name and signature are public API, since other components
connect to them; an unmarked method cannot be connected. async def
methods can be marked too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Port name in a configuration file. Defaults to the method name without leading underscores. |
None
|
thread
|
SlotThread
|
Thread the slot runs on, overriding the class's affinity. |
None
|