Skip to content

render_value

Attributes

Classes

RenderValueModuleConfig

Bases: KiaraModuleConfig

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
26
27
28
29
30
31
32
33
34
class RenderValueModuleConfig(KiaraModuleConfig):

    # render_scene_type: str = Field(
    #     description="The id of the model that describes (and handles) the actual rendering."
    # )
    source_type: str = Field(description="The (kiara) data type to be rendered.")
    target_type: str = Field(
        description="The (kiara) data type of210 the rendered result."
    )

Attributes

source_type: str = Field(description='The (kiara) data type to be rendered.') class-attribute instance-attribute
target_type: str = Field(description='The (kiara) data type of210 the rendered result.') class-attribute instance-attribute

RenderValueModule

Bases: KiaraModule

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
class RenderValueModule(KiaraModule):
    @classmethod
    def retrieve_supported_render_combinations(cls) -> Iterable[Tuple[str, str]]:

        result = []
        for attr in dir(cls):
            if (
                len(attr) <= 16
                or not attr.startswith("render__")
                or "__as__" not in attr
            ):
                continue

            attr = attr[8:]
            end_start_type = attr.find("__as__")
            source_type = attr[0:end_start_type]
            target_type = attr[end_start_type + 6 :]
            result.append((source_type, target_type))
        return result

    _config_cls = RenderValueModuleConfig
    _module_type_name: str = None  # type: ignore

    def create_inputs_schema(
        self,
    ) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

        # instruction = self.get_config_value("render_scene_type")
        # model_registry = ModelRegistry.instance()
        # instr_model_cls: Type[RenderScene] = model_registry.get_model_cls(instruction, required_subclass=RenderScene)  # type: ignore

        # data_type_name = instr_model_cls.retrieve_source_type()
        # assert data_type_name

        source_type = self.get_config_value("source_type")
        optional = source_type == "none"
        inputs = {
            "value": {
                "type": source_type,
                "doc": f"A value of type '{source_type}'",
                "optional": optional,
            },
            "render_config": {
                "type": "dict",
                "doc": "Instructions/config on how (or what) to render the provided value.",
                "default": {},
            },
        }
        return inputs

    def create_outputs_schema(
        self,
    ) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

        outputs = {
            "render_value_result": {
                "type": "render_value_result",
                "doc": "The rendered value, incl. some metadata.",
            },
        }

        return outputs

    def process(self, inputs: ValueMap, outputs: ValueMap) -> None:

        source_type = self.get_config_value("source_type")
        target_type = self.get_config_value("target_type")

        value: Value = inputs.get_value_obj("value")

        render_scene: KiaraDict = inputs.get_value_data("render_config")
        if render_scene:
            rc = render_scene.dict_data
        else:
            rc = {}

        func_name = f"render__{source_type}__as__{target_type}"

        func = getattr(self, func_name)
        result = func(value=value, render_config=rc)
        if isinstance(result, RenderValueResult):
            render_scene_result: RenderValueResult = result
        else:
            render_scene_result = RenderValueResult(
                value_id=value.value_id,
                render_config=rc,
                render_manifest=self.manifest.manifest_hash,
                rendered=result,
                related_scenes={},
            )
        render_scene_result.manifest_lookup[self.manifest.manifest_hash] = self.manifest

        outputs.set_value("render_value_result", render_scene_result)

Attributes

_config_cls = RenderValueModuleConfig class-attribute instance-attribute

Functions

retrieve_supported_render_combinations() -> Iterable[Tuple[str, str]] classmethod
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@classmethod
def retrieve_supported_render_combinations(cls) -> Iterable[Tuple[str, str]]:

    result = []
    for attr in dir(cls):
        if (
            len(attr) <= 16
            or not attr.startswith("render__")
            or "__as__" not in attr
        ):
            continue

        attr = attr[8:]
        end_start_type = attr.find("__as__")
        source_type = attr[0:end_start_type]
        target_type = attr[end_start_type + 6 :]
        result.append((source_type, target_type))
    return result
create_inputs_schema() -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def create_inputs_schema(
    self,
) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

    # instruction = self.get_config_value("render_scene_type")
    # model_registry = ModelRegistry.instance()
    # instr_model_cls: Type[RenderScene] = model_registry.get_model_cls(instruction, required_subclass=RenderScene)  # type: ignore

    # data_type_name = instr_model_cls.retrieve_source_type()
    # assert data_type_name

    source_type = self.get_config_value("source_type")
    optional = source_type == "none"
    inputs = {
        "value": {
            "type": source_type,
            "doc": f"A value of type '{source_type}'",
            "optional": optional,
        },
        "render_config": {
            "type": "dict",
            "doc": "Instructions/config on how (or what) to render the provided value.",
            "default": {},
        },
    }
    return inputs
create_outputs_schema() -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
 99
100
101
102
103
104
105
106
107
108
109
110
def create_outputs_schema(
    self,
) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

    outputs = {
        "render_value_result": {
            "type": "render_value_result",
            "doc": "The rendered value, incl. some metadata.",
        },
    }

    return outputs
process(inputs: ValueMap, outputs: ValueMap) -> None
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def process(self, inputs: ValueMap, outputs: ValueMap) -> None:

    source_type = self.get_config_value("source_type")
    target_type = self.get_config_value("target_type")

    value: Value = inputs.get_value_obj("value")

    render_scene: KiaraDict = inputs.get_value_data("render_config")
    if render_scene:
        rc = render_scene.dict_data
    else:
        rc = {}

    func_name = f"render__{source_type}__as__{target_type}"

    func = getattr(self, func_name)
    result = func(value=value, render_config=rc)
    if isinstance(result, RenderValueResult):
        render_scene_result: RenderValueResult = result
    else:
        render_scene_result = RenderValueResult(
            value_id=value.value_id,
            render_config=rc,
            render_manifest=self.manifest.manifest_hash,
            rendered=result,
            related_scenes={},
        )
    render_scene_result.manifest_lookup[self.manifest.manifest_hash] = self.manifest

    outputs.set_value("render_value_result", render_scene_result)

ValueTypeRenderModule

Bases: KiaraModule

A module that uses render methods attached to DataType classes.

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
class ValueTypeRenderModule(KiaraModule):

    """A module that uses render methods attached to DataType classes."""

    _module_type_name = "render.value"
    _config_cls = RenderValueModuleConfig

    def _retrieve_module_characteristics(self) -> ModuleCharacteristics:
        return DEFAULT_IDEMPOTENT_INTERNAL_MODULE_CHARACTERISTICS

    def create_inputs_schema(
        self,
    ) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

        source_type = self.get_config_value("source_type")
        assert source_type not in ["target", "base_name"]

        schema = {
            "value": {
                "type": source_type,
                "doc": "The value to render.",
                "optional": False,
            },
            "render_config": {
                "type": "dict",
                "doc": "Instructions/config on how (or what) to render the provided value.",
                "default": {},
            },
        }

        return schema

    def create_outputs_schema(
        self,
    ) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

        outputs = {
            "render_value_result": {
                "type": "render_value_result",
                "doc": "The rendered value, incl. some metadata.",
            },
        }

        return outputs

    def process(self, inputs: ValueMap, outputs: ValueMap):

        source_value = inputs.get_value_obj("value")
        if not source_value.is_set:
            raise KiaraProcessingException(
                f"Can't render value '{source_value.value_id}': value not set."
            )

        # source_type = self.get_config_value("source_type")
        target_type = self.get_config_value("target_type")

        render_scene: KiaraDict = inputs.get_value_data("render_config")

        try:
            data_type_cls = source_value.data_type_info.data_type_class.get_class()
            data_type = data_type_cls(**source_value.value_schema.type_config)

        except Exception as e:
            source_data_type = source_value.data_type_name
            log_message("data_type.unknown", data_type=source_data_type, error=e)

            from kiara.data_types.included_core_types import AnyType

            data_type = AnyType()

        func_name = f"render_as__{target_type}"
        func = getattr(data_type, func_name)

        if render_scene:
            rc = render_scene.dict_data
        else:
            rc = {}

        result = func(
            value=source_value,
            render_config=rc,
            manifest=self.manifest,
        )

        if isinstance(result, RenderValueResult):
            render_scene_result = result
        else:
            render_scene_result = RenderValueResult(
                value_id=source_value.value_id,
                render_config=rc,
                render_manifest=self.manifest.manifest_hash,
                rendered=result,
                related_scenes={},
                manifest_lookup={self.manifest.manifest_hash: self.manifest},
            )

        outputs.set_value("render_value_result", render_scene_result)

Attributes

_config_cls = RenderValueModuleConfig class-attribute instance-attribute

Functions

create_inputs_schema() -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
def create_inputs_schema(
    self,
) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

    source_type = self.get_config_value("source_type")
    assert source_type not in ["target", "base_name"]

    schema = {
        "value": {
            "type": source_type,
            "doc": "The value to render.",
            "optional": False,
        },
        "render_config": {
            "type": "dict",
            "doc": "Instructions/config on how (or what) to render the provided value.",
            "default": {},
        },
    }

    return schema
create_outputs_schema() -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
176
177
178
179
180
181
182
183
184
185
186
187
def create_outputs_schema(
    self,
) -> Mapping[str, Union[ValueSchema, Mapping[str, Any]]]:

    outputs = {
        "render_value_result": {
            "type": "render_value_result",
            "doc": "The rendered value, incl. some metadata.",
        },
    }

    return outputs
process(inputs: ValueMap, outputs: ValueMap)
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/modules/included_core_modules/render_value.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
def process(self, inputs: ValueMap, outputs: ValueMap):

    source_value = inputs.get_value_obj("value")
    if not source_value.is_set:
        raise KiaraProcessingException(
            f"Can't render value '{source_value.value_id}': value not set."
        )

    # source_type = self.get_config_value("source_type")
    target_type = self.get_config_value("target_type")

    render_scene: KiaraDict = inputs.get_value_data("render_config")

    try:
        data_type_cls = source_value.data_type_info.data_type_class.get_class()
        data_type = data_type_cls(**source_value.value_schema.type_config)

    except Exception as e:
        source_data_type = source_value.data_type_name
        log_message("data_type.unknown", data_type=source_data_type, error=e)

        from kiara.data_types.included_core_types import AnyType

        data_type = AnyType()

    func_name = f"render_as__{target_type}"
    func = getattr(data_type, func_name)

    if render_scene:
        rc = render_scene.dict_data
    else:
        rc = {}

    result = func(
        value=source_value,
        render_config=rc,
        manifest=self.manifest,
    )

    if isinstance(result, RenderValueResult):
        render_scene_result = result
    else:
        render_scene_result = RenderValueResult(
            value_id=source_value.value_id,
            render_config=rc,
            render_manifest=self.manifest.manifest_hash,
            rendered=result,
            related_scenes={},
            manifest_lookup={self.manifest.manifest_hash: self.manifest},
        )

    outputs.set_value("render_value_result", render_scene_result)

Functions