Expose `RuntimeVars` + `get_runtime_vars()` from pkg

Export the new `RuntimeVars` struct and `get_runtime_vars()`
from `tractor.__init__` and improve the accessor to
optionally return the struct form.

Deats,
- add `RuntimeVars` and `get_runtime_vars` to
  `__init__.py` exports; alphabetize `_state` imports.
- move `get_runtime_vars()` up in `_state.py` to sit
  right below `_runtime_vars` dict definition.
- add `as_dict: bool = True` param so callers can get
  either the legacy `dict` or the new `RuntimeVars`
  struct.
- drop the old stub fn at bottom of `_state.py`.
- rm stale `from .msg.pretty_struct import Struct` comment.

(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
multicast_revertable_streams
Gud Boi 2026-03-23 13:33:39 -04:00
parent be5e7e446b
commit 94458807ce
2 changed files with 22 additions and 12 deletions

View File

@ -41,10 +41,12 @@ from ._supervise import (
ActorNursery as ActorNursery, ActorNursery as ActorNursery,
) )
from ._state import ( from ._state import (
RuntimeVars as RuntimeVars,
current_actor as current_actor, current_actor as current_actor,
is_root_process as is_root_process,
current_ipc_ctx as current_ipc_ctx, current_ipc_ctx as current_ipc_ctx,
debug_mode as debug_mode debug_mode as debug_mode,
get_runtime_vars as get_runtime_vars,
is_root_process as is_root_process,
) )
from ._exceptions import ( from ._exceptions import (
ContextCancelled as ContextCancelled, ContextCancelled as ContextCancelled,

View File

@ -33,7 +33,6 @@ from typing import (
import platformdirs import platformdirs
from trio.lowlevel import current_task from trio.lowlevel import current_task
# from .msg.pretty_struct import Struct
from msgspec import ( from msgspec import (
field, field,
Struct, Struct,
@ -54,6 +53,7 @@ _def_tpt_proto: TransportProtocolKey = 'tcp'
_current_actor: Actor|None = None # type: ignore # noqa _current_actor: Actor|None = None # type: ignore # noqa
_last_actor_terminated: Actor|None = None _last_actor_terminated: Actor|None = None
# TODO: mk this a `msgspec.Struct`! # TODO: mk this a `msgspec.Struct`!
# -[x] type out all fields obvi! # -[x] type out all fields obvi!
# -[ ] (eventually) mk wire-ready for monitoring? # -[ ] (eventually) mk wire-ready for monitoring?
@ -140,6 +140,23 @@ _runtime_vars: dict[str, Any] = {
} }
def get_runtime_vars(
as_dict: bool = True,
) -> dict:
'''
Deliver a **copy** of the current `Actor`'s "runtime variables".
By default, for historical impl reasons, this delivers the `dict`
form, but the `RuntimeVars` struct should be utilized as possible
for future calls.
'''
if as_dict:
return dict(_runtime_vars)
return RuntimeVars(**_runtime_vars)
def last_actor() -> Actor|None: def last_actor() -> Actor|None:
''' '''
Try to return last active `Actor` singleton Try to return last active `Actor` singleton
@ -301,12 +318,3 @@ def current_ipc_protos() -> list[str]:
''' '''
return _runtime_vars['_enable_tpts'] return _runtime_vars['_enable_tpts']
# !TODO, convert this to the new `RuntimeVars` struct!
def get_runtime_vars() -> dict:
'''
Deliver a **copy** of the current `Actor`'s "runtime variables".
'''
return dict(_runtime_vars)