Skip to content

optional

optional #

cg.optional() — collect a block into an OptionalProcedure.

The block runs but may fail or be skipped without failing the surrounding procedure. A path cached inside the block stays assigned and readable for the rest of the procedure.

OptionalContext #

Bases: ProcedureContext

Reduce a block's roots to a sequence wrapped in an OptionalProcedure.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/optional.py
class OptionalContext(ProcedureContext):
    """Reduce a block's roots to a sequence wrapped in an ``OptionalProcedure``."""

    def _finish(self) -> None:
        from capturegraph.procedures.nodes.process.structural import (
            OptionalProcedure,
            ProcedureSequence,
        )

        OptionalProcedure(procedure=ProcedureSequence(procedures=self._step_roots()))

optional() #

Run the with block as an optional step; its failure never propagates.

Source code in capturegraph-lib/capturegraph/procedures/procedure/authoring/contexts/optional.py
@contextmanager
def optional() -> Iterator[None]:
    """Run the ``with`` block as an optional step; its failure never propagates."""
    with OptionalContext().collect():
        yield