Skip to content

Why configuration, context and lifecycle are separate

A translator combines three kinds of information: validated configuration, mutable workflow state, and operations on that state. Keeping those responsibilities separate lets a hook be tested without launching the CLI or loading a real model dataset.

PluginConfig is a Pydantic model. Its fields describe settings, while a PluginContext carries systems, file stores, rules and metadata between hooks. A class plugin receives this context through from_context() and accesses public properties such as config, system and store. It does not need to override those properties or read _ctx.

on_build() returns the system for a later on_transform() or on_export(). Only implemented hooks run. This ordering makes dependencies visible, but it does not provide rollback: changes made before a failed hook may remain. The lifecycle tutorial checks success and failure paths with a complete implementation. The reference records the exact hook order and result contracts.

A class is useful when several lifecycle stages share context. An exposed function is useful for a single transform with explicit system and configuration arguments. This complete example shows that the function changes a supplied system:

>>> from r2x_core import PluginConfig, System, expose_plugin
>>> from rust_ok import Ok, Result
>>> class RenameConfig(PluginConfig):
... name: str = "renamed"
>>> @expose_plugin
... def rename(system: System, config: RenameConfig) -> Result[System, str]:
... system.name = config.name
... return Ok(system)
>>> system = System(name="original")
>>> result = rename(system, RenameConfig())
>>> # Expected: a successful Result contains the same changed system.
>>> result.unwrap().name
# 'renamed'
>>> assert result.unwrap() is system

Discovery belongs to the installed package boundary

Section titled “Discovery belongs to the installed package boundary”

The Rust CLI discovers registered entry points and manages its own Python environment. Adding core to a separate project does not install a translator there. See plugin discovery and the CLI guide to managing plugins. Installing a plugin runs Python code with the host process’s permissions. It is not a sandbox.