p2: old style deprecated support + wf_authoring to use new stuff
holy moly file changes
This commit is contained in:
@@ -3,15 +3,15 @@ from __future__ import annotations
|
||||
from copy import deepcopy
|
||||
|
||||
from wf_core.models.workflow import Workflow
|
||||
from wf_core.paths import set_nested_value
|
||||
from wf_core.run_state import ExecutionFrame, FrameStatus, RunState, RunStatus
|
||||
|
||||
|
||||
def create_run_state(workflow: Workflow, workflow_input: dict[str, object]) -> RunState:
|
||||
state = {
|
||||
name: deepcopy(field.default)
|
||||
for name, field in workflow.state_schema.fields.items()
|
||||
if field.default is not None
|
||||
}
|
||||
state: dict[str, object] = {}
|
||||
for field in workflow.state_schema.fields:
|
||||
if field.default is not None:
|
||||
set_nested_value(state, list(field.path.parts), deepcopy(field.default))
|
||||
state.update(dict(workflow_input))
|
||||
run = RunState(
|
||||
workflow_name=workflow.name,
|
||||
|
||||
@@ -7,6 +7,7 @@ from typing import Any
|
||||
from wf_core.errors import WorkflowExecutionError
|
||||
from wf_core.local_paths import LocalPathError, get_local_value, has_overlapping_paths
|
||||
from wf_core.models.reducers import ReducerRef
|
||||
from wf_core.models.schemas import StateFieldDecl
|
||||
from wf_core.models.steps import NodeUse, OutputBinding
|
||||
from wf_core.models.workflow import Workflow
|
||||
from wf_core.paths import (
|
||||
@@ -59,6 +60,7 @@ def apply_output_bindings(
|
||||
"mapped state patch has overlapping destination paths"
|
||||
)
|
||||
|
||||
state_fields = workflow.state_schema.field_map()
|
||||
resolved_patch: dict[StatePath, Any] = {}
|
||||
for binding in bindings:
|
||||
try:
|
||||
@@ -77,6 +79,7 @@ def apply_output_bindings(
|
||||
destination_path,
|
||||
value,
|
||||
reducers=reducers,
|
||||
state_fields=state_fields,
|
||||
)
|
||||
prepared_patch[destination_path] = (key_path, merged_value)
|
||||
|
||||
@@ -137,6 +140,7 @@ def prepare_state_value(
|
||||
value: Any,
|
||||
*,
|
||||
reducers: Mapping[str, ReducerDefinition] | None = None,
|
||||
state_fields: Mapping[str, StateFieldDecl] | None = None,
|
||||
) -> tuple[list[str], Any]:
|
||||
"""Resolve reducer output for a state write without mutating state."""
|
||||
try:
|
||||
@@ -150,7 +154,10 @@ def prepare_state_value(
|
||||
)
|
||||
|
||||
declared_path = ".".join(parts)
|
||||
declared_field = workflow.state_schema.fields.get(declared_path)
|
||||
fields = (
|
||||
state_fields if state_fields is not None else workflow.state_schema.field_map()
|
||||
)
|
||||
declared_field = fields.get(declared_path)
|
||||
reducer = (
|
||||
declared_field.reducer if declared_field else ReducerRef(name="wf.std.replace")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user