docs: update preset documentation from YAML to TOML
This commit is contained in:
@@ -1,16 +1,35 @@
|
|||||||
"""
|
"""
|
||||||
Pipeline presets - Pre-configured pipeline configurations.
|
Pipeline presets - Pre-configured pipeline configurations.
|
||||||
|
|
||||||
Provides PipelinePreset as a unified preset system that wraps
|
Provides PipelinePreset as a unified preset system.
|
||||||
the existing Preset class from animation.py for backwards compatibility.
|
Presets can be loaded from TOML files (presets.toml) or defined in code.
|
||||||
|
|
||||||
|
Loading order:
|
||||||
|
1. Built-in presets.toml in the package
|
||||||
|
2. User config ~/.config/mainline/presets.toml
|
||||||
|
3. Local ./presets.toml (overrides earlier)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from engine.animation import Preset as AnimationPreset
|
|
||||||
from engine.pipeline.params import PipelineParams
|
from engine.pipeline.params import PipelineParams
|
||||||
|
|
||||||
|
|
||||||
|
def _load_toml_presets() -> dict[str, Any]:
|
||||||
|
"""Load presets from TOML file."""
|
||||||
|
try:
|
||||||
|
from engine.pipeline.preset_loader import load_presets
|
||||||
|
|
||||||
|
return load_presets()
|
||||||
|
except Exception:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
# Pre-load TOML presets
|
||||||
|
_YAML_PRESETS = _load_toml_presets()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PipelinePreset:
|
class PipelinePreset:
|
||||||
"""Pre-configured pipeline with stages and animation.
|
"""Pre-configured pipeline with stages and animation.
|
||||||
@@ -18,7 +37,6 @@ class PipelinePreset:
|
|||||||
A PipelinePreset packages:
|
A PipelinePreset packages:
|
||||||
- Initial params: Starting configuration
|
- Initial params: Starting configuration
|
||||||
- Stages: List of stage configurations to create
|
- Stages: List of stage configurations to create
|
||||||
- Animation: Optional animation controller
|
|
||||||
|
|
||||||
This is the new unified preset that works with the Pipeline class.
|
This is the new unified preset that works with the Pipeline class.
|
||||||
"""
|
"""
|
||||||
@@ -29,13 +47,9 @@ class PipelinePreset:
|
|||||||
display: str = "terminal"
|
display: str = "terminal"
|
||||||
camera: str = "vertical"
|
camera: str = "vertical"
|
||||||
effects: list[str] = field(default_factory=list)
|
effects: list[str] = field(default_factory=list)
|
||||||
initial_params: PipelineParams | None = None
|
|
||||||
animation_preset: AnimationPreset | None = None
|
|
||||||
|
|
||||||
def to_params(self) -> PipelineParams:
|
def to_params(self) -> PipelineParams:
|
||||||
"""Convert to PipelineParams."""
|
"""Convert to PipelineParams."""
|
||||||
if self.initial_params:
|
|
||||||
return self.initial_params.copy()
|
|
||||||
params = PipelineParams()
|
params = PipelineParams()
|
||||||
params.source = self.source
|
params.source = self.source
|
||||||
params.display = self.display
|
params.display = self.display
|
||||||
@@ -44,26 +58,17 @@ class PipelinePreset:
|
|||||||
return params
|
return params
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_animation_preset(cls, preset: AnimationPreset) -> "PipelinePreset":
|
def from_yaml(cls, name: str, data: dict[str, Any]) -> "PipelinePreset":
|
||||||
"""Create a PipelinePreset from an existing animation Preset."""
|
"""Create a PipelinePreset from YAML data."""
|
||||||
params = preset.initial_params
|
|
||||||
return cls(
|
return cls(
|
||||||
name=preset.name,
|
name=name,
|
||||||
description=preset.description,
|
description=data.get("description", ""),
|
||||||
source=params.source,
|
source=data.get("source", "headlines"),
|
||||||
display=params.display,
|
display=data.get("display", "terminal"),
|
||||||
camera=params.camera_mode,
|
camera=data.get("camera", "vertical"),
|
||||||
effects=params.effect_order.copy(),
|
effects=data.get("effects", []),
|
||||||
initial_params=params,
|
|
||||||
animation_preset=preset,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_animation_controller(self):
|
|
||||||
"""Create an AnimationController from this preset."""
|
|
||||||
if self.animation_preset:
|
|
||||||
return self.animation_preset.create_controller()
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
# Built-in presets
|
# Built-in presets
|
||||||
DEMO_PRESET = PipelinePreset(
|
DEMO_PRESET = PipelinePreset(
|
||||||
@@ -121,14 +126,34 @@ FIREHOSE_PRESET = PipelinePreset(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
PRESETS: dict[str, PipelinePreset] = {
|
# Build presets from YAML data
|
||||||
|
def _build_presets() -> dict[str, PipelinePreset]:
|
||||||
|
"""Build preset dictionary from all sources."""
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
# Add YAML presets
|
||||||
|
yaml_presets = _YAML_PRESETS.get("presets", {})
|
||||||
|
for name, data in yaml_presets.items():
|
||||||
|
result[name] = PipelinePreset.from_yaml(name, data)
|
||||||
|
|
||||||
|
# Add built-in presets as fallback (if not in YAML)
|
||||||
|
builtins = {
|
||||||
"demo": DEMO_PRESET,
|
"demo": DEMO_PRESET,
|
||||||
"poetry": POETRY_PRESET,
|
"poetry": POETRY_PRESET,
|
||||||
"pipeline": PIPELINE_VIZ_PRESET,
|
"pipeline": PIPELINE_VIZ_PRESET,
|
||||||
"websocket": WEBSOCKET_PRESET,
|
"websocket": WEBSOCKET_PRESET,
|
||||||
"sixel": SIXEL_PRESET,
|
"sixel": SIXEL_PRESET,
|
||||||
"firehose": FIREHOSE_PRESET,
|
"firehose": FIREHOSE_PRESET,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for name, preset in builtins.items():
|
||||||
|
if name not in result:
|
||||||
|
result[name] = preset
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
PRESETS: dict[str, PipelinePreset] = _build_presets()
|
||||||
|
|
||||||
|
|
||||||
def get_preset(name: str) -> PipelinePreset | None:
|
def get_preset(name: str) -> PipelinePreset | None:
|
||||||
@@ -150,6 +175,5 @@ def create_preset_from_params(
|
|||||||
source=params.source,
|
source=params.source,
|
||||||
display=params.display,
|
display=params.display,
|
||||||
camera=params.camera_mode,
|
camera=params.camera_mode,
|
||||||
effects=params.effect_order.copy(),
|
effects=params.effect_order.copy() if hasattr(params, "effect_order") else [],
|
||||||
initial_params=params,
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user