Skip to content

export_as

Attributes

logger = structlog.getLogger() module-attribute

Classes

ExportAsOperationDetails

Bases: BaseOperationDetails

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/operations/included_core_operations/export_as.py
24
25
26
27
28
class ExportAsOperationDetails(BaseOperationDetails):

    source_type: str = Field(description="The type of the value to be created.")
    target_profile: str = Field(description="The result profile type.")
    optional_args: Mapping[str, ValueSchema] = Field(description="Optional arguments.")

Attributes

source_type: str = Field(description='The type of the value to be created.') class-attribute instance-attribute
target_profile: str = Field(description='The result profile type.') class-attribute instance-attribute
optional_args: Mapping[str, ValueSchema] = Field(description='Optional arguments.') class-attribute instance-attribute

ExportAsOperationType

Bases: OperationType[ExportAsOperationDetails]

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/operations/included_core_operations/export_as.py
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
class ExportAsOperationType(OperationType[ExportAsOperationDetails]):

    _operation_type_name = "export_as"

    def _calculate_op_id(self, source_type: str, target_profile: str):

        if source_type == "any":
            operation_id = f"export.as.{target_profile}"
        else:
            operation_id = f"export.{source_type}.as.{target_profile}"

        return operation_id

    def retrieve_included_operation_configs(
        self,
    ) -> Iterable[Union[Mapping, OperationConfig]]:

        result = []
        for name, module_cls in self._kiara.module_type_classes.items():
            if not hasattr(module_cls, "retrieve_supported_export_combinations"):
                continue

            try:
                supported_combinations = module_cls.retrieve_supported_export_combinations()  # type: ignore
                for sup_comb in supported_combinations:
                    source_type = sup_comb["source_type"]
                    target_profile = sup_comb["target_profile"]
                    func = sup_comb["func"]

                    if source_type not in self._kiara.data_type_names:
                        logger.debug(
                            "ignore.operation_config",
                            module_type=name,
                            reason=f"Source type '{source_type}' not registered.",
                        )
                        continue

                    if not hasattr(module_cls, func):
                        logger.debug(
                            "ignore.operation_config",
                            module_type=name,
                            reason=f"Specified create function '{func}' not available.",
                        )
                        continue

                    mc = {"source_type": source_type, "target_profile": target_profile}
                    # TODO: check whether module config actually supports those, for now, only 'DataExportModule' subtypes are supported
                    _func = getattr(module_cls, func)
                    doc = DocumentationMetadataModel.from_function(_func)

                    oc = ManifestOperationConfig(
                        module_type=name, module_config=mc, doc=doc
                    )
                    result.append(oc)
            except Exception as e:
                log_exception(e)
                logger.debug(
                    "ignore.create_operation_instance", module_type=name, reason=e
                )
                continue

        return result

    def check_matching_operation(
        self, module: "KiaraModule"
    ) -> Union[ExportAsOperationDetails, None]:

        if not isinstance(module, DataExportModule):
            return None

        source_type = None
        for field_name, schema in module.inputs_schema.items():
            if field_name == schema.type:
                if source_type is not None:
                    logger.debug(
                        "ignore.operation",
                        operation_type="create_from",
                        reason=f"more than one possible target type field: {field_name}",
                    )
                    return None
                source_type = field_name

        if source_type is None:
            return None

        target_profile = module.config.target_profile

        op_id = self._calculate_op_id(
            source_type=source_type, target_profile=target_profile
        )

        optional = {}
        for field, schema in module.inputs_schema.items():
            if field in [source_type]:
                continue
            optional[field] = schema

        details = {
            "module_inputs_schema": module.inputs_schema,
            "module_outputs_schema": module.outputs_schema,
            "operation_id": op_id,
            "source_type": source_type,
            "target_profile": target_profile,
            "optional_args": optional,
            "is_internal_operation": False,
        }

        result = ExportAsOperationDetails.create_operation_details(**details)
        return result

Functions

retrieve_included_operation_configs() -> Iterable[Union[Mapping, OperationConfig]]
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/operations/included_core_operations/export_as.py
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def retrieve_included_operation_configs(
    self,
) -> Iterable[Union[Mapping, OperationConfig]]:

    result = []
    for name, module_cls in self._kiara.module_type_classes.items():
        if not hasattr(module_cls, "retrieve_supported_export_combinations"):
            continue

        try:
            supported_combinations = module_cls.retrieve_supported_export_combinations()  # type: ignore
            for sup_comb in supported_combinations:
                source_type = sup_comb["source_type"]
                target_profile = sup_comb["target_profile"]
                func = sup_comb["func"]

                if source_type not in self._kiara.data_type_names:
                    logger.debug(
                        "ignore.operation_config",
                        module_type=name,
                        reason=f"Source type '{source_type}' not registered.",
                    )
                    continue

                if not hasattr(module_cls, func):
                    logger.debug(
                        "ignore.operation_config",
                        module_type=name,
                        reason=f"Specified create function '{func}' not available.",
                    )
                    continue

                mc = {"source_type": source_type, "target_profile": target_profile}
                # TODO: check whether module config actually supports those, for now, only 'DataExportModule' subtypes are supported
                _func = getattr(module_cls, func)
                doc = DocumentationMetadataModel.from_function(_func)

                oc = ManifestOperationConfig(
                    module_type=name, module_config=mc, doc=doc
                )
                result.append(oc)
        except Exception as e:
            log_exception(e)
            logger.debug(
                "ignore.create_operation_instance", module_type=name, reason=e
            )
            continue

    return result
check_matching_operation(module: KiaraModule) -> Union[ExportAsOperationDetails, None]
Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/kiara/operations/included_core_operations/export_as.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def check_matching_operation(
    self, module: "KiaraModule"
) -> Union[ExportAsOperationDetails, None]:

    if not isinstance(module, DataExportModule):
        return None

    source_type = None
    for field_name, schema in module.inputs_schema.items():
        if field_name == schema.type:
            if source_type is not None:
                logger.debug(
                    "ignore.operation",
                    operation_type="create_from",
                    reason=f"more than one possible target type field: {field_name}",
                )
                return None
            source_type = field_name

    if source_type is None:
        return None

    target_profile = module.config.target_profile

    op_id = self._calculate_op_id(
        source_type=source_type, target_profile=target_profile
    )

    optional = {}
    for field, schema in module.inputs_schema.items():
        if field in [source_type]:
            continue
        optional[field] = schema

    details = {
        "module_inputs_schema": module.inputs_schema,
        "module_outputs_schema": module.outputs_schema,
        "operation_id": op_id,
        "source_type": source_type,
        "target_profile": target_profile,
        "optional_args": optional,
        "is_internal_operation": False,
    }

    result = ExportAsOperationDetails.create_operation_details(**details)
    return result

Functions