Skip to content

kiara.operations.calculate_hash

CalculateHashOperationType

Operation type to calculate hash(es) for data.

This is mostly used internally, so users usually won't be exposed to operations of this type.

CalculateValueHashesConfig pydantic-model

hash_type: str pydantic-field required

The hash type.

value_type: str pydantic-field required

The type of the value to calculate the hash for.

CalculateValueHashModule

Calculate the hash of a value.

create_input_schema(self)

Abstract method to implement by child classes, returns a description of the input schema of this module.

If returning a dictionary of dictionaries, the format of the return value is as follows (items with '*' are optional):

{ "[input_field_name]: { "type": "[value_type]", "doc*": "[a description of this input]", "optional*': [boolean whether this input is optional or required (defaults to 'False')] "[other_input_field_name]: { "type: ... ... }

Source code in kiara/operations/calculate_hash.py
def create_input_schema(
    self,
) -> typing.Mapping[
    str, typing.Union[ValueSchema, typing.Mapping[str, typing.Any]]
]:

    input_name = self.get_config_value("value_type")
    if input_name == "any":
        input_name = "value_item"

    return {
        input_name: {
            "type": self.get_config_value("value_type"),
            "doc": f"A value of type '{self.get_config_value('value_type')}'.",
        }
    }

create_output_schema(self)

Abstract method to implement by child classes, returns a description of the output schema of this module.

If returning a dictionary of dictionaries, the format of the return value is as follows (items with '*' are optional):

{ "[output_field_name]: { "type": "[value_type]", "doc*": "[a description of this output]" "[other_input_field_name]: { "type: ... ... }

Source code in kiara/operations/calculate_hash.py
def create_output_schema(
    self,
) -> typing.Mapping[
    str, typing.Union[ValueSchema, typing.Mapping[str, typing.Any]]
]:
    return {"hash": {"type": "string", "doc": "The hash string."}}

retrieve_module_profiles(kiara) classmethod

Retrieve a collection of profiles (pre-set module configs) for this kiara module type.

This is used to automatically create generally useful operations (incl. their ids).

Source code in kiara/operations/calculate_hash.py
@classmethod
def retrieve_module_profiles(
    cls, kiara: "Kiara"
) -> typing.Mapping[str, typing.Union[typing.Mapping[str, typing.Any], Operation]]:

    all_metadata_profiles: typing.Dict[
        str, typing.Dict[str, typing.Dict[str, typing.Any]]
    ] = {}

    for value_type_name, value_type in kiara.type_mgmt.value_types.items():

        hash_types = value_type.get_supported_hash_types()

        for ht in hash_types:
            op_config = {
                "module_type": cls._module_type_id,  # type: ignore
                "module_config": {"value_type": value_type_name, "hash_type": ht},
                "doc": f"Calculate '{ht}' hash for value type '{value_type_name}'.",
            }
            all_metadata_profiles[
                f"calculate_hash.{ht}.for.{value_type_name}"
            ] = op_config

    return all_metadata_profiles