meta

Utility functions for merging metadata for multiple files.

class meta.MergeMetaAll[source]

Merge metadata by taking the set of values.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

property value

Get the merged value.

class meta.MergeMetaMax[source]

Merge metadata by taking the maximum value.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

class meta.MergeMetaMin[source]

Merge metadata by taking the minimum value.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

class meta.MergeMetaOverride(value=None)[source]

Merge metadata by overriding the value.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

class meta.MergeMetaSubset(value=None)[source]

Merge metadata by taking the subset of consistent values.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

property warn

Whether to warn about inconsistent metadata.

class meta.MergeMetaSum[source]

Merge metadata by adding the values.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

class meta.MergeMetaUnion[source]

Merge metadata by taking the union.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

property value

Get the merged value.

class meta.MergeMetaUnique(value=None)[source]

Merge metadata by taking the unique values.

add(value)[source]

Add a new value to the metadata.

property valid

Check if the value is valid.

class meta.MetaNameDict(metadata: dict)[source]

Wrapper class to access metadata dictionary.

Initialize the MetaNameDict with a metadata dictionary.

class MetaKey(meta, key: str)[source]

Class to parse metadata keys.

class MetaVal(meta, key, idx=None)[source]

Class to read metadata values.

property key: str

Get the metadata key.

Returns:

metadata key

read_dict(data) any[source]

Try to extract a value from a dictionary.

Parameters:

data – dictionary of data

Returns:

extracted value

read_list(data) any[source]

Try to extract a value from a list.

Parameters:

data – list of data

Returns:

extracted value

property value: any

Get the metadata value.

Returns:

metadata value

eval(condition: str) bool[source]

Evaluate a condition using the metadata dictionary.

Parameters:

condition – condition string to evaluate

Returns:

evaluated value

format(template: str, strict: bool = True) str[source]

Format a string using the metadata dictionary.

Parameters:

template – template string

Returns:

formatted string

get(key, default=None)[source]

Get a metadata value by key.

Parameters:
  • key – metadata key

  • default – default value if key not found

Returns:

metadata value

meta.auto_output(files: dict) None[source]

Auto-generate an output file name with the same extension as the inputs, if needed.

Parameters:

files – set of files to merge

meta.check_method(files: dict) None[source]

Check and set the merging method based on the input file metadata.

Parameters:

files – set of files to merge

meta.check_required(metadata: dict) list[source]

Check if the metadata dictionary contains all required keys.

Parameters:

metadata – metadata dictionary

Returns:

List of any missing required keys

meta.fix(name: str, metadata: dict) None[source]

Fix the metadata dictionary.

Parameters:
  • name – name of the file (for logging)

  • metadata – metadata dictionary

meta.log_method() None[source]

Log the final merging method configuration.

meta.make_names(files: dict) str[source]

Update merging method and create a name for the merged files.

Parameters:

files – set of files to merge

Returns:

merged file name

meta.match_method(name: str | None = None, metadata: dict | None = None) dict[source]

Find a built-in merging method by name or metadata conditions.

Parameters:
  • name – name of the merging method

  • metadata – metadata dictionary

Returns:

merging method dictionary

meta.merge_cfg_keys() dict[source]

Get special merging configuration keys from the global config.

Returns:

dictionary of merging configuration keys

meta.merged_keys(files: dict, warn: bool = False) dict[source]

Merge metadata from multiple files into a single dictionary.

Parameters:
  • files – set of files to merge

  • warn – whether to warn about inconsistent metadata

Returns:

merged metadata

meta.parents(files: dict) list[str][source]

Retrieve all the parents from a set of files.

Parameters:

files – set of files to merge

Returns:

set of parents

meta.set_method(method: dict) None[source]

Set merging method parameters.

Parameters:

method – merging method dictionary

meta.set_method_auto(metadata: dict) None[source]

Auto-select merging method based on metadata conditions.

Parameters:

metadata – metadata dictionary

meta.set_method_custom() None[source]

Set merging method parameters for a custom script.

meta.validate(name: str, metadata: dict, requirements: bool = True) bool[source]

Validate the metadata dictionary.

Parameters:
  • name – name of the file (for logging)

  • metadata – metadata dictionary

  • requirements – whether to check for required keys

Returns:

True if metadata is valid, False otherwise