Unreleased
Generated from the docstrings of Tau 0.16.0-dev (commit c439c401) by scripts/api_docs.py in the Tau repository. Not the 0.15 API.
Embedding tau¶
A program that runs sessions itself: the driver and its clock.
Names: Clock, Driver, DriverState, SystemClock, __version__
Clock¶
class Clock(Protocol)
What the driver reads time through, so a test can move time itself. SystemClock is the
real one.
Clock.now¶
def now(self) -> int
The current time in milliseconds. It stamps the nodes the driver writes.
Driver¶
class Driver
Runs one session's cursors over providers, tools, and extensions.
providers maps each provider name to the provider a model with that provider is
sampled by; each must be named by its own name. The program that built them closes
them. catalog is where a Config node's model name is resolved, at each sample.
user_config (LoadedConfig.user) is what lets an extension save its options to the user's
file (Cursor.save_options, /config --save); without it they raise ConfigError.
A frontend never calls the driver: it holds a Client (client(id) makes one, naming
itself), whose calls run on the loop thread, publish what they changed, and poke the pump.
Once the driver has failed or stopped they raise ConnectionError (the failure's
"Type: msg", chained, or "the driver is stopped"), as rest does; a stream connected then
ends at once. The extensions' commands (/model of the
built-in extension tau first) run for clients; a command that takes a Cursor runs ahead
of the pre_step hooks of a step the driver asks for. Aborting or going elsewhere cancels
it. Extensions are listed in the constructor, in hook order, and checked there like tools
(DefinitionError); model.md does not yet say how config_at names them. reload swaps
them for others while nothing is in flight.
Driver.init¶
def __init__(
self,
session: Session,
providers: Mapping[str, Provider],
catalog: ModelCatalog,
*,
tools: Sequence[Tool | Callable[..., object]] = (),
extensions: Sequence[Extension] = (),
clock: Clock | None = None,
user_config: UserConfig | None = None,
) -> None
Driver.use_catalog¶
def use_catalog(self, catalog: ModelCatalog) -> None
Resolve model names in catalog from the next sample dispatched on.
Driver.reload¶
def reload(self, extensions: Sequence[Extension]) -> None
Run extensions (listed in hook order, as at construction) instead of the ones the
driver has, with the same tools: rebuild the options, tools, tool owners and commands,
and forget every folded Config. Only when nothing is in flight: no cursor busy (a
command waiting for its step has none out yet, but its cursor is busy) and no effect
out, since every job holds the set it was dispatched with (Busy naming the cursors);
the next job dispatched uses the new one. DefinitionError (nothing changes) as at
construction. The tree is not rewritten: a Config node that sets options of an
extension no longer here (or no longer fitting its type) fails when it is read
(ConfigError), not now. Clients are told nothing, as after use_catalog: they ask
commands() and options() again.
Driver.start¶
def start(self) -> None
Start the pump. Call inside the running loop.
Driver.stop¶
async def stop(self) -> None
Cancel everything without answering, as a crash would. rest and every frontend
call raise from now on; client streams end, later ones at once.
Driver.state¶
def state(self) -> DriverState
A snapshot of the driver, for a harness.
Driver.rest¶
async def rest(self, cursor: int, waiter: int | None = None) -> None
Wait until the cursor is at rest with no effect out. Raises ConnectionError once the
driver has failed or stopped (also if it does meanwhile). A cursor held by an open
question or a gate does not rest. Returns early if waiter, the cursor that waits (a
handle's), is aborted or left meanwhile.
Driver.client¶
def client(self, id: str, *, buffer: int = 256) -> LocalClient
A client named id (stable across reconnects: john@laptop:tui), connected now, its
stream opening with the snapshot: make it inside the running loop. buffer bounds the
stream (Feed).
Driver.add_item¶
def add_item(self, to: int, data: ItemData) -> int
Add an item to a cursor's scratchpad; the cursor wakes. For whoever has something
to tell a resting cursor from outside a hook: a timer extension, tau serve relaying a
webhook. An ItemData.Input is what a client's input and send add (they say who
typed it), so it is refused here. A hook adds its extension's item with its handle's
add_item.
DriverState¶
@dataclass(frozen=True)
class DriverState
units: int
queued: bool
open_questions: int
parked: int
failure: Exception | None
stopped: bool
What a harness reads to tell quiet from busy: the effects running (units), whether the
pump has something to do (queued: a report or poke to take, or a busy cursor with no
effect out; never once the driver has failed or stopped, when the session may be closed),
the questions open, the effects parked in the driver (parked: an effect with a question
open or a handle's rest or close_cursor out waits for an answer or another cursor, and
counts once however many it has out), what the driver died of, and whether it was stopped.
check raises ConnectionError for a failed or stopped driver, as every client call does
first.
DriverState.check¶
def check(self) -> None
Raise ConnectionError if the driver has failed or is stopped.
SystemClock¶
class SystemClock
The Clock that reads the wall clock. Pass it to Driver, which reads time only through
a clock; a test passes its own.
SystemClock.now¶
def now(self) -> int
The wall-clock time in milliseconds since the epoch.
version¶
__version__ = version('ffwf-tau')