Skip to content

root

root #

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

Everything a procedure body records reduces here to a single ProcedureSequence — the procedure's root node, exposed as [RootContext.root][]. It is the one context with no parent, so the root sequence belongs to no enclosing block.

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:
        from capturegraph.procedures.nodes.process.structural import (
            ProcedureSequence,
        )
        from capturegraph.procedures.procedure.authoring.contexts.detached import (
            detached,
        )

        with detached():
            self._root = ProcedureSequence(procedures=self._step_roots())

    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