Skip to content

root

root #

The top-level context of a @cg.procedure build.

Everything a procedure body records reduces, through a nested [procedure_sequence][..sequence.procedure_sequence], to a single ProcedureSequence emitted here. [RootContext][] enforces that exactly one root remains and exposes it as [RootContext.root][].

RootContext #

Bases: ProcedureContext

The outermost context; reduces a procedure body to its single root node.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/root.py
class RootContext(ProcedureContext):
    """The outermost context; reduces a procedure body to its single root node."""

    def __init__(self) -> None:
        """Start with no root reduced yet."""
        super().__init__()
        self._root: Procedure[CGType] | None = None

    def _finish(self) -> None:
        steps = self._step_roots()
        if len(steps) != 1:
            raise AuthoringError(
                f"a procedure must reduce to exactly one root node, got {len(steps)}"
            )
        self._root = steps[0]

    def root(self) -> Procedure[CGType]:
        """The single root node the procedure reduced to."""
        if self._root is None:
            raise AuthoringError("root() called before the context finished")
        return self._root

__init__() #

Start with no root reduced yet.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/root.py
def __init__(self) -> None:
    """Start with no root reduced yet."""
    super().__init__()
    self._root: Procedure[CGType] | None = None

root() #

The single root node the procedure reduced to.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/root.py
def root(self) -> Procedure[CGType]:
    """The single root node the procedure reduced to."""
    if self._root is None:
        raise AuthoringError("root() called before the context finished")
    return self._root