Registry¶
The workbench catalogue of what can be opened, the runner that streams catalogue scripts, and the process tree a stop ends.
femforge_workbench.registry
¶
The workbench catalogue: specs of what can be opened, discovered from the built-ins and the femforge.workbenches entry points, imported only on open.
Type Aliases:
-
Target–A
pkg.module:attrstring, or the module-level function it names.
Classes:
-
WorkbenchKind–How a spec is opened: a dock of panels, one Renderable in a plotter, or a script run in a subprocess.
-
OutputKind–How a script output is shown.
-
OutputSpec–One file a script produces.
-
WorkbenchSpec–One card of the catalogue: what it is, how it opens, and what it leaves behind.
-
EntryPointLike–What discover needs from an entry point.
Functions:
-
split_target–The module and optional attribute of a
pkg.module:attrtarget. -
resolve–The object a target names, importing its module now:
pkg.module:attrgives the attribute,pkg.modulethe module. -
script_module–The module name the running script imports as: its
-mname, else its file's stem, since the script's directory leads sys.path. -
target_of–The
pkg.module:attrstring of a target; a function defined in the running script is named by the module its file imports as. -
script–A script card, run in a subprocess.
-
panel–A dock card.
-
renderable–A viewer card, rebuilt on save.
-
legacy–The spec of a module following the old
main() -> Renderablecontract. -
discover–Every spec: the built-ins plus what each entry point in the group provides (a spec or a sequence), sorted by group and title; a name given two different specs is an error.
Attributes:
-
BUILTIN(tuple[WorkbenchSpec, ...]) –The specs discover() carries without an entry point.
BUILTIN
module-attribute
¶
BUILTIN: tuple[WorkbenchSpec, ...] = (LAUNCHER, DEMO, BROWSERS, FIELD_VIEWER, MONITORS)
The specs discover() carries without an entry point.
Target
¶
A pkg.module:attr string, or the module-level function it names.
WorkbenchKind
¶
Bases: StrEnum
How a spec is opened: a dock of panels, one Renderable in a plotter, or a script run in a subprocess.
OutputKind
¶
Bases: StrEnum
How a script output is shown.
Methods:
-
from_path–The kind a file's suffix implies, text when unknown.
from_path
classmethod
¶
from_path(path: Path) -> OutputKind
The kind a file's suffix implies, text when unknown.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
OutputSpec
dataclass
¶
OutputSpec(path: Path, title: str, kind: OutputKind)
One file a script produces.
Methods:
-
at–An output typed from its suffix and titled by its name unless given.
-
modified–When the file was last written, None while it does not exist.
at
classmethod
¶
at(path: Path, title: str | None = None) -> OutputSpec
An output typed from its suffix and titled by its name unless given.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
WorkbenchSpec
dataclass
¶
WorkbenchSpec(name: str, title: str, kind: WorkbenchKind, target: str, description: str = '', group: str = '', args: tuple[str, ...] = (), cwd: Path | None = None, outputs: tuple[OutputSpec, ...] = ())
One card of the catalogue: what it is, how it opens, and what it leaves behind.
Methods:
-
last_run–The newest output timestamp, None when nothing has been produced.
-
command–The subprocess that runs this spec: the module for a script, the workbench CLI for the rest.
Attributes:
last_run
¶
last_run() -> datetime | None
The newest output timestamp, None when nothing has been produced.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
command
¶
The subprocess that runs this spec: the module for a script, the workbench CLI for the rest.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
EntryPointLike
¶
split_target
¶
The module and optional attribute of a pkg.module:attr target.
resolve
¶
The object a target names, importing its module now: pkg.module:attr gives the attribute, pkg.module the module.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
script_module
¶
script_module() -> str
The module name the running script imports as: its -m name, else its file's stem, since the script's directory leads sys.path.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
target_of
¶
The pkg.module:attr string of a target; a function defined in the running script is named by the module its file imports as.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
script
¶
script(name: str, title: str, *, target: str, description: str = '', group: str = '', args: Sequence[str] = (), cwd: Path | None = None, outputs: Sequence[OutputSpec] = ()) -> WorkbenchSpec
A script card, run in a subprocess.
Parameters:
-
name(str) –The card's unique name, which the command line opens it by.
-
title(str) –The title the card and the title menu show.
-
target(str) –The module run with
-m. -
description(str, default:'') –The one-line summary under the title.
-
group(str, default:'') –The catalogue group the card is listed under.
-
args(Sequence[str], default:()) –The arguments the script runs with.
-
cwd(Path | None, default:None) –The directory the script runs in; None keeps the shell's.
-
outputs(Sequence[OutputSpec], default:()) –The files the script produces, which the launcher shows.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
panel
¶
panel(name: str, title: str, *, target: Target, description: str = '', group: str = '', args: Sequence[str] = ()) -> WorkbenchSpec
A dock card.
Parameters:
-
name(str) –The card's unique name, which the command line opens it by.
-
title(str) –The title the card and the title menu show.
-
target(Target) –A module-level function returning the dock Split, or its
pkg.module:attrname. -
description(str, default:'') –The one-line summary under the title.
-
group(str, default:'') –The catalogue group the card is listed under.
-
args(Sequence[str], default:()) –The arguments the card's command passes to the workbench command line.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
renderable
¶
renderable(name: str, title: str, *, target: Target, description: str = '', group: str = '', args: Sequence[str] = ()) -> WorkbenchSpec
A viewer card, rebuilt on save.
Parameters:
-
name(str) –The card's unique name, which the command line opens it by.
-
title(str) –The title the card and the title menu show.
-
target(Target) –A module-level function returning the Renderable, or its
pkg.module:attrname. -
description(str, default:'') –The one-line summary under the title.
-
group(str, default:'') –The catalogue group the card is listed under.
-
args(Sequence[str], default:()) –The arguments the card's command passes to the workbench command line.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
legacy
¶
legacy(module: str) -> WorkbenchSpec
The spec of a module following the old main() -> Renderable contract.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
discover
¶
discover(entry_points: Sequence[EntryPointLike] | None = None) -> list[WorkbenchSpec]
Every spec: the built-ins plus what each entry point in the group provides (a spec or a sequence), sorted by group and title; a name given two different specs is an error.
Source code in packages/femforge-workbench/src/femforge_workbench/registry.py
femforge_workbench.runner
¶
Script runs on the server loop: each catalogue script as a subprocess whose lines stream as they arrive and whose process tree dies on stop.
Type Aliases:
-
LineHandler–Receives the task name and one output line without its newline.
-
TaskHandler–Receives the task after it started and again after it exited.
Classes:
-
TaskStatus–Where a script run stands.
-
TaskField–The keys of a task row in the client state.
-
Task–One script run: its process, when it started and how it ended.
-
ScriptRunner–Starts named commands, streaming their output lines and reporting each status change.
Attributes:
-
LINE_LIMIT–Bytes one streamed line may hold before the reader gives up on it.
-
STREAM_ENV–Makes the child flush every line as it is written, in UTF-8 whatever the console code page, laid out for a wide terminal.
LINE_LIMIT
module-attribute
¶
Bytes one streamed line may hold before the reader gives up on it.
STREAM_ENV
module-attribute
¶
Makes the child flush every line as it is written, in UTF-8 whatever the console code page, laid out for a wide terminal.
LineHandler
¶
Receives the task name and one output line without its newline.
TaskHandler
¶
Receives the task after it started and again after it exited.
Task
dataclass
¶
Task(name: str, process: Process, tree: ProcessTree, started: datetime = now(), status: TaskStatus = RUNNING, returncode: int | None = None, stopping: bool = False)
ScriptRunner
¶
ScriptRunner(on_line: LineHandler, on_change: TaskHandler)
Starts named commands, streaming their output lines and reporting each status change.
Methods:
-
running–Whether the named task runs.
-
rows–Every task as a row of the client state.
-
run–Runs the command to completion, streaming its lines; a name still running is an error.
-
stop–Kills the task's process tree; its run then ends as stopped.
Source code in packages/femforge-workbench/src/femforge_workbench/runner.py
running
¶
rows
¶
run
async
¶
Runs the command to completion, streaming its lines; a name still running is an error.
Parameters:
-
name(str) –The task name, unique among the running tasks.
-
command(Sequence[str]) –The command and its arguments.
-
cwd(Path | None, default:None) –The directory the command runs in; None keeps the server's.
Source code in packages/femforge-workbench/src/femforge_workbench/runner.py
stop
async
¶
stop(name: str) -> None
Kills the task's process tree; its run then ends as stopped.
Source code in packages/femforge-workbench/src/femforge_workbench/runner.py
femforge_workbench.process_tree
¶
One child process and everything it starts, ended together: a job object on Windows, a process group elsewhere.
Classes:
-
ProcessTree–One process and every process it starts: a job object on Windows, the process group the leader heads elsewhere.
Attributes:
-
WINDOWS(Final) –Whether a tree is a job object (Windows) or a process group (elsewhere).
-
CREATION_FLAGS(Final) –creationflags for Popen: CREATE_SUSPENDED on Windows, so the child waits until it is in its job and nothing it starts can escape; 0 elsewhere.
-
NEW_SESSION(Final) –start_new_session for Popen: on POSIX the child leads a process group of its own, whose id is its pid.
-
KILL_GRACE(Final) –Seconds a terminated tree gets before what is left is killed.
-
POLL(Final) –Seconds between looks at a tree that was asked to exit.
WINDOWS
module-attribute
¶
Whether a tree is a job object (Windows) or a process group (elsewhere).
CREATION_FLAGS
module-attribute
¶
creationflags for Popen: CREATE_SUSPENDED on Windows, so the child waits until it is in its job and nothing it starts can escape; 0 elsewhere.
NEW_SESSION
module-attribute
¶
start_new_session for Popen: on POSIX the child leads a process group of its own, whose id is its pid.
KILL_GRACE
module-attribute
¶
KILL_GRACE: Final = 2.0
Seconds a terminated tree gets before what is left is killed.
ProcessTree
dataclass
¶
One process and every process it starts: a job object on Windows, the process group the leader heads elsewhere.
Methods:
-
adopt–Takes a process spawned with
CREATION_FLAGSandNEW_SESSION: into a new job and let run on Windows, checked to lead its own group elsewhere. -
kill–Ends every process in the tree and returns how many there were; POSIX asks first and kills what is left after
graceseconds, Windows has no gentle signal. -
close–Ends anything still in the tree and releases it: a job dies with its handle, a group gets SIGKILL.
Attributes:
-
pid(int) –The process the tree was built around; on POSIX also the group id.
-
job(int) –The Windows job handle; 0 on POSIX, where a group needs none.
pid
instance-attribute
¶
pid: int
The process the tree was built around; on POSIX also the group id.
job
class-attribute
instance-attribute
¶
job: int = 0
The Windows job handle; 0 on POSIX, where a group needs none.
adopt
classmethod
¶
adopt(pid: int) -> ProcessTree
Takes a process spawned with CREATION_FLAGS and NEW_SESSION: into a new job and let run on Windows, checked to lead its own group elsewhere.
Source code in packages/femforge-workbench/src/femforge_workbench/process_tree.py
kill
¶
kill(grace: float = KILL_GRACE) -> int
Ends every process in the tree and returns how many there were; POSIX asks first and kills what is left after grace seconds, Windows has no gentle signal.
Source code in packages/femforge-workbench/src/femforge_workbench/process_tree.py
close
¶
Ends anything still in the tree and releases it: a job dies with its handle, a group gets SIGKILL.