diff --git a/tractor/__init__.py b/tractor/__init__.py index 6fac747f..374b7875 100644 --- a/tractor/__init__.py +++ b/tractor/__init__.py @@ -41,10 +41,12 @@ from ._supervise import ( ActorNursery as ActorNursery, ) from ._state import ( + RuntimeVars as RuntimeVars, current_actor as current_actor, - is_root_process as is_root_process, 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 ( ContextCancelled as ContextCancelled, diff --git a/tractor/_state.py b/tractor/_state.py index b3458cf7..d3b5851e 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -33,7 +33,6 @@ from typing import ( import platformdirs from trio.lowlevel import current_task -# from .msg.pretty_struct import Struct from msgspec import ( field, Struct, @@ -54,6 +53,7 @@ _def_tpt_proto: TransportProtocolKey = 'tcp' _current_actor: Actor|None = None # type: ignore # noqa _last_actor_terminated: Actor|None = None + # TODO: mk this a `msgspec.Struct`! # -[x] type out all fields obvi! # -[ ] (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: ''' Try to return last active `Actor` singleton @@ -301,12 +318,3 @@ def current_ipc_protos() -> list[str]: ''' 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)