procedure
procedure
#
The Procedure[T] base class — a node in the capture DAG.
A procedure is one node of a directed acyclic graph that the companion app
executes; Python only declares the graph. The generic parameter T is the
CGType the node produces — a value (Image, Array[Image]), a
Path[...] position, or Void.
The class body is a top-down index of the node's abilities: each concern is defined in its own module and imported here, so go to definition on any member lands on its implementation.
- state — methods.state
- construction hooks — methods.initialization
- identity — methods.identity
- field views — methods.fields
- navigation and
|=/&=caching — methods.navigation - boolean / numeric operators — methods.operators
- JSON / Graphviz export — methods.export
- field markers, classification, and validation — type_checking
The public authoring names re-export through here, so a node module needs only::
from capturegraph.procedures.procedure import (
Input,
Procedure,
Setting,
make_procedure,
)
Procedure
#
Bases: ProcedureState
Base class for every procedure node.
Subclasses are declared with [make_procedure][], parameterized by the
CGType they return, and use the field markers to declare their fields::
@make_procedure
class AssertBool(Procedure[Void]):
condition: Input[Bool]
message: Setting[str]
They inherit construction-time validation, identity by uuid, and the
fluent operators. Python never executes procedures.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str | None
|
Optional human-readable description of what this node does. |
Source code in capturegraph-lib/capturegraph/procedures/procedure/__init__.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 | |
__and__(other)
#
a & b — a BoolAnd node.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/operators.py
__eq__(other)
#
Two procedures are equal iff they are the same node (same uuid).
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/identity.py
__ge__(other)
#
a >= b — BoolNot(NumberLessThan(a, b)).
__getattr__(name)
#
Read a struct field; bound as Procedure.__getattr__.
E.g. root.reference, CapturePanorama().preview. Only missing attributes
reach here, and dunders never navigate.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
__getitem__(key)
#
__getitem__(
self: Procedure[Array],
key: int
| Procedure[CGType]
| JSONScalar
| bool
| float
| str,
) -> Procedure[CGType]
Index a navigable position or a value-access array / map.
On a navigated Path it selects an array element / map entry position
(another Path). On a map value a node returns it selects the entry's
value (MapKey); on the Array that a map's keys()/values()
returns it selects the element value — a key scalar, or a Path[V] to
navigate. The runtime dispatches all of these through the same navigable view.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
__gt__(other)
#
a > b — NumberLessThan with the operands swapped.
__hash__()
#
__iand__(value)
#
path &= value — cache the value, overwriting any stored value.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
__init_subclass__()
#
Record the subclass's return type from its Procedure[X] base.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/initialization.py
__invert__()
#
~a — a BoolNot node.
__ior__(value)
#
path |= value — cache the value, skipping if already stored.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
__le__(other)
#
a <= b — BoolNot(NumberLessThan(b, a)).
__lt__(other)
#
a < b — a NumberLessThan node.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/operators.py
__or__(other)
#
a | b — a BoolOr node.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/operators.py
__post_init__()
#
Stamp identity, type-check the node, and register it with the context.
Constructing a node registers it with the active recording context (which
is how a procedure body is built — see
capturegraph.procedures.procedure.authoring.contexts). There must be one: a node
built with no active context raises, unless under cg.detached().
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/initialization.py
__repr__()
#
The node's DAG as pretty-printed JSON.
Equivalent to this node's to_json.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/export.py
__setattr__(name, value)
#
Type-checker-only stub; make_procedure installs the real version.
__setitem__(key, value)
#
Absorb the arr[i] |= value / map[k] &= value rebind.
arr[i] |= value desugars to arr.__setitem__(i, arr[i].__ior__(value));
the cache was already recorded by __ior__, so this swallows it — but only
when it is this exact slot's own cache (its destination is the navigation
child for key), mirroring the strict struct-field __setattr__ guard. A
plain arr[i] = value, or a cache built for a different slot, is rejected.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
__str__()
#
"label (Kind)", or just "Kind" when unlabeled.
exists()
#
path.exists() — a Bool that is true when a value is stored here.
Reads the position from disk (LoadPath) and reports whether that read
completes (ProcedureCompleted), so a missing value yields false instead
of aborting the run. Pair it with cg.when(...) to run a block only once the
position has been written. The read goes to disk regardless of any value cached
at this slot this run, so it tests what was already present before the run.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
keys()
#
A map position's keys as a read-only Array[K] value (index to select one).
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
load()
#
path.load() — read the value stored at this position.
Loading is explicit: an unwritten position used as a value never lowers to a disk read on its own. The read waits for a stored value (a prior run's, or one an interceptor fills); while nothing is stored it stays pending, so use [load_or][] when an absent value should produce a fallback instead. The read goes to disk regardless of any value cached at this slot this run, so it sees what was already present before the run.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
load_or(default)
#
path.load_or(default) — the stored value, or default's value.
Returned when nothing is stored here. The fallback runs only on a definitive
"nothing stored" answer — never while the value is still loading — so a slow
remote read cannot be mistaken for an absent one. default is a procedure (or
raw literal) whose type matches the position's — so a typed default names the
result's type, and the compile-time validation pass enforces the match.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/navigation.py
preload(default)
#
node.preload(default) — pre-answer this node with an adjustable default.
default is a procedure (or a raw literal, lifted to a constant) whose
type matches this node's; the runtime preloads it in so the node starts
complete and the user may adjust it before capturing::
session.photo &= cg.CaptureImage(
raw_photo=cg.UserInputBool(label="RAW").preload(False),
)
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/preloading.py
set_label(label)
#
Set a label on this node (in place) and return it, for fluent chaining.
static_map_keys()
#
The keys of the Map this node produces, when known at authoring time.
E.g. CaptureImagesByLabel's labels; None when they are only known at
runtime. A value-level [key] access warns when a constant key is
provably absent from this set; nodes whose keys are dynamic leave it
None and are never second-guessed.
Source code in capturegraph-lib/capturegraph/procedures/procedure/__init__.py
to_graphviz(group_by_depth=False)
#
This node's DAG as a Graphviz diagram for visualization.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/export.py
to_json(indent=4, target_schema=None)
#
This node's DAG as a JSON string in the cross-platform wire form.
See procedure_to_json.
Source code in capturegraph-lib/capturegraph/procedures/procedure/methods/export.py
values()
#
A map position's entry positions as Array[Path[V]].
Fan out, or index to select one to navigate.