Skip to content

data

Attributes

logger = structlog.getLogger() module-attribute

yaml = YAML(typ='safe') module-attribute

Classes

Functions

pretty_print_data(kiara: Kiara, value_id: uuid.UUID, target_type: uuid.UUID = 'terminal_renderable', **render_config: Any) -> Any

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/utils/data.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def pretty_print_data(
    kiara: "Kiara",
    value_id: uuid.UUID,
    target_type="terminal_renderable",
    **render_config: Any,
) -> Any:

    value = kiara.data_registry.get_value(value=value_id)

    op_type: PrettyPrintOperationType = kiara.operation_registry.get_operation_type("pretty_print")  # type: ignore

    data_type = value.data_type_name
    if data_type not in kiara.data_type_names:
        data_type = "any"

    try:
        op: Union[Operation, None] = op_type.get_operation_for_render_combination(
            source_type=data_type, target_type=target_type
        )
    except Exception as e:

        logger.debug(
            "error.pretty_print",
            source_type=data_type,
            target_type=target_type,
            error=e,
        )

        op = None
        if target_type == "terminal_renderable":
            try:
                op = op_type.get_operation_for_render_combination(
                    source_type="any", target_type="string"
                )
            except Exception:
                pass

    if op is None:
        raise Exception(
            f"Can't find operation to render '{value.value_schema.type}' as '{target_type}."
        )

    result = op.run(kiara=kiara, inputs={"value": value})
    rendered = result.get_value_data("rendered_value")
    return rendered

get_data_from_string(string_data: str, content_type: Union[str, None] = None) -> Any

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/utils/data.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def get_data_from_string(
    string_data: str, content_type: Union[str, None] = None
) -> Any:

    if content_type:
        assert content_type in ["json", "yaml"]

    if content_type == "json":
        data = orjson.loads(string_data.encode())
    elif content_type == "yaml":
        data = yaml.load(string_data)
    else:
        try:
            data = orjson.loads(string_data.encode())
        except Exception:
            try:
                data = yaml.load(string_data)
            except Exception:
                raise ValueError(
                    "Invalid data format, only 'json' or 'yaml' are supported currently."
                )

    return data