teachbooks.external_content.utils module

Utilities for external content.

teachbooks.external_content.utils.load_yaml_file(path: str | Path, encoding: str = 'utf8') dict[str, Any]

Load a yaml file file (ToC or config) as dictionary.

Parameters:
  • path – file path

  • encoding – file character encoding

Returns:

parsed file

teachbooks.external_content.utils.modify_field(data: dict, key: str, func: Callable, *args, **kwargs) dict
teachbooks.external_content.utils.modify_field(data: list, key: str, func: Callable, *args, **kwargs) list

Modify the fields that match a given key.

Recursively look for the fields matching a given key in a YAML-like mapping. Modify the matching fields by running func on them.

Parameters:
  • data – mapping where to look for matches

  • key – key to look for

  • func – function to run on the matching fields

  • args – positional arguments for func

  • kwargs – keyword arguments for func

Returns:

modified mapping