naming

Utilities for expanding name templates using metadata.

class merge_utils.naming.Formatter(metadata: dict | None = None)[source]

Wrapper class to access metadata dictionary.

Initialize the Formatter with a metadata dictionary.

class CfgFormatter(head, key, val)[source]

Class to format configuration keys.

class MetaFormatter(head, key, idx=None, valid=True)[source]

Class to format metadata keys.

class ValFormatter(head, key, value, no_format=False)[source]

Class to format generic values.

eval(condition: str) bool[source]

Evaluate a condition using the metadata dictionary.

Parameters:

condition – condition string to evaluate

Returns:

evaluated value

format(template: ConfigString, defer_uuid: bool = False)[source]

Format a config string using the metadata dictionary.

Parameters:

template – config string template

format_key(key: str, val: any, spec: str) str[source]

Format a metadata key with a given specification.

Parameters:
  • key – key name

  • val – key value

  • spec – format specification

Returns:

formatted string

get(key, idx=None)[source]

Get a metadata value by key.

Parameters:
  • key – metadata key

  • idx – optional index or slice

Returns:

metadata value

reset()[source]

Reset the formatter state.

merge_utils.naming.read_dict(data: dict, key: any) tuple[source]

Try to extract a value from a dictionary.

Parameters:
  • data – dictionary of data

  • key – dictionary key

Returns:

extracted value

merge_utils.naming.read_list(data: list, idx: any) tuple[source]

Try to extract a value from a list.

Parameters:
  • data – list of data

  • idx – index or slice string

Returns:

extracted value and list of errors