Skip to content

info

Attributes

INFO_BASE_INSTANCE_TYPE = TypeVar('INFO_BASE_INSTANCE_TYPE') module-attribute

INFO_BASE_CLASS = TypeVar('INFO_BASE_CLASS', bound=type) module-attribute

RENDER_FIELDS: Dict[str, Dict[str, Any]] = {'value_id': {'show_default': True, 'render': {'terminal': lambda v: str(v.value_id)}}, 'aliases': {'show_default': True, 'render': {'terminal': lambda v: ', '.join(v.aliases)}}, 'type': {'show_default': True, 'render': {'terminal': lambda x: x.value_schema.type}}, 'value_schema': {'show_default': False}, 'is_persisted': {'show_default': False, 'render': {'terminal': lambda v: 'yes' if v.is_persisted else 'no'}}, 'hash': {'show_default': False, 'render': {'terminal': lambda v: v.value_hash}}, 'data': {'show_default': False, 'render': {'terminal': pretty_print_value_data_terminal}}, 'pedigree': {'show_default': False, 'render': {'terminal': lambda v: '-- external data -- ' if v == ORPHAN else v}}, 'lineage': {'show_default': False}, 'load_config': {'show_default': False}, 'data_type_config': {'show_default': False, 'render': {'terminal': lambda v: Syntax(orjson_dumps(v.value_schema.type_config, option=orjson.OPT_INDENT_2), 'json', background_color='default')}}, 'serialize_details': {'show_default': False, 'render': {'terminal': lambda v: v.serialized.create_renderable()}}, 'properties': {'show_default': False, 'render': {'terminal': lambda v: v.property_values.create_renderable(show_header=False)}}, 'size': {'show_default': True, 'render': {'terminal': lambda v: humanfriendly.format_size(v.value_size)}}} module-attribute

INFO_ITEM_TYPE = TypeVar('INFO_ITEM_TYPE', bound=ItemInfo) module-attribute

Classes

ValueTypeAndDescription

Bases: BaseModel

Source code in kiara/interfaces/python_api/models/info.py
153
154
155
156
157
158
class ValueTypeAndDescription(BaseModel):

    description: str = Field(description="The description for the value.")
    type: str = Field(description="The value type.")
    value_default: Any = Field(description="Default for the value.", default=None)
    required: bool = Field(description="Whether this value is required")

Attributes

description: str = Field(description='The description for the value.') class-attribute
type: str = Field(description='The value type.') class-attribute
value_default: Any = Field(description='Default for the value.', default=None) class-attribute
required: bool = Field(description='Whether this value is required') class-attribute

ItemInfo

Bases: KiaraModel, Generic[INFO_BASE_INSTANCE_TYPE]

Base class that holds/manages information about an item within kiara.

Source code in kiara/interfaces/python_api/models/info.py
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
class ItemInfo(KiaraModel, Generic[INFO_BASE_INSTANCE_TYPE]):

    """Base class that holds/manages information about an item within kiara."""

    @classmethod
    @abc.abstractmethod
    def base_instance_class(cls) -> Type[INFO_BASE_INSTANCE_TYPE]:
        pass

    @classmethod
    @abc.abstractmethod
    def create_from_instance(
        cls, kiara: "Kiara", instance: INFO_BASE_INSTANCE_TYPE, **kwargs
    ):
        pass

    @validator("documentation", pre=True)
    def validate_doc(cls, value):

        return DocumentationMetadataModel.create(value)

    type_name: str = Field(description="The registered name for this item type.")
    documentation: DocumentationMetadataModel = Field(
        description="Documentation for the item."
    )
    authors: AuthorsMetadataModel = Field(
        description="Information about authorship for the item."
    )
    context: ContextMetadataModel = Field(
        description="Generic properties of this item (description, tags, labels, references, ...)."
    )

    def _retrieve_id(self) -> str:
        return self.type_name

    def _retrieve_data_to_hash(self) -> Any:
        return self.type_name

    def create_renderable(self, **config: Any) -> RenderableType:

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

        table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
        table.add_column("property", style="i")
        table.add_column("value")

        if include_doc:

            table.add_row(
                "Documentation",
                Panel(self.documentation.create_renderable(), box=box.SIMPLE),
            )
        table.add_row("Author(s)", self.authors.create_renderable())
        table.add_row("Context", self.context.create_renderable())

        if hasattr(self, "python_class"):
            table.add_row("Python class", self.python_class.create_renderable())  # type: ignore

        return table

Attributes

type_name: str = Field(description='The registered name for this item type.') class-attribute
documentation: DocumentationMetadataModel = Field(description='Documentation for the item.') class-attribute
authors: AuthorsMetadataModel = Field(description='Information about authorship for the item.') class-attribute
context: ContextMetadataModel = Field(description='Generic properties of this item (description, tags, labels, references, ...).') class-attribute

Functions

base_instance_class() -> Type[INFO_BASE_INSTANCE_TYPE] abstractmethod classmethod
Source code in kiara/interfaces/python_api/models/info.py
165
166
167
168
@classmethod
@abc.abstractmethod
def base_instance_class(cls) -> Type[INFO_BASE_INSTANCE_TYPE]:
    pass
create_from_instance(kiara: Kiara, instance: INFO_BASE_INSTANCE_TYPE, **kwargs) abstractmethod classmethod
Source code in kiara/interfaces/python_api/models/info.py
170
171
172
173
174
175
@classmethod
@abc.abstractmethod
def create_from_instance(
    cls, kiara: "Kiara", instance: INFO_BASE_INSTANCE_TYPE, **kwargs
):
    pass
validate_doc(value)
Source code in kiara/interfaces/python_api/models/info.py
177
178
179
180
@validator("documentation", pre=True)
def validate_doc(cls, value):

    return DocumentationMetadataModel.create(value)
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def create_renderable(self, **config: Any) -> RenderableType:

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

    table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
    table.add_column("property", style="i")
    table.add_column("value")

    if include_doc:

        table.add_row(
            "Documentation",
            Panel(self.documentation.create_renderable(), box=box.SIMPLE),
        )
    table.add_row("Author(s)", self.authors.create_renderable())
    table.add_row("Context", self.context.create_renderable())

    if hasattr(self, "python_class"):
        table.add_row("Python class", self.python_class.create_renderable())  # type: ignore

    return table

TypeInfo

Bases: ItemInfo, Generic[INFO_BASE_CLASS]

Source code in kiara/interfaces/python_api/models/info.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
class TypeInfo(ItemInfo, Generic[INFO_BASE_CLASS]):
    @classmethod
    def create_from_instance(cls, kiara: "Kiara", instance: INFO_BASE_CLASS, **kwargs):

        return cls.create_from_type_class(type_cls=instance, kiara=kiara)

    @classmethod
    @abc.abstractmethod
    def create_from_type_class(
        self, type_cls: INFO_BASE_CLASS, kiara: "Kiara"
    ) -> "ItemInfo":
        pass

    @classmethod
    def base_instance_class(self) -> INFO_BASE_CLASS:
        return type  # type: ignore

    python_class: PythonClass = Field(
        description="The python class that implements this module type."
    )

Attributes

python_class: PythonClass = Field(description='The python class that implements this module type.') class-attribute

Functions

create_from_instance(kiara: Kiara, instance: INFO_BASE_CLASS, **kwargs) classmethod
Source code in kiara/interfaces/python_api/models/info.py
223
224
225
226
@classmethod
def create_from_instance(cls, kiara: "Kiara", instance: INFO_BASE_CLASS, **kwargs):

    return cls.create_from_type_class(type_cls=instance, kiara=kiara)
create_from_type_class(type_cls: INFO_BASE_CLASS, kiara: Kiara) -> ItemInfo abstractmethod classmethod
Source code in kiara/interfaces/python_api/models/info.py
228
229
230
231
232
233
@classmethod
@abc.abstractmethod
def create_from_type_class(
    self, type_cls: INFO_BASE_CLASS, kiara: "Kiara"
) -> "ItemInfo":
    pass
base_instance_class() -> INFO_BASE_CLASS classmethod
Source code in kiara/interfaces/python_api/models/info.py
235
236
237
@classmethod
def base_instance_class(self) -> INFO_BASE_CLASS:
    return type  # type: ignore

InfoItemGroup

Bases: KiaraModel, Generic[INFO_ITEM_TYPE]

Source code in kiara/interfaces/python_api/models/info.py
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
class InfoItemGroup(KiaraModel, Generic[INFO_ITEM_TYPE]):
    @classmethod
    @abc.abstractmethod
    def base_info_class(cls) -> Type[INFO_ITEM_TYPE]:
        pass

    @classmethod
    def create_from_instances(
        cls,
        kiara: "Kiara",
        instances: Mapping[str, INFO_BASE_INSTANCE_TYPE],
        **kwargs: Any,
    ) -> "InfoItemGroup[INFO_ITEM_TYPE]":

        info_cls = cls.base_info_class()
        items = {}
        for k in sorted(instances.keys()):
            v = instances[k]
            items[k] = info_cls.create_from_instance(kiara=kiara, instance=v, **kwargs)

        group_title = kwargs.pop("group_title", None)
        result = cls(group_title=group_title, item_infos=items)
        result._kiara = kiara
        return result

    group_title: Union[str, None] = Field(description="The group alias.", default=None)
    item_infos: Mapping[str, INFO_ITEM_TYPE] = Field(description="The info items.")
    _kiara: Union["Kiara", None] = PrivateAttr(default=None)

    def _retrieve_subcomponent_keys(self) -> Iterable[str]:
        return self.item_infos.keys()

    def _retrieve_data_to_hash(self) -> Any:
        return {"type_name": self.__class__._kiara_model_name, "included_types": list(self.item_infos.keys())}  # type: ignore

    def create_renderable(self, **config: Any) -> RenderableType:

        full_doc = config.get("full_doc", False)

        table = Table(show_header=True, box=box.SIMPLE, show_lines=full_doc)
        table.add_column("Name", style="i")
        table.add_column("Description")

        for type_name in sorted(self.item_infos.keys()):
            t_md = self.item_infos[type_name]
            if full_doc:
                md = Markdown(t_md.documentation.full_doc)
            else:
                md = Markdown(t_md.documentation.description)
            table.add_row(type_name, md)

        return table

    def __getitem__(self, item: str) -> INFO_ITEM_TYPE:

        return self.item_infos[item]

    # def __iter__(self):
    #     return self.item_infos.__iter__()

    def __len__(self):
        return len(self.item_infos)

Attributes

group_title: Union[str, None] = Field(description='The group alias.', default=None) class-attribute
item_infos: Mapping[str, INFO_ITEM_TYPE] = Field(description='The info items.') class-attribute

Functions

base_info_class() -> Type[INFO_ITEM_TYPE] abstractmethod classmethod
Source code in kiara/interfaces/python_api/models/info.py
248
249
250
251
@classmethod
@abc.abstractmethod
def base_info_class(cls) -> Type[INFO_ITEM_TYPE]:
    pass
create_from_instances(kiara: Kiara, instances: Mapping[str, INFO_BASE_INSTANCE_TYPE], **kwargs: Any) -> InfoItemGroup[INFO_ITEM_TYPE] classmethod
Source code in kiara/interfaces/python_api/models/info.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@classmethod
def create_from_instances(
    cls,
    kiara: "Kiara",
    instances: Mapping[str, INFO_BASE_INSTANCE_TYPE],
    **kwargs: Any,
) -> "InfoItemGroup[INFO_ITEM_TYPE]":

    info_cls = cls.base_info_class()
    items = {}
    for k in sorted(instances.keys()):
        v = instances[k]
        items[k] = info_cls.create_from_instance(kiara=kiara, instance=v, **kwargs)

    group_title = kwargs.pop("group_title", None)
    result = cls(group_title=group_title, item_infos=items)
    result._kiara = kiara
    return result
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
def create_renderable(self, **config: Any) -> RenderableType:

    full_doc = config.get("full_doc", False)

    table = Table(show_header=True, box=box.SIMPLE, show_lines=full_doc)
    table.add_column("Name", style="i")
    table.add_column("Description")

    for type_name in sorted(self.item_infos.keys()):
        t_md = self.item_infos[type_name]
        if full_doc:
            md = Markdown(t_md.documentation.full_doc)
        else:
            md = Markdown(t_md.documentation.description)
        table.add_row(type_name, md)

    return table

TypeInfoItemGroup

Bases: InfoItemGroup[TypeInfo]

Source code in kiara/interfaces/python_api/models/info.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
class TypeInfoItemGroup(InfoItemGroup[TypeInfo]):
    @classmethod
    @abc.abstractmethod
    def base_info_class(cls) -> Type[TypeInfo]:
        pass

    @classmethod
    def create_from_type_items(
        cls, kiara: "Kiara", group_title: Union[str, None] = None, **items: Type
    ) -> "TypeInfoItemGroup":

        type_infos = {
            k: cls.base_info_class().create_from_type_class(type_cls=v, kiara=kiara)
            for k, v in items.items()
        }
        data_types_info = cls.construct(group_alias=group_title, item_infos=type_infos)  # type: ignore
        return data_types_info

Functions

base_info_class() -> Type[TypeInfo] abstractmethod classmethod
Source code in kiara/interfaces/python_api/models/info.py
312
313
314
315
@classmethod
@abc.abstractmethod
def base_info_class(cls) -> Type[TypeInfo]:
    pass
create_from_type_items(kiara: Kiara, group_title: Union[str, None] = None, **items: Type) -> TypeInfoItemGroup classmethod
Source code in kiara/interfaces/python_api/models/info.py
317
318
319
320
321
322
323
324
325
326
327
@classmethod
def create_from_type_items(
    cls, kiara: "Kiara", group_title: Union[str, None] = None, **items: Type
) -> "TypeInfoItemGroup":

    type_infos = {
        k: cls.base_info_class().create_from_type_class(type_cls=v, kiara=kiara)
        for k, v in items.items()
    }
    data_types_info = cls.construct(group_alias=group_title, item_infos=type_infos)  # type: ignore
    return data_types_info

KiaraModelTypeInfo

Bases: TypeInfo[Type[KiaraModel]]

Source code in kiara/interfaces/python_api/models/info.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
class KiaraModelTypeInfo(TypeInfo[Type[KiaraModel]]):

    _kiara_model_id = "info.kiara_model"

    @classmethod
    def create_from_type_class(
        self, type_cls: Type[KiaraModel], kiara: "Kiara"
    ) -> "KiaraModelTypeInfo":

        authors_md = AuthorsMetadataModel.from_class(type_cls)
        doc = DocumentationMetadataModel.from_class_doc(type_cls)
        python_class = PythonClass.from_class(type_cls)
        properties_md = ContextMetadataModel.from_class(type_cls)
        type_name = type_cls._kiara_model_id  # type: ignore
        schema = type_cls.schema()

        return KiaraModelTypeInfo.construct(
            type_name=type_name,
            documentation=doc,
            authors=authors_md,
            context=properties_md,
            python_class=python_class,
            metadata_schema=schema,
        )

    metadata_schema: Dict[str, Any] = Field(
        description="The (json) schema for this model data."
    )

    def create_renderable(self, **config: Any) -> RenderableType:

        include_doc = config.get("include_doc", True)
        include_schema = config.get("include_schema", False)

        table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
        table.add_column("property", style="i")
        table.add_column("value")

        if include_doc:
            table.add_row(
                "Documentation",
                Panel(self.documentation.create_renderable(), box=box.SIMPLE),
            )
        table.add_row("Author(s)", self.authors.create_renderable())
        table.add_row("Context", self.context.create_renderable())

        if hasattr(self, "python_class"):
            table.add_row("Python class", self.python_class.create_renderable())

        if include_schema:
            schema = Syntax(
                orjson_dumps(self.metadata_schema, option=orjson.OPT_INDENT_2),
                "json",
                background_color="default",
            )
            table.add_row("metadata_schema", schema)

        return table

Attributes

metadata_schema: Dict[str, Any] = Field(description='The (json) schema for this model data.') class-attribute

Functions

create_from_type_class(type_cls: Type[KiaraModel], kiara: Kiara) -> KiaraModelTypeInfo classmethod
Source code in kiara/interfaces/python_api/models/info.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
@classmethod
def create_from_type_class(
    self, type_cls: Type[KiaraModel], kiara: "Kiara"
) -> "KiaraModelTypeInfo":

    authors_md = AuthorsMetadataModel.from_class(type_cls)
    doc = DocumentationMetadataModel.from_class_doc(type_cls)
    python_class = PythonClass.from_class(type_cls)
    properties_md = ContextMetadataModel.from_class(type_cls)
    type_name = type_cls._kiara_model_id  # type: ignore
    schema = type_cls.schema()

    return KiaraModelTypeInfo.construct(
        type_name=type_name,
        documentation=doc,
        authors=authors_md,
        context=properties_md,
        python_class=python_class,
        metadata_schema=schema,
    )
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
def create_renderable(self, **config: Any) -> RenderableType:

    include_doc = config.get("include_doc", True)
    include_schema = config.get("include_schema", False)

    table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
    table.add_column("property", style="i")
    table.add_column("value")

    if include_doc:
        table.add_row(
            "Documentation",
            Panel(self.documentation.create_renderable(), box=box.SIMPLE),
        )
    table.add_row("Author(s)", self.authors.create_renderable())
    table.add_row("Context", self.context.create_renderable())

    if hasattr(self, "python_class"):
        table.add_row("Python class", self.python_class.create_renderable())

    if include_schema:
        schema = Syntax(
            orjson_dumps(self.metadata_schema, option=orjson.OPT_INDENT_2),
            "json",
            background_color="default",
        )
        table.add_row("metadata_schema", schema)

    return table

KiaraModelClassesInfo

Bases: TypeInfoItemGroup

Source code in kiara/interfaces/python_api/models/info.py
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
class KiaraModelClassesInfo(TypeInfoItemGroup):

    _kiara_model_id = "info.kiara_models"

    @classmethod
    def find_kiara_models(
        cls, alias: Union[str, None] = None, only_for_package: Union[str, None] = None
    ) -> "KiaraModelClassesInfo":

        models = find_all_kiara_model_classes()

        # we don't need the kiara instance, this is just to satisfy mypy
        kiara: Kiara = None  # type: ignore
        group: KiaraModelClassesInfo = KiaraModelClassesInfo.create_from_type_items(kiara=kiara, group_title=alias, **models)  # type: ignore

        if only_for_package:
            temp = {}
            for key, info in group.item_infos.items():
                if info.context.labels.get("package") == only_for_package:
                    temp[key] = info

            group = KiaraModelClassesInfo.construct(
                group_id=group.instance_id, group_alias=group.group_alias, item_infos=temp  # type: ignore
            )

        return group

    @classmethod
    def base_info_class(cls) -> Type[KiaraModelTypeInfo]:
        return KiaraModelTypeInfo  # type: ignore

    type_name: Literal["kiara_model"] = "kiara_model"
    item_infos: Mapping[str, KiaraModelTypeInfo] = Field(  # type: ignore
        description="The value metadata info instances for each type."
    )

Attributes

type_name: Literal['kiara_model'] = 'kiara_model' class-attribute
item_infos: Mapping[str, KiaraModelTypeInfo] = Field(description='The value metadata info instances for each type.') class-attribute

Functions

find_kiara_models(alias: Union[str, None] = None, only_for_package: Union[str, None] = None) -> KiaraModelClassesInfo classmethod
Source code in kiara/interfaces/python_api/models/info.py
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
@classmethod
def find_kiara_models(
    cls, alias: Union[str, None] = None, only_for_package: Union[str, None] = None
) -> "KiaraModelClassesInfo":

    models = find_all_kiara_model_classes()

    # we don't need the kiara instance, this is just to satisfy mypy
    kiara: Kiara = None  # type: ignore
    group: KiaraModelClassesInfo = KiaraModelClassesInfo.create_from_type_items(kiara=kiara, group_title=alias, **models)  # type: ignore

    if only_for_package:
        temp = {}
        for key, info in group.item_infos.items():
            if info.context.labels.get("package") == only_for_package:
                temp[key] = info

        group = KiaraModelClassesInfo.construct(
            group_id=group.instance_id, group_alias=group.group_alias, item_infos=temp  # type: ignore
        )

    return group
base_info_class() -> Type[KiaraModelTypeInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
417
418
419
@classmethod
def base_info_class(cls) -> Type[KiaraModelTypeInfo]:
    return KiaraModelTypeInfo  # type: ignore

ValueInfo

Bases: ItemInfo[Value]

Source code in kiara/interfaces/python_api/models/info.py
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
class ValueInfo(ItemInfo[Value]):

    _kiara_model_id = "info.value"

    @classmethod
    def base_instance_class(cls) -> Type[Value]:
        return Value

    @classmethod
    def create_from_instance(cls, kiara: "Kiara", instance: Value, **kwargs: Any):

        resolve_aliases = kwargs.get("resolve_aliases", True)
        resolve_destinies = kwargs.get("resolve_destinies", True)
        resolve_properties = kwargs.get("resolve_properties", True)

        if resolve_aliases:
            aliases = sorted(
                kiara.alias_registry.find_aliases_for_value_id(instance.value_id)
            )
        else:
            aliases = None

        if instance.is_stored:
            persisted_details = kiara.data_registry.retrieve_persisted_value_details(
                value_id=instance.value_id
            )
        else:
            persisted_details = None

        if instance.data_type_name in kiara.type_registry.data_type_profiles:
            is_internal = "internal" in kiara.type_registry.get_type_lineage(
                instance.data_type_name
            )
        else:
            is_internal = False

        if resolve_destinies:
            destiny_links = kiara.data_registry.find_destinies_for_value(
                value_id=instance.value_id
            )
            filtered_destinies = {}
            for alias, value_id in destiny_links.items():
                if (
                    alias in instance.property_links.keys()
                    and value_id == instance.property_links[alias]
                ):
                    continue
                filtered_destinies[alias] = value_id
        else:
            filtered_destinies = None

        if resolve_properties:
            properties = instance.get_all_property_data()
        else:
            properties = None

        authors = AuthorsMetadataModel()
        context = ContextMetadataModel()
        doc = DocumentationMetadataModel()

        model = ValueInfo(
            type_name=str(instance.value_id),
            documentation=doc,
            authors=authors,
            context=context,
            value_id=instance.value_id,
            kiara_id=instance.kiara_id,
            value_schema=instance.value_schema,
            value_status=instance.value_status,
            environment_hashes=instance.environment_hashes,
            value_size=instance.value_size,
            value_hash=instance.value_hash,
            pedigree=instance.pedigree,
            pedigree_output_name=instance.pedigree_output_name,
            data_type_info=instance.data_type_info,
            # data_type_config=instance.data_type_config,
            # data_type_class=instance.data_type_class,
            property_links=instance.property_links,
            destiny_links=filtered_destinies,
            destiny_backlinks=instance.destiny_backlinks,
            aliases=aliases,
            serialized=persisted_details,
            properties=properties,
            is_internal=is_internal,
            is_persisted=instance._is_stored,
        )
        model._value = instance
        model._alias_registry = kiara.alias_registry  # type: ignore
        model._data_registry = instance._data_registry
        return model

    value_id: uuid.UUID = Field(description="The id of the value.")

    kiara_id: uuid.UUID = Field(
        description="The id of the kiara context this value belongs to."
    )

    value_schema: ValueSchema = Field(
        description="The schema that was used for this Value."
    )

    value_status: ValueStatus = Field(description="The set/unset status of this value.")
    value_size: int = Field(description="The size of this value, in bytes.")
    value_hash: str = Field(description="The hash of this value.")
    pedigree: ValuePedigree = Field(
        description="Information about the module and inputs that went into creating this value."
    )
    pedigree_output_name: str = Field(
        description="The output name that produced this value (using the manifest inside the pedigree)."
    )
    data_type_info: DataTypeInfo = Field(
        description="Information about the underlying data type and it's configuration."
    )
    aliases: Union[List[str], None] = Field(
        description="The aliases that are registered for this value."
    )
    serialized: Union[PersistedData, None] = Field(
        description="Details for the serialization process that was used for this value."
    )
    properties: Union[Mapping[str, Any], None] = Field(
        description="Property data for this value.", default=None
    )
    destiny_links: Union[Mapping[str, uuid.UUID], None] = Field(
        description="References to all the values that act as destiny for this value in this context."
    )
    environment_hashes: Mapping[str, Mapping[str, str]] = Field(
        description="Hashes for the environments this value was created in."
    )
    enviroments: Union[Mapping[str, Mapping[str, Any]], None] = Field(
        description="Information about the environments this value was created in.",
        default=None,
    )
    property_links: Mapping[str, uuid.UUID] = Field(
        description="Links to values that are properties of this value.",
        default_factory=dict,
    )
    destiny_backlinks: Mapping[uuid.UUID, str] = Field(
        description="Backlinks to values that this value acts as destiny/or property for.",
        default_factory=dict,
    )
    is_internal: bool = Field(
        description="Whether this value is only used internally in kiara.",
        default=False,
    )
    is_persisted: bool = Field(
        description="Whether this value is stored in at least one data store."
    )
    _alias_registry: "AliasRegistry" = PrivateAttr(default=None)
    _data_registry: "DataRegistry" = PrivateAttr(default=None)
    _value: Value = PrivateAttr(default=None)

    def _retrieve_id(self) -> str:
        return str(self.value_id)

    def _retrieve_data_to_hash(self) -> Any:
        return self.value_id.bytes

    @property
    def property_values(self) -> "ValueMap":
        return self._value.property_values

    @property
    def lineage(self) -> "ValueLineage":
        return self._value.lineage

    def resolve_aliases(self):
        if self.aliases is None:
            aliases = self._alias_registry.find_aliases_for_value_id(self.value_id)
            if aliases:
                aliases = sorted(aliases)
            self.aliases = aliases

    def resolve_destinies(self):
        if self.destiny_links is None:
            destiny_links = self._value._data_registry.find_destinies_for_value(
                value_id=self.value_id
            )
            filtered_destinies = {}
            for alias, value_id in destiny_links.items():
                if (
                    alias in self.property_links.keys()
                    and value_id == self.property_links[alias]
                ):
                    continue
                filtered_destinies[alias] = value_id
            self.destiny_links = filtered_destinies

    def create_info_data(self, **config: Any) -> Mapping[str, Any]:

        return self._value.create_info_data(**config)

    def create_renderable(self, **render_config: Any) -> RenderableType:

        return self._value.create_renderable(**render_config)

Attributes

value_id: uuid.UUID = Field(description='The id of the value.') class-attribute
kiara_id: uuid.UUID = Field(description='The id of the kiara context this value belongs to.') class-attribute
value_schema: ValueSchema = Field(description='The schema that was used for this Value.') class-attribute
value_status: ValueStatus = Field(description='The set/unset status of this value.') class-attribute
value_size: int = Field(description='The size of this value, in bytes.') class-attribute
value_hash: str = Field(description='The hash of this value.') class-attribute
pedigree: ValuePedigree = Field(description='Information about the module and inputs that went into creating this value.') class-attribute
pedigree_output_name: str = Field(description='The output name that produced this value (using the manifest inside the pedigree).') class-attribute
data_type_info: DataTypeInfo = Field(description="Information about the underlying data type and it's configuration.") class-attribute
aliases: Union[List[str], None] = Field(description='The aliases that are registered for this value.') class-attribute
serialized: Union[PersistedData, None] = Field(description='Details for the serialization process that was used for this value.') class-attribute
properties: Union[Mapping[str, Any], None] = Field(description='Property data for this value.', default=None) class-attribute
environment_hashes: Mapping[str, Mapping[str, str]] = Field(description='Hashes for the environments this value was created in.') class-attribute
enviroments: Union[Mapping[str, Mapping[str, Any]], None] = Field(description='Information about the environments this value was created in.', default=None) class-attribute
is_internal: bool = Field(description='Whether this value is only used internally in kiara.', default=False) class-attribute
is_persisted: bool = Field(description='Whether this value is stored in at least one data store.') class-attribute
property_values: ValueMap property
lineage: ValueLineage property

Functions

base_instance_class() -> Type[Value] classmethod
Source code in kiara/interfaces/python_api/models/info.py
431
432
433
@classmethod
def base_instance_class(cls) -> Type[Value]:
    return Value
create_from_instance(kiara: Kiara, instance: Value, **kwargs: Any) classmethod
Source code in kiara/interfaces/python_api/models/info.py
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
@classmethod
def create_from_instance(cls, kiara: "Kiara", instance: Value, **kwargs: Any):

    resolve_aliases = kwargs.get("resolve_aliases", True)
    resolve_destinies = kwargs.get("resolve_destinies", True)
    resolve_properties = kwargs.get("resolve_properties", True)

    if resolve_aliases:
        aliases = sorted(
            kiara.alias_registry.find_aliases_for_value_id(instance.value_id)
        )
    else:
        aliases = None

    if instance.is_stored:
        persisted_details = kiara.data_registry.retrieve_persisted_value_details(
            value_id=instance.value_id
        )
    else:
        persisted_details = None

    if instance.data_type_name in kiara.type_registry.data_type_profiles:
        is_internal = "internal" in kiara.type_registry.get_type_lineage(
            instance.data_type_name
        )
    else:
        is_internal = False

    if resolve_destinies:
        destiny_links = kiara.data_registry.find_destinies_for_value(
            value_id=instance.value_id
        )
        filtered_destinies = {}
        for alias, value_id in destiny_links.items():
            if (
                alias in instance.property_links.keys()
                and value_id == instance.property_links[alias]
            ):
                continue
            filtered_destinies[alias] = value_id
    else:
        filtered_destinies = None

    if resolve_properties:
        properties = instance.get_all_property_data()
    else:
        properties = None

    authors = AuthorsMetadataModel()
    context = ContextMetadataModel()
    doc = DocumentationMetadataModel()

    model = ValueInfo(
        type_name=str(instance.value_id),
        documentation=doc,
        authors=authors,
        context=context,
        value_id=instance.value_id,
        kiara_id=instance.kiara_id,
        value_schema=instance.value_schema,
        value_status=instance.value_status,
        environment_hashes=instance.environment_hashes,
        value_size=instance.value_size,
        value_hash=instance.value_hash,
        pedigree=instance.pedigree,
        pedigree_output_name=instance.pedigree_output_name,
        data_type_info=instance.data_type_info,
        # data_type_config=instance.data_type_config,
        # data_type_class=instance.data_type_class,
        property_links=instance.property_links,
        destiny_links=filtered_destinies,
        destiny_backlinks=instance.destiny_backlinks,
        aliases=aliases,
        serialized=persisted_details,
        properties=properties,
        is_internal=is_internal,
        is_persisted=instance._is_stored,
    )
    model._value = instance
    model._alias_registry = kiara.alias_registry  # type: ignore
    model._data_registry = instance._data_registry
    return model
resolve_aliases()
Source code in kiara/interfaces/python_api/models/info.py
592
593
594
595
596
597
def resolve_aliases(self):
    if self.aliases is None:
        aliases = self._alias_registry.find_aliases_for_value_id(self.value_id)
        if aliases:
            aliases = sorted(aliases)
        self.aliases = aliases
resolve_destinies()
Source code in kiara/interfaces/python_api/models/info.py
599
600
601
602
603
604
605
606
607
608
609
610
611
612
def resolve_destinies(self):
    if self.destiny_links is None:
        destiny_links = self._value._data_registry.find_destinies_for_value(
            value_id=self.value_id
        )
        filtered_destinies = {}
        for alias, value_id in destiny_links.items():
            if (
                alias in self.property_links.keys()
                and value_id == self.property_links[alias]
            ):
                continue
            filtered_destinies[alias] = value_id
        self.destiny_links = filtered_destinies
create_info_data(**config: Any) -> Mapping[str, Any]
Source code in kiara/interfaces/python_api/models/info.py
614
615
616
def create_info_data(self, **config: Any) -> Mapping[str, Any]:

    return self._value.create_info_data(**config)
create_renderable(**render_config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
618
619
620
def create_renderable(self, **render_config: Any) -> RenderableType:

    return self._value.create_renderable(**render_config)

ValuesInfo

Bases: InfoItemGroup[ValueInfo]

Source code in kiara/interfaces/python_api/models/info.py
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
class ValuesInfo(InfoItemGroup[ValueInfo]):
    @classmethod
    def base_info_class(cls) -> Type[ValueInfo]:
        return ValueInfo

    def create_render_map(
        self, render_type: str, default_render_func: Callable, **render_config
    ):

        list_by_alias = render_config.get("list_by_alias", True)
        show_internal = render_config.get("show_internal_values", False)

        render_fields = render_config.get("render_fields", None)
        if not render_fields:
            render_fields = [k for k, v in RENDER_FIELDS.items() if v["show_default"]]
            if list_by_alias:
                render_fields[0] = "aliases"
                render_fields[1] = "value_id"

        render_map: Dict[uuid.UUID, Dict[str, Any]] = {}

        lookup = {}
        value_info: ValueInfo
        for value_info in self.item_infos.values():  # type: ignore
            if not show_internal and value_info.is_internal:
                continue
            lookup[value_info.value_id] = value_info

            details = {}
            for property in render_fields:

                render_func = (
                    RENDER_FIELDS.get(property, {})
                    .get("render", {})
                    .get(render_type, None)
                )
                if render_func is None:
                    if hasattr(value_info, property):
                        attr = getattr(value_info, property)
                        rendered = default_render_func(attr)
                    else:
                        raise Exception(
                            f"Can't render property '{property}': no render function registered and not a property."
                        )
                else:
                    rendered = render_func(value_info)
                details[property] = rendered
            render_map[value_info.value_id] = details

        if not list_by_alias:
            return {str(k): v for k, v in render_map.items()}
        else:
            result: Dict[str, Dict[str, Any]] = {}
            for value_id, render_details in render_map.items():
                value_aliases = lookup[value_id].aliases
                if value_aliases:
                    for alias in value_aliases:
                        assert alias not in result.keys()
                        render_details = dict(render_details)
                        render_details["alias"] = alias
                        result[alias] = render_details
                else:
                    render_details["alias"] = ""
                    result[f"no_aliases_{value_id}"] = render_details
            return result

    def create_renderable(self, render_type: str = "terminal", **render_config: Any):

        render_map = self.create_render_map(
            render_type=render_type,
            default_render_func=extract_renderable,
            **render_config,
        )

        list_by_alias = render_config.get("list_by_alias", True)
        render_fields = render_config.get("render_fields", None)
        if not render_fields:
            render_fields = [k for k, v in RENDER_FIELDS.items() if v["show_default"]]
        if list_by_alias:
            render_fields.insert(0, "alias")
            render_fields.remove("aliases")

        table = Table(box=box.SIMPLE)
        for property in render_fields:
            if property == "aliases" and list_by_alias:
                table.add_column("alias")
            elif property == "size":
                table.add_column("size", justify="right")
            else:
                table.add_column(property)

        for item_id, details in render_map.items():
            row = []
            for field in render_fields:
                value = details[field]
                row.append(value)
            table.add_row(*row)

        return table

Functions

base_info_class() -> Type[ValueInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
624
625
626
@classmethod
def base_info_class(cls) -> Type[ValueInfo]:
    return ValueInfo
create_render_map(render_type: str, default_render_func: Callable, **render_config)
Source code in kiara/interfaces/python_api/models/info.py
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
def create_render_map(
    self, render_type: str, default_render_func: Callable, **render_config
):

    list_by_alias = render_config.get("list_by_alias", True)
    show_internal = render_config.get("show_internal_values", False)

    render_fields = render_config.get("render_fields", None)
    if not render_fields:
        render_fields = [k for k, v in RENDER_FIELDS.items() if v["show_default"]]
        if list_by_alias:
            render_fields[0] = "aliases"
            render_fields[1] = "value_id"

    render_map: Dict[uuid.UUID, Dict[str, Any]] = {}

    lookup = {}
    value_info: ValueInfo
    for value_info in self.item_infos.values():  # type: ignore
        if not show_internal and value_info.is_internal:
            continue
        lookup[value_info.value_id] = value_info

        details = {}
        for property in render_fields:

            render_func = (
                RENDER_FIELDS.get(property, {})
                .get("render", {})
                .get(render_type, None)
            )
            if render_func is None:
                if hasattr(value_info, property):
                    attr = getattr(value_info, property)
                    rendered = default_render_func(attr)
                else:
                    raise Exception(
                        f"Can't render property '{property}': no render function registered and not a property."
                    )
            else:
                rendered = render_func(value_info)
            details[property] = rendered
        render_map[value_info.value_id] = details

    if not list_by_alias:
        return {str(k): v for k, v in render_map.items()}
    else:
        result: Dict[str, Dict[str, Any]] = {}
        for value_id, render_details in render_map.items():
            value_aliases = lookup[value_id].aliases
            if value_aliases:
                for alias in value_aliases:
                    assert alias not in result.keys()
                    render_details = dict(render_details)
                    render_details["alias"] = alias
                    result[alias] = render_details
            else:
                render_details["alias"] = ""
                result[f"no_aliases_{value_id}"] = render_details
        return result
create_renderable(render_type: str = 'terminal', **render_config: Any)
Source code in kiara/interfaces/python_api/models/info.py
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
def create_renderable(self, render_type: str = "terminal", **render_config: Any):

    render_map = self.create_render_map(
        render_type=render_type,
        default_render_func=extract_renderable,
        **render_config,
    )

    list_by_alias = render_config.get("list_by_alias", True)
    render_fields = render_config.get("render_fields", None)
    if not render_fields:
        render_fields = [k for k, v in RENDER_FIELDS.items() if v["show_default"]]
    if list_by_alias:
        render_fields.insert(0, "alias")
        render_fields.remove("aliases")

    table = Table(box=box.SIMPLE)
    for property in render_fields:
        if property == "aliases" and list_by_alias:
            table.add_column("alias")
        elif property == "size":
            table.add_column("size", justify="right")
        else:
            table.add_column(property)

    for item_id, details in render_map.items():
        row = []
        for field in render_fields:
            value = details[field]
            row.append(value)
        table.add_row(*row)

    return table

KiaraModuleConfigMetadata

Bases: KiaraModel

Source code in kiara/interfaces/python_api/models/info.py
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
class KiaraModuleConfigMetadata(KiaraModel):

    _kiara_model_id = "metadata.module_config"

    @classmethod
    def from_config_class(
        cls,
        config_cls: Type[KiaraModuleConfig],
    ):

        flat_models = get_flat_models_from_model(config_cls)
        model_name_map = get_model_name_map(flat_models)
        m_schema, _, _ = model_process_schema(config_cls, model_name_map=model_name_map)
        fields = m_schema["properties"]

        config_values = {}
        for field_name, details in fields.items():

            type_str = "-- n/a --"
            if "type" in details.keys():
                type_str = details["type"]

            desc = details.get("description", DEFAULT_NO_DESC_VALUE)
            default = config_cls.__fields__[field_name].default
            if default is None:
                if callable(config_cls.__fields__[field_name].default_factory):
                    default = config_cls.__fields__[field_name].default_factory()  # type: ignore

            req = config_cls.__fields__[field_name].required

            config_values[field_name] = ValueTypeAndDescription(
                description=desc, type=type_str, value_default=default, required=req
            )

        python_cls = PythonClass.from_class(config_cls)
        return KiaraModuleConfigMetadata(
            python_class=python_cls, config_values=config_values
        )

    python_class: PythonClass = Field(description="The config model python class.")
    config_values: Dict[str, ValueTypeAndDescription] = Field(
        description="The available configuration values."
    )

    def _retrieve_id(self) -> str:
        return self.python_class.full_name

    def _retrieve_data_to_hash(self) -> Any:
        return self.python_class.full_name

Attributes

python_class: PythonClass = Field(description='The config model python class.') class-attribute
config_values: Dict[str, ValueTypeAndDescription] = Field(description='The available configuration values.') class-attribute

Functions

from_config_class(config_cls: Type[KiaraModuleConfig]) classmethod
Source code in kiara/interfaces/python_api/models/info.py
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
@classmethod
def from_config_class(
    cls,
    config_cls: Type[KiaraModuleConfig],
):

    flat_models = get_flat_models_from_model(config_cls)
    model_name_map = get_model_name_map(flat_models)
    m_schema, _, _ = model_process_schema(config_cls, model_name_map=model_name_map)
    fields = m_schema["properties"]

    config_values = {}
    for field_name, details in fields.items():

        type_str = "-- n/a --"
        if "type" in details.keys():
            type_str = details["type"]

        desc = details.get("description", DEFAULT_NO_DESC_VALUE)
        default = config_cls.__fields__[field_name].default
        if default is None:
            if callable(config_cls.__fields__[field_name].default_factory):
                default = config_cls.__fields__[field_name].default_factory()  # type: ignore

        req = config_cls.__fields__[field_name].required

        config_values[field_name] = ValueTypeAndDescription(
            description=desc, type=type_str, value_default=default, required=req
        )

    python_cls = PythonClass.from_class(config_cls)
    return KiaraModuleConfigMetadata(
        python_class=python_cls, config_values=config_values
    )

DataTypeClassInfo

Bases: TypeInfo[Type[DataType]]

Source code in kiara/interfaces/python_api/models/info.py
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
class DataTypeClassInfo(TypeInfo[Type["DataType"]]):

    _kiara_model_id = "info.data_type"

    @classmethod
    def create_from_type_class(
        self, type_cls: Type["DataType"], kiara: Union["Kiara", None] = None
    ) -> "DataTypeClassInfo":

        authors = AuthorsMetadataModel.from_class(type_cls)
        doc = DocumentationMetadataModel.from_class_doc(type_cls)
        properties_md = ContextMetadataModel.from_class(type_cls)

        if kiara is not None:
            qual_profiles = kiara.type_registry.get_associated_profiles(type_cls._data_type_name)  # type: ignore
            lineage = kiara.type_registry.get_type_lineage(type_cls._data_type_name)  # type: ignore
        else:
            qual_profiles = None
            lineage = None

        try:
            result = DataTypeClassInfo.construct(
                type_name=type_cls._data_type_name,  # type: ignore
                python_class=PythonClass.from_class(type_cls),
                value_cls=PythonClass.from_class(type_cls.python_class()),
                data_type_config_cls=PythonClass.from_class(
                    type_cls.data_type_config_class()
                ),
                lineage=lineage,  # type: ignore
                qualifier_profiles=qual_profiles,
                documentation=doc,
                authors=authors,
                context=properties_md,
            )
        except Exception as e:
            if isinstance(
                e, TypeError
            ) and "missing 1 required positional argument: 'cls'" in str(e):
                raise Exception(
                    f"Invalid implementation of TypeValue subclass '{type_cls.__name__}': 'python_class' method must be marked as a '@classmethod'. This is a bug."
                )
            raise e

        result._kiara = kiara
        return result

    @classmethod
    def base_class(self) -> Type["DataType"]:
        from kiara.data_types import DataType

        return DataType

    @classmethod
    def category_name(cls) -> str:
        return "data_type"

    value_cls: PythonClass = Field(description="The python class of the value itself.")
    data_type_config_cls: PythonClass = Field(
        description="The python class holding the schema for configuring this type."
    )
    lineage: Union[List[str], None] = Field(description="This types lineage.")
    qualifier_profiles: Union[Mapping[str, Mapping[str, Any]], None] = Field(
        description="A map of qualifier profiles for this data types."
    )
    _kiara: Union["Kiara", None] = PrivateAttr(default=None)

    def _retrieve_id(self) -> str:
        return self.type_name

    def _retrieve_data_to_hash(self) -> Any:
        return self.type_name

    def create_renderable(self, **config: Any) -> RenderableType:

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

        table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
        table.add_column("property", style="i")
        table.add_column("value")

        if self.lineage:
            table.add_row("lineage", "\n".join(self.lineage[0:]))
        else:
            table.add_row("lineage", "-- n/a --")

        if self.qualifier_profiles:
            qual_table = Table(show_header=False, box=box.SIMPLE)
            qual_table.add_column("name")
            qual_table.add_column("config")
            for name, details in self.qualifier_profiles.items():
                json_details = orjson_dumps(details, option=orjson.OPT_INDENT_2)
                qual_table.add_row(
                    name, Syntax(json_details, "json", background_color="default")
                )
            table.add_row("qualifier profile(s)", qual_table)
        else:
            table.add_row("qualifier profile(s)", "-- n/a --")

        if include_doc:
            table.add_row(
                "Documentation",
                Panel(self.documentation.create_renderable(), box=box.SIMPLE),
            )

        table.add_row("Author(s)", self.authors.create_renderable())
        table.add_row("Context", self.context.create_renderable())

        table.add_row("Python class", self.python_class.create_renderable())
        table.add_row("Config class", self.data_type_config_cls.create_renderable())
        table.add_row("Value class", self.value_cls.create_renderable())

        return table

Attributes

value_cls: PythonClass = Field(description='The python class of the value itself.') class-attribute
data_type_config_cls: PythonClass = Field(description='The python class holding the schema for configuring this type.') class-attribute
lineage: Union[List[str], None] = Field(description='This types lineage.') class-attribute
qualifier_profiles: Union[Mapping[str, Mapping[str, Any]], None] = Field(description='A map of qualifier profiles for this data types.') class-attribute

Functions

create_from_type_class(type_cls: Type[DataType], kiara: Union[Kiara, None] = None) -> DataTypeClassInfo classmethod
Source code in kiara/interfaces/python_api/models/info.py
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
@classmethod
def create_from_type_class(
    self, type_cls: Type["DataType"], kiara: Union["Kiara", None] = None
) -> "DataTypeClassInfo":

    authors = AuthorsMetadataModel.from_class(type_cls)
    doc = DocumentationMetadataModel.from_class_doc(type_cls)
    properties_md = ContextMetadataModel.from_class(type_cls)

    if kiara is not None:
        qual_profiles = kiara.type_registry.get_associated_profiles(type_cls._data_type_name)  # type: ignore
        lineage = kiara.type_registry.get_type_lineage(type_cls._data_type_name)  # type: ignore
    else:
        qual_profiles = None
        lineage = None

    try:
        result = DataTypeClassInfo.construct(
            type_name=type_cls._data_type_name,  # type: ignore
            python_class=PythonClass.from_class(type_cls),
            value_cls=PythonClass.from_class(type_cls.python_class()),
            data_type_config_cls=PythonClass.from_class(
                type_cls.data_type_config_class()
            ),
            lineage=lineage,  # type: ignore
            qualifier_profiles=qual_profiles,
            documentation=doc,
            authors=authors,
            context=properties_md,
        )
    except Exception as e:
        if isinstance(
            e, TypeError
        ) and "missing 1 required positional argument: 'cls'" in str(e):
            raise Exception(
                f"Invalid implementation of TypeValue subclass '{type_cls.__name__}': 'python_class' method must be marked as a '@classmethod'. This is a bug."
            )
        raise e

    result._kiara = kiara
    return result
base_class() -> Type[DataType] classmethod
Source code in kiara/interfaces/python_api/models/info.py
821
822
823
824
825
@classmethod
def base_class(self) -> Type["DataType"]:
    from kiara.data_types import DataType

    return DataType
category_name() -> str classmethod
Source code in kiara/interfaces/python_api/models/info.py
827
828
829
@classmethod
def category_name(cls) -> str:
    return "data_type"
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
def create_renderable(self, **config: Any) -> RenderableType:

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

    table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
    table.add_column("property", style="i")
    table.add_column("value")

    if self.lineage:
        table.add_row("lineage", "\n".join(self.lineage[0:]))
    else:
        table.add_row("lineage", "-- n/a --")

    if self.qualifier_profiles:
        qual_table = Table(show_header=False, box=box.SIMPLE)
        qual_table.add_column("name")
        qual_table.add_column("config")
        for name, details in self.qualifier_profiles.items():
            json_details = orjson_dumps(details, option=orjson.OPT_INDENT_2)
            qual_table.add_row(
                name, Syntax(json_details, "json", background_color="default")
            )
        table.add_row("qualifier profile(s)", qual_table)
    else:
        table.add_row("qualifier profile(s)", "-- n/a --")

    if include_doc:
        table.add_row(
            "Documentation",
            Panel(self.documentation.create_renderable(), box=box.SIMPLE),
        )

    table.add_row("Author(s)", self.authors.create_renderable())
    table.add_row("Context", self.context.create_renderable())

    table.add_row("Python class", self.python_class.create_renderable())
    table.add_row("Config class", self.data_type_config_cls.create_renderable())
    table.add_row("Value class", self.value_cls.create_renderable())

    return table

DataTypeClassesInfo

Bases: TypeInfoItemGroup

Source code in kiara/interfaces/python_api/models/info.py
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
class DataTypeClassesInfo(TypeInfoItemGroup):

    _kiara_model_id = "info.data_types"

    # @classmethod
    # def create_from_type_items(
    #     cls,
    #     group_title: Union[str, None] = None,
    #     **items: Type,
    # ) -> "TypeInfoModelGroup":
    #
    #     type_infos = {
    #         k: cls.base_info_class().create_from_type_class(v) for k, v in items.items()  # type: ignore
    #     }
    #     data_types_info = cls.construct(group_alias=group_title, item_infos=type_infos)  # type: ignore
    #     return data_types_info
    #
    # @classmethod
    # def create_augmented_from_type_items(
    #     cls,
    #     kiara: Union["Kiara", None] = None,
    #     group_alias: Union[str, None] = None,
    #     **items: Type,
    # ) -> "TypeInfoModelGroup":
    #
    #     type_infos = {
    #         k: cls.base_info_class().create_from_type_class(v, kiara=kiara) for k, v in items.items()  # type: ignore
    #     }
    #     data_types_info = cls.construct(group_alias=group_alias, item_infos=type_infos)  # type: ignore
    #     data_types_info._kiara = kiara
    #     return data_types_info

    @classmethod
    def base_info_class(cls) -> Type[DataTypeClassInfo]:
        return DataTypeClassInfo

    type_name: Literal["data_type"] = "data_type"
    item_infos: Mapping[str, DataTypeClassInfo] = Field(  # type: ignore
        description="The data_type info instances for each type."
    )
    # _kiara: Union["Kiara", None] = PrivateAttr(default=None)

    def create_renderable(self, **config: Any) -> RenderableType:

        full_doc = config.get("full_doc", False)
        show_subtypes_inline = config.get("show_qualifier_profiles_inline", True)
        show_lineage = config.get("show_type_lineage", True)

        show_lines = full_doc or show_subtypes_inline or show_lineage

        table = Table(show_header=True, box=box.SIMPLE, show_lines=show_lines)
        table.add_column("type name", style="i")

        if show_lineage:
            table.add_column("type lineage")

        if show_subtypes_inline:
            table.add_column("(qualifier) profiles")

        if full_doc:
            table.add_column("documentation")
        else:
            table.add_column("description")

        all_types = self.item_infos.keys()

        for type_name in sorted(all_types):  # type: ignore

            t_md = self.item_infos[type_name]  # type: ignore
            row: List[Any] = [type_name]

            if show_lineage:
                if self._kiara is None:
                    lineage_str = "-- n/a --"
                else:
                    lineage = list(
                        self._kiara.type_registry.get_type_lineage(type_name)
                    )
                    lineage_str = ", ".join(reversed(lineage[1:]))
                row.append(lineage_str)
            if show_subtypes_inline:
                if self._kiara is None:
                    qual_profiles = "-- n/a --"
                else:
                    qual_p = self._kiara.type_registry.get_associated_profiles(
                        data_type_name=type_name
                    ).keys()
                    if qual_p:
                        qual_profiles = "\n".join(qual_p)
                    else:
                        qual_profiles = "-- n/a --"
                row.append(qual_profiles)

            if full_doc:
                md = Markdown(t_md.documentation.full_doc)
            else:
                md = Markdown(t_md.documentation.description)
            row.append(md)
            table.add_row(*row)

        return table

Attributes

type_name: Literal['data_type'] = 'data_type' class-attribute
item_infos: Mapping[str, DataTypeClassInfo] = Field(description='The data_type info instances for each type.') class-attribute

Functions

base_info_class() -> Type[DataTypeClassInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
921
922
923
@classmethod
def base_info_class(cls) -> Type[DataTypeClassInfo]:
    return DataTypeClassInfo
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
def create_renderable(self, **config: Any) -> RenderableType:

    full_doc = config.get("full_doc", False)
    show_subtypes_inline = config.get("show_qualifier_profiles_inline", True)
    show_lineage = config.get("show_type_lineage", True)

    show_lines = full_doc or show_subtypes_inline or show_lineage

    table = Table(show_header=True, box=box.SIMPLE, show_lines=show_lines)
    table.add_column("type name", style="i")

    if show_lineage:
        table.add_column("type lineage")

    if show_subtypes_inline:
        table.add_column("(qualifier) profiles")

    if full_doc:
        table.add_column("documentation")
    else:
        table.add_column("description")

    all_types = self.item_infos.keys()

    for type_name in sorted(all_types):  # type: ignore

        t_md = self.item_infos[type_name]  # type: ignore
        row: List[Any] = [type_name]

        if show_lineage:
            if self._kiara is None:
                lineage_str = "-- n/a --"
            else:
                lineage = list(
                    self._kiara.type_registry.get_type_lineage(type_name)
                )
                lineage_str = ", ".join(reversed(lineage[1:]))
            row.append(lineage_str)
        if show_subtypes_inline:
            if self._kiara is None:
                qual_profiles = "-- n/a --"
            else:
                qual_p = self._kiara.type_registry.get_associated_profiles(
                    data_type_name=type_name
                ).keys()
                if qual_p:
                    qual_profiles = "\n".join(qual_p)
                else:
                    qual_profiles = "-- n/a --"
            row.append(qual_profiles)

        if full_doc:
            md = Markdown(t_md.documentation.full_doc)
        else:
            md = Markdown(t_md.documentation.description)
        row.append(md)
        table.add_row(*row)

    return table

ModuleTypeInfo

Bases: TypeInfo[Type[KiaraModule]]

Source code in kiara/interfaces/python_api/models/info.py
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
class ModuleTypeInfo(TypeInfo[Type["KiaraModule"]]):

    _kiara_model_id = "info.kiara_module_type"

    @classmethod
    def create_from_type_class(cls, type_cls: Type["KiaraModule"], kiara: "Kiara") -> "ModuleTypeInfo":  # type: ignore

        module_attrs = cls.extract_module_attributes(module_cls=type_cls)
        return cls.construct(**module_attrs)

    @classmethod
    def base_class(self) -> Type["KiaraModule"]:

        from kiara.modules import KiaraModule

        return KiaraModule

    @classmethod
    def category_name(cls) -> str:
        return "module"

    @classmethod
    def extract_module_attributes(
        self, module_cls: Type["KiaraModule"]
    ) -> Dict[str, Any]:

        if not hasattr(module_cls, "process"):
            raise Exception(f"Module class '{module_cls}' misses 'process' method.")

        module_src = textwrap.dedent(inspect.getsource(module_cls))  # type: ignore

        authors_md = AuthorsMetadataModel.from_class(module_cls)
        doc = DocumentationMetadataModel.from_class_doc(module_cls)
        python_class = PythonClass.from_class(module_cls)
        properties_md = ContextMetadataModel.from_class(module_cls)
        config = KiaraModuleConfigMetadata.from_config_class(module_cls._config_cls)

        return {
            "type_name": module_cls._module_type_name,  # type: ignore
            "documentation": doc,
            "authors": authors_md,
            "context": properties_md,
            "python_class": python_class,
            "config": config,
            "module_src": module_src,
        }

    module_src: str = Field(
        description="The source code of the process method of the module."
    )

    def create_renderable(self, **config: Any) -> RenderableType:

        include_config_schema = config.get("include_config_schema", True)
        include_src = config.get("include_src", True)
        include_doc = config.get("include_doc", True)

        table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
        table.add_column("property", style="i")
        table.add_column("value")

        if include_doc:
            table.add_row(
                "Documentation",
                Panel(self.documentation.create_renderable(), box=box.SIMPLE),
            )
        table.add_row("Author(s)", self.authors.create_renderable())
        table.add_row("Context", self.context.create_renderable())

        if include_config_schema:
            config_cls = self.python_class.get_class()._config_cls  # type: ignore
            from kiara.utils.output import create_table_from_base_model_cls

            table.add_row(
                "Module config schema", create_table_from_base_model_cls(config_cls)
            )

        table.add_row("Python class", self.python_class.create_renderable())

        if include_src:
            from kiara.context.config import KIARA_SETTINGS

            _config = Syntax(
                self.module_src,
                "python",
                background_color=KIARA_SETTINGS.syntax_highlight_background,
            )
            table.add_row("Processing source code", Panel(_config, box=box.HORIZONTALS))

        return table

Attributes

module_src: str = Field(description='The source code of the process method of the module.') class-attribute

Functions

create_from_type_class(type_cls: Type[KiaraModule], kiara: Kiara) -> ModuleTypeInfo classmethod
Source code in kiara/interfaces/python_api/models/info.py
 996
 997
 998
 999
1000
@classmethod
def create_from_type_class(cls, type_cls: Type["KiaraModule"], kiara: "Kiara") -> "ModuleTypeInfo":  # type: ignore

    module_attrs = cls.extract_module_attributes(module_cls=type_cls)
    return cls.construct(**module_attrs)
base_class() -> Type[KiaraModule] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1002
1003
1004
1005
1006
1007
@classmethod
def base_class(self) -> Type["KiaraModule"]:

    from kiara.modules import KiaraModule

    return KiaraModule
category_name() -> str classmethod
Source code in kiara/interfaces/python_api/models/info.py
1009
1010
1011
@classmethod
def category_name(cls) -> str:
    return "module"
extract_module_attributes(module_cls: Type[KiaraModule]) -> Dict[str, Any] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
@classmethod
def extract_module_attributes(
    self, module_cls: Type["KiaraModule"]
) -> Dict[str, Any]:

    if not hasattr(module_cls, "process"):
        raise Exception(f"Module class '{module_cls}' misses 'process' method.")

    module_src = textwrap.dedent(inspect.getsource(module_cls))  # type: ignore

    authors_md = AuthorsMetadataModel.from_class(module_cls)
    doc = DocumentationMetadataModel.from_class_doc(module_cls)
    python_class = PythonClass.from_class(module_cls)
    properties_md = ContextMetadataModel.from_class(module_cls)
    config = KiaraModuleConfigMetadata.from_config_class(module_cls._config_cls)

    return {
        "type_name": module_cls._module_type_name,  # type: ignore
        "documentation": doc,
        "authors": authors_md,
        "context": properties_md,
        "python_class": python_class,
        "config": config,
        "module_src": module_src,
    }
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
def create_renderable(self, **config: Any) -> RenderableType:

    include_config_schema = config.get("include_config_schema", True)
    include_src = config.get("include_src", True)
    include_doc = config.get("include_doc", True)

    table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
    table.add_column("property", style="i")
    table.add_column("value")

    if include_doc:
        table.add_row(
            "Documentation",
            Panel(self.documentation.create_renderable(), box=box.SIMPLE),
        )
    table.add_row("Author(s)", self.authors.create_renderable())
    table.add_row("Context", self.context.create_renderable())

    if include_config_schema:
        config_cls = self.python_class.get_class()._config_cls  # type: ignore
        from kiara.utils.output import create_table_from_base_model_cls

        table.add_row(
            "Module config schema", create_table_from_base_model_cls(config_cls)
        )

    table.add_row("Python class", self.python_class.create_renderable())

    if include_src:
        from kiara.context.config import KIARA_SETTINGS

        _config = Syntax(
            self.module_src,
            "python",
            background_color=KIARA_SETTINGS.syntax_highlight_background,
        )
        table.add_row("Processing source code", Panel(_config, box=box.HORIZONTALS))

    return table

ModuleTypesInfo

Bases: TypeInfoItemGroup

Source code in kiara/interfaces/python_api/models/info.py
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
class ModuleTypesInfo(TypeInfoItemGroup):

    _kiara_model_id = "info.module_types"

    @classmethod
    def base_info_class(cls) -> Type[TypeInfo]:
        return ModuleTypeInfo

    type_name: Literal["module_type"] = "module_type"
    item_infos: Mapping[str, ModuleTypeInfo] = Field(  # type: ignore
        description="The module type info instances for each type."
    )

Attributes

type_name: Literal['module_type'] = 'module_type' class-attribute
item_infos: Mapping[str, ModuleTypeInfo] = Field(description='The module type info instances for each type.') class-attribute

Functions

base_info_class() -> Type[TypeInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1088
1089
1090
@classmethod
def base_info_class(cls) -> Type[TypeInfo]:
    return ModuleTypeInfo

OperationTypeInfo

Bases: TypeInfo[Type[OperationType]]

Source code in kiara/interfaces/python_api/models/info.py
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
class OperationTypeInfo(TypeInfo[Type["OperationType"]]):

    _kiara_model_id = "info.operation_type"

    @classmethod
    def create_from_type_class(  # type: ignore
        cls, kiara: "Kiara", type_cls: Type["OperationType"]  # type: ignore
    ) -> "OperationTypeInfo":

        authors_md = AuthorsMetadataModel.from_class(type_cls)
        doc = DocumentationMetadataModel.from_class_doc(type_cls)
        python_class = PythonClass.from_class(type_cls)
        properties_md = ContextMetadataModel.from_class(type_cls)

        return OperationTypeInfo.construct(
            type_name=type_cls._operation_type_name,  # type: ignore
            documentation=doc,
            authors=authors_md,
            context=properties_md,
            python_class=python_class,
        )

    @classmethod
    def base_class(self) -> Type["OperationType"]:
        from kiara.operations import OperationType

        return OperationType

    @classmethod
    def category_name(cls) -> str:
        return "operation_type"

    def _retrieve_id(self) -> str:
        return self.type_name

    def _retrieve_data_to_hash(self) -> Any:
        return self.type_name

Functions

create_from_type_class(kiara: Kiara, type_cls: Type[OperationType]) -> OperationTypeInfo classmethod
Source code in kiara/interfaces/python_api/models/info.py
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
@classmethod
def create_from_type_class(  # type: ignore
    cls, kiara: "Kiara", type_cls: Type["OperationType"]  # type: ignore
) -> "OperationTypeInfo":

    authors_md = AuthorsMetadataModel.from_class(type_cls)
    doc = DocumentationMetadataModel.from_class_doc(type_cls)
    python_class = PythonClass.from_class(type_cls)
    properties_md = ContextMetadataModel.from_class(type_cls)

    return OperationTypeInfo.construct(
        type_name=type_cls._operation_type_name,  # type: ignore
        documentation=doc,
        authors=authors_md,
        context=properties_md,
        python_class=python_class,
    )
base_class() -> Type[OperationType] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1120
1121
1122
1123
1124
@classmethod
def base_class(self) -> Type["OperationType"]:
    from kiara.operations import OperationType

    return OperationType
category_name() -> str classmethod
Source code in kiara/interfaces/python_api/models/info.py
1126
1127
1128
@classmethod
def category_name(cls) -> str:
    return "operation_type"

OperationTypeClassesInfo

Bases: TypeInfoItemGroup

Source code in kiara/interfaces/python_api/models/info.py
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
class OperationTypeClassesInfo(TypeInfoItemGroup):

    _kiara_model_id = "info.operation_types"

    @classmethod
    def base_info_class(cls) -> Type[OperationTypeInfo]:  # type: ignore
        return OperationTypeInfo

    type_name: Literal["operation_type"] = "operation_type"
    item_infos: Mapping[str, OperationTypeInfo] = Field(  # type: ignore
        description="The operation info instances for each type."
    )

Attributes

type_name: Literal['operation_type'] = 'operation_type' class-attribute
item_infos: Mapping[str, OperationTypeInfo] = Field(description='The operation info instances for each type.') class-attribute

Functions

base_info_class() -> Type[OperationTypeInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1141
1142
1143
@classmethod
def base_info_class(cls) -> Type[OperationTypeInfo]:  # type: ignore
    return OperationTypeInfo

FieldInfo

Bases: BaseModel

Source code in kiara/interfaces/python_api/models/info.py
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
class FieldInfo(BaseModel):

    field_name: str = Field(description="The field name.")
    field_schema: ValueSchema = Field(description="The schema of the field.")
    data_type_info: DataTypeInfo = Field(
        description="Information about the data type instance of the associated value."
    )
    value_required: bool = Field(
        description="Whether user input is required (meaning: 'optional' is False, and no default set)."
    )

Attributes

field_name: str = Field(description='The field name.') class-attribute
field_schema: ValueSchema = Field(description='The schema of the field.') class-attribute
data_type_info: DataTypeInfo = Field(description='Information about the data type instance of the associated value.') class-attribute
value_required: bool = Field(description="Whether user input is required (meaning: 'optional' is False, and no default set).") class-attribute

PipelineStructureInfo

Bases: ItemInfo

Source code in kiara/interfaces/python_api/models/info.py
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
class PipelineStructureInfo(ItemInfo):

    _kiara_model_id = "info.pipeline_structure"

    @classmethod
    def base_instance_class(cls) -> Type[PipelineStructure]:
        return PipelineStructure

    @classmethod
    def create_from_instance(
        cls, kiara: "Kiara", instance: PipelineStructure, **kwargs
    ):

        authors = AuthorsMetadataModel()
        context = ContextMetadataModel()

        execution_graph: Dict[str, Any] = {}
        data_flow_graph: Dict[str, Any] = {}
        data_flow_graph_simple: Dict[str, Any] = {}

        input_fields = {}
        for field_name, schema in instance.pipeline_inputs_schema.items():
            dt = kiara.type_registry.get_data_type_instance(
                type_name=schema.type, type_config=schema.type_config
            )
            dt_info = FieldInfo.construct(
                field_name=field_name,
                field_schema=schema,
                data_type_info=dt.info,
                value_required=schema.is_required(),
            )
            input_fields[field_name] = dt_info

        output_fields = {}
        for field_name, schema in instance.pipeline_outputs_schema.items():
            dt = kiara.type_registry.get_data_type_instance(
                type_name=schema.type, type_config=schema.type_config
            )
            dt_info = FieldInfo.construct(
                field_name=field_name,
                field_schema=schema,
                data_type_info=dt.info,
                value_required=schema.is_required(),
            )
            output_fields[field_name] = dt_info

        return cls(
            type_name=instance.instance_id,
            documentation=instance.pipeline_config.doc,
            authors=authors,
            context=context,
            pipeline_config=instance.pipeline_config,
            steps={step.step_id: step for step in instance.steps},
            step_details=instance.steps_details,
            input_aliases=instance.input_aliases,
            output_aliases=instance.output_aliases,
            constants=instance.constants,
            defaults=instance.defaults,
            pipeline_input_fields=input_fields,
            pipeline_output_fields=output_fields,
            pipeline_input_refs=instance.pipeline_input_refs,
            pipeline_output_refs=instance.pipeline_output_refs,
            execution_graph=execution_graph,
            data_flow_graph=data_flow_graph,
            data_flow_graph_simple=data_flow_graph_simple,
            processing_stages=instance.processing_stages,
            # processing_stages_info=instance.processing_stages_info,
        )

    pipeline_config: PipelineConfig = Field(
        description="The underlying pipeline config."
    )
    steps: Mapping[str, PipelineStep] = Field(
        description="All steps for this pipeline, indexed by their step_id."
    )
    step_details: Mapping[str, StepInfo] = Field(
        description="Additional information for each step."
    )
    input_aliases: Dict[str, str] = Field(description="The input aliases.")
    output_aliases: Dict[str, str] = Field(description="The output aliases.")
    constants: Mapping[str, Any] = Field(
        description="The input constants for this pipeline."
    )
    defaults: Mapping[str, Any] = Field(
        description="The default inputs for this pipeline."
    )

    pipeline_input_fields: Mapping[str, FieldInfo] = Field(
        description="The pipeline inputs schema."
    )
    pipeline_output_fields: Mapping[str, FieldInfo] = Field(
        description="The pipeline outputs schema."
    )

    pipeline_input_refs: Mapping[str, PipelineInputRef] = Field(
        description="References to the step inputs that are linked to pipeline inputs."
    )
    pipeline_output_refs: Mapping[str, PipelineOutputRef] = Field(
        description="References to the step outputs that are linked to pipeline outputs."
    )

    execution_graph: Dict[str, Any] = Field(
        description="Data describing the execution graph of this pipeline."
    )
    data_flow_graph: Dict[str, Any] = Field(
        description="Data describing the data flow of this pipeline."
    )
    data_flow_graph_simple: Dict[str, Any] = Field(
        description="Data describing the (simplified) data flow of this pipeline."
    )

    processing_stages: List[List[str]] = Field(
        description="A list of lists, containing all the step_ids per stage, in the order of execution."
    )
    # processing_stages_info: Mapping[int, PipelineStage] = Field(
    #     description="More detailed information about each step of this pipelines execution graph."
    # )

    def get_step(self, step_id) -> PipelineStep:
        return self.steps[step_id]

    def get_step_details(self, step_id: str) -> StepInfo:
        return self.step_details[step_id]

    def create_renderable(self, **config: Any) -> RenderableType:

        tree = Tree("pipeline")
        inputs = tree.add("inputs")
        for field_name, field_info in self.pipeline_input_fields.items():
            inputs.add(f"[i]{field_name}[i] (type: {field_info.field_schema.type})")

        steps = tree.add("steps")
        for idx, stage in enumerate(self.processing_stages, start=1):
            stage_node = steps.add(f"stage {idx}")
            for step_id in stage:
                step_node = stage_node.add(f"step: {step_id}")
                step = self.get_step(step_id=step_id)
                if step.doc.is_set:
                    step_node.add(f"desc: {step.doc.description}")
                step_node.add(f"module: {step.manifest_src.module_type}")

        outputs = tree.add("outputs")
        for field_name, field_info in self.pipeline_output_fields.items():
            outputs.add(f"[i]{field_name}[i] (type: {field_info.field_schema.type})")

        return tree

Attributes

pipeline_config: PipelineConfig = Field(description='The underlying pipeline config.') class-attribute
steps: Mapping[str, PipelineStep] = Field(description='All steps for this pipeline, indexed by their step_id.') class-attribute
step_details: Mapping[str, StepInfo] = Field(description='Additional information for each step.') class-attribute
input_aliases: Dict[str, str] = Field(description='The input aliases.') class-attribute
output_aliases: Dict[str, str] = Field(description='The output aliases.') class-attribute
constants: Mapping[str, Any] = Field(description='The input constants for this pipeline.') class-attribute
defaults: Mapping[str, Any] = Field(description='The default inputs for this pipeline.') class-attribute
pipeline_input_fields: Mapping[str, FieldInfo] = Field(description='The pipeline inputs schema.') class-attribute
pipeline_output_fields: Mapping[str, FieldInfo] = Field(description='The pipeline outputs schema.') class-attribute
pipeline_input_refs: Mapping[str, PipelineInputRef] = Field(description='References to the step inputs that are linked to pipeline inputs.') class-attribute
pipeline_output_refs: Mapping[str, PipelineOutputRef] = Field(description='References to the step outputs that are linked to pipeline outputs.') class-attribute
execution_graph: Dict[str, Any] = Field(description='Data describing the execution graph of this pipeline.') class-attribute
data_flow_graph: Dict[str, Any] = Field(description='Data describing the data flow of this pipeline.') class-attribute
data_flow_graph_simple: Dict[str, Any] = Field(description='Data describing the (simplified) data flow of this pipeline.') class-attribute
processing_stages: List[List[str]] = Field(description='A list of lists, containing all the step_ids per stage, in the order of execution.') class-attribute

Functions

base_instance_class() -> Type[PipelineStructure] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1167
1168
1169
@classmethod
def base_instance_class(cls) -> Type[PipelineStructure]:
    return PipelineStructure
create_from_instance(kiara: Kiara, instance: PipelineStructure, **kwargs) classmethod
Source code in kiara/interfaces/python_api/models/info.py
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
@classmethod
def create_from_instance(
    cls, kiara: "Kiara", instance: PipelineStructure, **kwargs
):

    authors = AuthorsMetadataModel()
    context = ContextMetadataModel()

    execution_graph: Dict[str, Any] = {}
    data_flow_graph: Dict[str, Any] = {}
    data_flow_graph_simple: Dict[str, Any] = {}

    input_fields = {}
    for field_name, schema in instance.pipeline_inputs_schema.items():
        dt = kiara.type_registry.get_data_type_instance(
            type_name=schema.type, type_config=schema.type_config
        )
        dt_info = FieldInfo.construct(
            field_name=field_name,
            field_schema=schema,
            data_type_info=dt.info,
            value_required=schema.is_required(),
        )
        input_fields[field_name] = dt_info

    output_fields = {}
    for field_name, schema in instance.pipeline_outputs_schema.items():
        dt = kiara.type_registry.get_data_type_instance(
            type_name=schema.type, type_config=schema.type_config
        )
        dt_info = FieldInfo.construct(
            field_name=field_name,
            field_schema=schema,
            data_type_info=dt.info,
            value_required=schema.is_required(),
        )
        output_fields[field_name] = dt_info

    return cls(
        type_name=instance.instance_id,
        documentation=instance.pipeline_config.doc,
        authors=authors,
        context=context,
        pipeline_config=instance.pipeline_config,
        steps={step.step_id: step for step in instance.steps},
        step_details=instance.steps_details,
        input_aliases=instance.input_aliases,
        output_aliases=instance.output_aliases,
        constants=instance.constants,
        defaults=instance.defaults,
        pipeline_input_fields=input_fields,
        pipeline_output_fields=output_fields,
        pipeline_input_refs=instance.pipeline_input_refs,
        pipeline_output_refs=instance.pipeline_output_refs,
        execution_graph=execution_graph,
        data_flow_graph=data_flow_graph,
        data_flow_graph_simple=data_flow_graph_simple,
        processing_stages=instance.processing_stages,
        # processing_stages_info=instance.processing_stages_info,
    )
get_step(step_id) -> PipelineStep
Source code in kiara/interfaces/python_api/models/info.py
1281
1282
def get_step(self, step_id) -> PipelineStep:
    return self.steps[step_id]
get_step_details(step_id: str) -> StepInfo
Source code in kiara/interfaces/python_api/models/info.py
1284
1285
def get_step_details(self, step_id: str) -> StepInfo:
    return self.step_details[step_id]
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
def create_renderable(self, **config: Any) -> RenderableType:

    tree = Tree("pipeline")
    inputs = tree.add("inputs")
    for field_name, field_info in self.pipeline_input_fields.items():
        inputs.add(f"[i]{field_name}[i] (type: {field_info.field_schema.type})")

    steps = tree.add("steps")
    for idx, stage in enumerate(self.processing_stages, start=1):
        stage_node = steps.add(f"stage {idx}")
        for step_id in stage:
            step_node = stage_node.add(f"step: {step_id}")
            step = self.get_step(step_id=step_id)
            if step.doc.is_set:
                step_node.add(f"desc: {step.doc.description}")
            step_node.add(f"module: {step.manifest_src.module_type}")

    outputs = tree.add("outputs")
    for field_name, field_info in self.pipeline_output_fields.items():
        outputs.add(f"[i]{field_name}[i] (type: {field_info.field_schema.type})")

    return tree

OperationInfo

Bases: ItemInfo

Source code in kiara/interfaces/python_api/models/info.py
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
class OperationInfo(ItemInfo):

    _kiara_model_id = "info.operation"

    @classmethod
    def base_instance_class(cls) -> Type[Operation]:
        return Operation

    @classmethod
    def create_from_instance(cls, kiara: "Kiara", instance: Operation, **kwargs):

        return cls.create_from_operation(kiara=kiara, operation=instance)

    @classmethod
    def create_from_operation(cls, kiara: "Kiara", operation: Operation):

        module = operation.module
        module_cls = module.__class__

        authors_md = AuthorsMetadataModel.from_class(module_cls)
        properties_md = ContextMetadataModel.from_class(module_cls)

        op_types = kiara.operation_registry.find_all_operation_types(
            operation_id=operation.operation_id
        )

        input_fields = {}
        for field_name, schema in operation.inputs_schema.items():
            dt = kiara.type_registry.get_data_type_instance(
                type_name=schema.type, type_config=schema.type_config
            )
            dt_info = FieldInfo.construct(
                field_name=field_name,
                field_schema=schema,
                data_type_info=dt.info,
                value_required=schema.is_required(),
            )
            input_fields[field_name] = dt_info

        output_fields = {}
        for field_name, schema in operation.outputs_schema.items():
            dt = kiara.type_registry.get_data_type_instance(
                type_name=schema.type, type_config=schema.type_config
            )
            dt_info = FieldInfo.construct(
                field_name=field_name,
                field_schema=schema,
                data_type_info=dt.info,
                value_required=schema.is_required(),
            )
            output_fields[field_name] = dt_info

        op_info = OperationInfo.construct(
            type_name=operation.operation_id,
            operation_types=list(op_types),
            input_fields=input_fields,
            output_fields=output_fields,
            operation=operation,
            documentation=operation.doc,
            authors=authors_md,
            context=properties_md,
        )

        return op_info

    @classmethod
    def category_name(cls) -> str:
        return "operation"

    operation: Operation = Field(description="The operation instance.")
    operation_types: List[str] = Field(
        description="The operation types this operation belongs to."
    )
    input_fields: Mapping[str, FieldInfo] = Field(
        description="The inputs schema for this operation."
    )
    output_fields: Mapping[str, FieldInfo] = Field(
        description="The outputs schema for this operation."
    )

    def create_renderable(self, **config: Any) -> RenderableType:

        include_doc = config.get("include_doc", False)
        include_op_details = config.get("include_op_details", True)

        table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
        table.add_column("property", style="i")
        table.add_column("value")

        if include_doc:
            table.add_row(
                "Documentation",
                Panel(self.documentation.create_renderable(), box=box.SIMPLE),
            )
        table.add_row("Author(s)", self.authors.create_renderable(**config))
        table.add_row("Context", self.context.create_renderable(**config))

        if include_op_details:
            table.add_row(
                "Operation details", self.operation.create_renderable(**config)
            )
        return table

Attributes

operation: Operation = Field(description='The operation instance.') class-attribute
operation_types: List[str] = Field(description='The operation types this operation belongs to.') class-attribute
input_fields: Mapping[str, FieldInfo] = Field(description='The inputs schema for this operation.') class-attribute
output_fields: Mapping[str, FieldInfo] = Field(description='The outputs schema for this operation.') class-attribute

Functions

base_instance_class() -> Type[Operation] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1315
1316
1317
@classmethod
def base_instance_class(cls) -> Type[Operation]:
    return Operation
create_from_instance(kiara: Kiara, instance: Operation, **kwargs) classmethod
Source code in kiara/interfaces/python_api/models/info.py
1319
1320
1321
1322
@classmethod
def create_from_instance(cls, kiara: "Kiara", instance: Operation, **kwargs):

    return cls.create_from_operation(kiara=kiara, operation=instance)
create_from_operation(kiara: Kiara, operation: Operation) classmethod
Source code in kiara/interfaces/python_api/models/info.py
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
@classmethod
def create_from_operation(cls, kiara: "Kiara", operation: Operation):

    module = operation.module
    module_cls = module.__class__

    authors_md = AuthorsMetadataModel.from_class(module_cls)
    properties_md = ContextMetadataModel.from_class(module_cls)

    op_types = kiara.operation_registry.find_all_operation_types(
        operation_id=operation.operation_id
    )

    input_fields = {}
    for field_name, schema in operation.inputs_schema.items():
        dt = kiara.type_registry.get_data_type_instance(
            type_name=schema.type, type_config=schema.type_config
        )
        dt_info = FieldInfo.construct(
            field_name=field_name,
            field_schema=schema,
            data_type_info=dt.info,
            value_required=schema.is_required(),
        )
        input_fields[field_name] = dt_info

    output_fields = {}
    for field_name, schema in operation.outputs_schema.items():
        dt = kiara.type_registry.get_data_type_instance(
            type_name=schema.type, type_config=schema.type_config
        )
        dt_info = FieldInfo.construct(
            field_name=field_name,
            field_schema=schema,
            data_type_info=dt.info,
            value_required=schema.is_required(),
        )
        output_fields[field_name] = dt_info

    op_info = OperationInfo.construct(
        type_name=operation.operation_id,
        operation_types=list(op_types),
        input_fields=input_fields,
        output_fields=output_fields,
        operation=operation,
        documentation=operation.doc,
        authors=authors_md,
        context=properties_md,
    )

    return op_info
category_name() -> str classmethod
Source code in kiara/interfaces/python_api/models/info.py
1376
1377
1378
@classmethod
def category_name(cls) -> str:
    return "operation"
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
def create_renderable(self, **config: Any) -> RenderableType:

    include_doc = config.get("include_doc", False)
    include_op_details = config.get("include_op_details", True)

    table = Table(box=box.SIMPLE, show_header=False, padding=(0, 0, 0, 0))
    table.add_column("property", style="i")
    table.add_column("value")

    if include_doc:
        table.add_row(
            "Documentation",
            Panel(self.documentation.create_renderable(), box=box.SIMPLE),
        )
    table.add_row("Author(s)", self.authors.create_renderable(**config))
    table.add_row("Context", self.context.create_renderable(**config))

    if include_op_details:
        table.add_row(
            "Operation details", self.operation.create_renderable(**config)
        )
    return table

OperationGroupInfo

Bases: InfoItemGroup

Source code in kiara/interfaces/python_api/models/info.py
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
class OperationGroupInfo(InfoItemGroup):

    _kiara_model_id = "info.operations"

    @classmethod
    def base_info_class(cls) -> Type[ItemInfo]:
        return OperationInfo

    @classmethod
    def create_from_operations(
        cls, kiara: "Kiara", group_title: Union[str, None] = None, **items: Operation
    ) -> "OperationGroupInfo":

        op_infos = {
            k: OperationInfo.create_from_operation(kiara=kiara, operation=v)
            for k, v in items.items()
        }

        op_group_info = cls.construct(group_title=group_title, item_infos=op_infos)
        return op_group_info

    # type_name: Literal["operation_type"] = "operation_type"
    item_infos: Mapping[str, OperationInfo] = Field(
        description="The operation info instances for each type."
    )

    def create_renderable(self, **config: Any) -> RenderableType:

        by_type = config.get("by_type", False)

        if by_type:
            return self._create_renderable_by_type(**config)
        else:
            return self._create_renderable_list(**config)

    def _create_renderable_list(self, **config):

        include_internal_operations = config.get("include_internal_operations", True)
        full_doc = config.get("full_doc", False)
        filter = config.get("filter", [])

        table = Table(box=box.SIMPLE, show_header=True)
        table.add_column("Id", no_wrap=True, style="i")
        table.add_column("Type(s)", style="green")
        table.add_column("Description")

        for op_id, op_info in self.item_infos.items():

            if (
                not include_internal_operations
                and op_info.operation.operation_details.is_internal_operation
            ):
                continue

            types = op_info.operation_types

            if "custom_module" in types:
                types.remove("custom_module")

            desc_str = op_info.documentation.description
            if full_doc:
                desc = Markdown(op_info.documentation.full_doc)
            else:
                desc = Markdown(op_info.documentation.description)

            if filter:
                match = True
                for f in filter:
                    if (
                        f.lower() not in op_id.lower()
                        and f.lower() not in desc_str.lower()
                    ):
                        match = False
                        break
                if match:
                    table.add_row(op_id, ", ".join(types), desc)

            else:
                table.add_row(op_id, ", ".join(types), desc)

        return table

    def _create_renderable_by_type(self, **config) -> Table:

        include_internal_operations = config.get("include_internal_operations", True)
        full_doc = config.get("full_doc", False)
        filter = config.get("filter", [])

        by_type: Dict[str, Dict[str, OperationInfo]] = {}
        for op_id, op in self.item_infos.items():
            if filter:
                match = True
                for f in filter:
                    if (
                        f.lower() not in op_id.lower()
                        and f.lower() not in op.documentation.description.lower()
                    ):
                        match = False
                        break
                if not match:
                    continue
            for op_type in op.operation_types:
                by_type.setdefault(op_type, {})[op_id] = op

        table = Table(box=box.SIMPLE, show_header=True)
        table.add_column("Type", no_wrap=True, style="b green")
        table.add_column("Id", no_wrap=True, style="i")
        if full_doc:
            table.add_column("Documentation", no_wrap=False, style="i")
        else:
            table.add_column("Description", no_wrap=False, style="i")

        for operation_name in sorted(by_type.keys()):

            # if operation_name == "custom_module":
            #     continue

            first_line_value = True
            op_infos = by_type[operation_name]

            for op_id in sorted(op_infos.keys()):
                op_info: OperationInfo = op_infos[op_id]

                if (
                    not include_internal_operations
                    and op_info.operation.operation_details.is_internal_operation
                ):
                    continue

                if full_doc:
                    desc = Markdown(op_info.documentation.full_doc)
                else:
                    desc = Markdown(op_info.documentation.description)

                row: List[RenderableType] = []
                if first_line_value:
                    row.append(operation_name)
                else:
                    row.append("")

                row.append(op_id)
                row.append(desc)

                table.add_row(*row)
                first_line_value = False

        return table

Attributes

item_infos: Mapping[str, OperationInfo] = Field(description='The operation info instances for each type.') class-attribute

Functions

base_info_class() -> Type[ItemInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1419
1420
1421
@classmethod
def base_info_class(cls) -> Type[ItemInfo]:
    return OperationInfo
create_from_operations(kiara: Kiara, group_title: Union[str, None] = None, **items: Operation) -> OperationGroupInfo classmethod
Source code in kiara/interfaces/python_api/models/info.py
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
@classmethod
def create_from_operations(
    cls, kiara: "Kiara", group_title: Union[str, None] = None, **items: Operation
) -> "OperationGroupInfo":

    op_infos = {
        k: OperationInfo.create_from_operation(kiara=kiara, operation=v)
        for k, v in items.items()
    }

    op_group_info = cls.construct(group_title=group_title, item_infos=op_infos)
    return op_group_info
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
1441
1442
1443
1444
1445
1446
1447
1448
def create_renderable(self, **config: Any) -> RenderableType:

    by_type = config.get("by_type", False)

    if by_type:
        return self._create_renderable_by_type(**config)
    else:
        return self._create_renderable_list(**config)

RendererInfo

Bases: ItemInfo[KiaraRenderer]

Source code in kiara/interfaces/python_api/models/info.py
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
class RendererInfo(ItemInfo[KiaraRenderer]):

    renderer_config: Mapping[str, Any] = Field(description="The renderer config.")
    renderer_cls: PythonClass = Field(
        description="The Python class that implements the renderer."
    )
    supported_inputs: List[str] = Field(
        description="Descriptions of the supported inputs."
    )
    supported_source_types: List[str] = Field(
        description="Descriptions of the supported source types."
    )
    supported_target_types: List[str] = Field(
        description="Descriptions of the supported target types."
    )
    supported_python_classes: List[PythonClass] = Field(
        description="A list of supported Python types that are acceptable as inputs."
    )

    @classmethod
    def base_instance_class(cls) -> Type[KiaraRenderer]:
        return KiaraRenderer

    @classmethod
    def create_from_instance(cls, kiara: "Kiara", instance: KiaraRenderer, **kwargs):

        doc = instance.doc
        authors = AuthorsMetadataModel.from_class(instance.__class__)
        properties_md = ContextMetadataModel.from_class(instance.__class__)

        renderer_name = instance._renderer_name  # type: ignore
        renderer_config = instance.renderer_config.dict()
        renderer_cls = PythonClass.from_class(item_cls=instance.__class__)
        supported_inputs = list(instance.supported_inputs_descs)
        supported_python_classes = [
            PythonClass.from_class(x)
            for x in instance.retrieve_supported_python_classes()
        ]

        supported_input_types = instance.retrieve_supported_render_sources()
        if isinstance(supported_input_types, str):
            supported_input_types = [supported_input_types]
        supported_target_types = instance.retrieve_supported_render_targets()
        if isinstance(supported_target_types, str):
            supported_target_types = [supported_target_types]

        return cls(
            type_name=renderer_name,
            documentation=doc,
            authors=authors,
            context=properties_md,
            renderer_config=renderer_config,
            renderer_cls=renderer_cls,
            supported_inputs=supported_inputs,
            supported_python_classes=supported_python_classes,
            supported_source_types=supported_input_types,
            supported_target_types=supported_target_types,
        )

    def create_renderable(self, **config: Any) -> RenderableType:

        show_metadata = config.get("show_metadata", False)

        table = Table(box=box.SIMPLE, show_header=False)
        table.add_column("key", style="i")
        table.add_column("value")

        table.add_row("Documentation", self.documentation.create_renderable(**config))
        inputs_md = ""
        for inp in self.supported_inputs:
            inputs_md += f"- {inp}\n"
        table.add_row("Supported inputs", Markdown(inputs_md))

        if show_metadata:
            table.add_row("Renderer name", self.type_name)
            if self.renderer_config:
                json = orjson_dumps(self.renderer_config, option=orjson.OPT_INDENT_2)
                table.add_row(
                    "Renderer config", Syntax(json, "json", background_color="default")
                )

            table.add_row(
                "Renderer class", self.renderer_cls.create_renderable(**config)
            )
            table.add_row("Author(s)", self.authors.create_renderable(**config))
            table.add_row("Context", self.context.create_renderable(**config))

        python_cls_md = ""
        for inp_cls in self.supported_python_classes:
            python_cls_md += f"- {inp_cls.full_name}\n"
        table.add_row(python_cls_md)

        return table

Attributes

renderer_config: Mapping[str, Any] = Field(description='The renderer config.') class-attribute
renderer_cls: PythonClass = Field(description='The Python class that implements the renderer.') class-attribute
supported_inputs: List[str] = Field(description='Descriptions of the supported inputs.') class-attribute
supported_source_types: List[str] = Field(description='Descriptions of the supported source types.') class-attribute
supported_target_types: List[str] = Field(description='Descriptions of the supported target types.') class-attribute
supported_python_classes: List[PythonClass] = Field(description='A list of supported Python types that are acceptable as inputs.') class-attribute

Functions

base_instance_class() -> Type[KiaraRenderer] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1583
1584
1585
@classmethod
def base_instance_class(cls) -> Type[KiaraRenderer]:
    return KiaraRenderer
create_from_instance(kiara: Kiara, instance: KiaraRenderer, **kwargs) classmethod
Source code in kiara/interfaces/python_api/models/info.py
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
@classmethod
def create_from_instance(cls, kiara: "Kiara", instance: KiaraRenderer, **kwargs):

    doc = instance.doc
    authors = AuthorsMetadataModel.from_class(instance.__class__)
    properties_md = ContextMetadataModel.from_class(instance.__class__)

    renderer_name = instance._renderer_name  # type: ignore
    renderer_config = instance.renderer_config.dict()
    renderer_cls = PythonClass.from_class(item_cls=instance.__class__)
    supported_inputs = list(instance.supported_inputs_descs)
    supported_python_classes = [
        PythonClass.from_class(x)
        for x in instance.retrieve_supported_python_classes()
    ]

    supported_input_types = instance.retrieve_supported_render_sources()
    if isinstance(supported_input_types, str):
        supported_input_types = [supported_input_types]
    supported_target_types = instance.retrieve_supported_render_targets()
    if isinstance(supported_target_types, str):
        supported_target_types = [supported_target_types]

    return cls(
        type_name=renderer_name,
        documentation=doc,
        authors=authors,
        context=properties_md,
        renderer_config=renderer_config,
        renderer_cls=renderer_cls,
        supported_inputs=supported_inputs,
        supported_python_classes=supported_python_classes,
        supported_source_types=supported_input_types,
        supported_target_types=supported_target_types,
    )
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
def create_renderable(self, **config: Any) -> RenderableType:

    show_metadata = config.get("show_metadata", False)

    table = Table(box=box.SIMPLE, show_header=False)
    table.add_column("key", style="i")
    table.add_column("value")

    table.add_row("Documentation", self.documentation.create_renderable(**config))
    inputs_md = ""
    for inp in self.supported_inputs:
        inputs_md += f"- {inp}\n"
    table.add_row("Supported inputs", Markdown(inputs_md))

    if show_metadata:
        table.add_row("Renderer name", self.type_name)
        if self.renderer_config:
            json = orjson_dumps(self.renderer_config, option=orjson.OPT_INDENT_2)
            table.add_row(
                "Renderer config", Syntax(json, "json", background_color="default")
            )

        table.add_row(
            "Renderer class", self.renderer_cls.create_renderable(**config)
        )
        table.add_row("Author(s)", self.authors.create_renderable(**config))
        table.add_row("Context", self.context.create_renderable(**config))

    python_cls_md = ""
    for inp_cls in self.supported_python_classes:
        python_cls_md += f"- {inp_cls.full_name}\n"
    table.add_row(python_cls_md)

    return table

RendererInfos

Bases: InfoItemGroup[RendererInfo]

Source code in kiara/interfaces/python_api/models/info.py
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
class RendererInfos(InfoItemGroup[RendererInfo]):
    @classmethod
    def base_info_class(cls) -> Type[RendererInfo]:
        return RendererInfo

    def create_renderable(self, **config: Any) -> RenderableType:

        table = Table(show_header=True, box=box.SIMPLE, show_lines=True)
        table.add_column("Source type(s)")
        table.add_column("Target type(s)")
        table.add_column("Description")

        rows: Dict[str, Dict[str, List[RenderableType]]] = {}
        info: RendererInfo
        for info in self.item_infos.values():  # type: ignore
            row: List[RenderableType] = []
            source_types = "\n".join(info.supported_source_types)
            target_types = "\n".join(info.supported_target_types)
            row.append(source_types)  # type: ignore
            row.append(target_types)  # type: ignore
            row.append(info.documentation.create_renderable(**config))

            rows.setdefault(source_types, {})[target_types] = row

        for source in sorted(rows.keys()):
            for target in sorted(rows[source].keys()):
                row = rows[source][target]
                table.add_row(*row)

        return table

Functions

base_info_class() -> Type[RendererInfo] classmethod
Source code in kiara/interfaces/python_api/models/info.py
1660
1661
1662
@classmethod
def base_info_class(cls) -> Type[RendererInfo]:
    return RendererInfo
create_renderable(**config: Any) -> RenderableType
Source code in kiara/interfaces/python_api/models/info.py
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
def create_renderable(self, **config: Any) -> RenderableType:

    table = Table(show_header=True, box=box.SIMPLE, show_lines=True)
    table.add_column("Source type(s)")
    table.add_column("Target type(s)")
    table.add_column("Description")

    rows: Dict[str, Dict[str, List[RenderableType]]] = {}
    info: RendererInfo
    for info in self.item_infos.values():  # type: ignore
        row: List[RenderableType] = []
        source_types = "\n".join(info.supported_source_types)
        target_types = "\n".join(info.supported_target_types)
        row.append(source_types)  # type: ignore
        row.append(target_types)  # type: ignore
        row.append(info.documentation.create_renderable(**config))

        rows.setdefault(source_types, {})[target_types] = row

    for source in sorted(rows.keys()):
        for target in sorted(rows[source].keys()):
            row = rows[source][target]
            table.add_row(*row)

    return table

Functions

pretty_print_value_data_terminal(value: ValueInfo)

Source code in kiara/interfaces/python_api/models/info.py
83
84
85
86
87
88
89
90
91
92
93
94
def pretty_print_value_data_terminal(value: "ValueInfo"):

    try:
        renderable = value._value._data_registry.pretty_print_data(
            value.value_id, target_type="terminal_renderable"
        )
    except Exception as e:
        log_exception(e)
        log_message("error.pretty_print", value=value.value_id, error=e)
        renderable = [str(value._value.data)]

    return renderable