Skip to content

kiara.operations

Operation pydantic-model

id: str pydantic-field required

The operation id.

create_renderable(self, **config)

Create a printable overview of this operations details.

Available config options: - 'include_full_doc' (default: True): whether to include the full documentation, or just a description - 'include_src' (default: False): whether to include the module source code

Source code in kiara/operations/__init__.py
def create_renderable(self, **config: typing.Any) -> RenderableType:
    """Create a printable overview of this operations details.

    Available config options:
      - 'include_full_doc' (default: True): whether to include the full documentation, or just a description
      - 'include_src' (default: False): whether to include the module source code
    """

    include_full_doc = config.get("include_full_doc", True)

    table = Table(box=box.SIMPLE, show_header=False, show_lines=True)
    table.add_column("Property", style="i")
    table.add_column("Value")

    if self.doc:
        if include_full_doc:
            table.add_row("Documentation", self.doc.full_doc)
        else:
            table.add_row("Description", self.doc.description)

    module_type_md = self.module.get_type_metadata()

    table.add_row("Module type", self.module_type)
    conf = Syntax(
        json.dumps(self.module_config, indent=2), "json", background_color="default"
    )
    table.add_row("Module config", conf)

    constants = self.module_config.get("constants")
    inputs_table = create_table_from_field_schemas(
        _add_required=True,
        _add_default=True,
        _show_header=True,
        _constants=constants,
        **self.module.input_schemas,
    )
    table.add_row("Inputs", inputs_table)
    outputs_table = create_table_from_field_schemas(
        _add_required=False,
        _add_default=False,
        _show_header=True,
        _constants=None,
        **self.module.output_schemas,
    )
    table.add_row("Outputs", outputs_table)

    m_md_o = module_type_md.origin.create_renderable()
    m_md_c = module_type_md.context.create_renderable()
    m_md = RenderGroup(m_md_o, m_md_c)
    table.add_row("Module metadata", m_md)

    if config.get("include_src", False):
        table.add_row("Source code", module_type_md.process_src)

    return table