Files
ResInsight/GrpcInterface/Python/rips/taskmaestro_helper/schema.py
T
Kristian Bendiksen e6dc62a160 Workflows: Add interactive editor for taskmaestro workflows
Build, copy and edit taskmaestro workflows in ResInsight and save them as
standard workflow.yaml + input.yaml.

- Python helper: catalog, load, save and export-registered subcommands,
  and run --registered for installed workflows
- C++ definition model with pure edit operations, port type checks,
  config field derivation, static validation and undo/redo
- Installed folder listing registered workflows (read-only, runnable,
  can be duplicated)
- Graph editor dock with task palette, drag-to-connect, context menus,
  automatic layout and debounced live validation
- New/Duplicate/Save/Save As/Rescan commands; unsaved edits run from a
  temporary folder and prompt before being discarded
- Update the design document and the user README
2026-10-23 20:23:54 +02:00

57 lines
2.0 KiB
Python

"""JSON schemas for task input/output types, as consumed by ResInsight.
taskmaestro's ``TaskSchemaGenerator`` marks opaque Python objects as
``{"not": {}, "x-taskmaestro-opaque": true, ...}``. This module adds
``x-ri-python-type``/``x-ri-python-bases`` to models and opaque types. The bases
list the class MRO so ResInsight can check port compatibility the same way
taskmaestro does (``issubclass``) without importing anything.
"""
from __future__ import annotations
import inspect
from typing import Any
from pydantic import BaseModel
from taskmaestro.introspection import TaskSchemaGenerator, python_type_name
from taskmaestro.introspection import model_json_schema as tm_model_json_schema
from taskmaestro.introspection import task_descriptor as tm_task_descriptor
_IGNORED_BASES = {object, BaseModel}
def python_bases(cls: type[Any]) -> list[str]:
"""Return the dotted names of ``cls`` and its bases, most derived first."""
names: list[str] = []
for base in inspect.getmro(cls):
if base in _IGNORED_BASES or base.__module__ == "typing":
continue
name = python_type_name(base)
if name not in names:
names.append(name)
return names
def _type_annotations(cls: type[Any]) -> dict[str, Any]:
return {
"x-ri-python-type": python_type_name(cls),
"x-ri-python-bases": python_bases(cls),
}
class ResInsightSchemaGenerator(TaskSchemaGenerator):
"""Schema generator that records Python class bases for port compatibility."""
@classmethod
def type_annotations(cls, python_type: type[Any]) -> dict[str, Any]:
return _type_annotations(python_type)
def model_json_schema(model: type[Any]) -> dict[str, Any]:
return tm_model_json_schema(model, ResInsightSchemaGenerator)
def task_descriptor(task_id: str, cls: type[Any]) -> dict[str, Any]:
"""Describe a task class for the ResInsight task palette and port typing."""
return tm_task_descriptor(task_id, cls, ResInsightSchemaGenerator)