cliconfig.tag_routines

Routines to manipulate the tags on the keys of a dict.

Used by the processing functions.

clean_tag(flat_key, tag_name)

Clean a tag from a flat key.

It removes all occurrences of the tag with the exact name.

Parameters:
  • flat_key (str) – The flat key to clean.

  • tag_name (str) – The name of the tag to remove, with or without the ‘@’ prefix.

Returns:

flat_key – The cleaned flat key.

Return type:

str

Note

tag_name is supposed to be the exact name of the tag.

Examples

>>> clean_tag('abc@tag.def@tag_2.ghi@tag', 'tag')
abc.def@tag_2.ghi
clean_all_tags(flat_key)

Clean all tags from a flat key.

Parameters:

flat_key (str) – The flat key to clean.

Returns:

flat_key – The cleaned flat key.

Return type:

str

dict_clean_tags(flat_dict)

Clean a dict from all tags and return the list of keys with tags.

Parameters:

flat_dict (Dict[str, Any]) – The flat dict to clean.

Return type:

Tuple[Dict[str, Any], List[str]]

Returns:

  • clean_dict (Dict[str, Any]) – The cleaned flat dict without tags in the keys.

  • tagged_keys (List[str]) – The list of keys with tags that have been cleaned.

is_tag_in(flat_key, tag_name, *, full_key=False)

Check if a tag is in a flat key.

The tag name must be the exact name, with or without the “@”. It supports the case where there are other tags that are prefixes or suffixes of the considered tag.

Parameters:
  • flat_key (str) – The flat key to check.

  • tag_name (str) – The name of the tag to check, with or without the ‘@’ prefix.

  • full_key (bool, optional) – If True, check for the full key. If False, check for the last part of the flat key (after the last dot) that correspond to the parameter name. By default, False.

Returns:

True if the tag is in the flat key, False otherwise.

Return type:

bool