vpype_cli.State¶
- class State(document: Document | None = None)¶
Encapsulates the current state of the vpype pipeline processing.
This class encapsulates the current state of the pipeline and provides services to commands. To access the current state instance, a command must use the
pass_state()decorator.- Parameters:
document (vp.Document | None) -- if provided, use this document
Methods
Context manager to set the current state (used internally).
Context manager to temporarily set expression variables.
Returns the current
Stateinstance.Evaluate an argument.
Evaluate any instance of
_DeferredEvaluatorand replace them with the converted value.Apply property and expression substitution on user input.
Attributes
Content of the current pipeline.
Default layer ID used by
generator()andlayer_processor()commands when--layeris not provided.Layer ID being populated by a
generator()or processed by alayer_processor()command.
Methods¶
- State.current()¶
Context manager to set the current state (used internally).
- State.expression_variables(variables: dict[str, Any]) Generator[None, None, None]¶
Context manager to temporarily set expression variables.
This context manager is typically used by block processors to temporarily set relevant expression variables. These variables are deleted or, if pre-existing, restored upon exiting the context.
Example:
>>> import vpype_cli >>> @vpype_cli.cli.command() ... @vpype_cli.block_processor ... def run_twice(state, processors): ... with state.expression_variables({"_first": True}): ... vpype_cli.execute_processors(processors, state) ... with state.expression_variables({"_first": False}): ... vpype_cli.execute_processors(processors, state)
- classmethod State.get_current()¶
Returns the current
Stateinstance.Commands should use the
pass_state()decorator instead of using this function.
- State.preprocess_argument(arg: Any) Any¶
Evaluate an argument.
If
argis a_DeferredEvaluatorinstance, evaluate it a return its value instead.
Attributes¶
- State.target_layer_id: int | None¶
Default layer ID used by
generator()andlayer_processor()commands when--layeris not provided.
- State.current_layer_id: int | None¶
Layer ID being populated by a
generator()or processed by alayer_processor()command.