esm_parser package

Submodules

esm_parser.esm_parser module

esm_parser.shell_to_dict module

Backwards compatability for old runscripts

esm_parser.shell_to_dict.ShellscriptToUserConfig(runscript_path)[source]

Generates a User Config from an old Shellscript

esm_parser.shell_to_dict.mini_recursive_run_func(config, func)[source]
esm_parser.shell_to_dict.purify_cases(config)[source]
esm_parser.shell_to_dict.remap_old_new_keys(config)[source]

esm_parser.yaml_to_dict module

exception esm_parser.yaml_to_dict.EsmConfigFileError(fpath, yaml_error)[source]

Bases: Exception

Exception for yaml file containing tabs or other syntax issues.

An exception used when yaml.load() throws a yaml.scanner.ScannerError. This error occurs mainly when there are tabs inside a yaml file or when the syntax is incorrect. If tabs are found, this exception returns a user-friendly message indicating where the tabs are located in the yaml file.

Parameters

fpath (str) – Path to the yaml file

esm_parser.yaml_to_dict.check_changes_duplicates(yamldict_all, fpath)[source]

Checks for duplicates and conflicting _changes and add_:

  1. Finds variables containing _changes (but excluding add_) and checks if they are compatible with the same _changes inside the same file. If they are not compatible returns an error where the conflicting variable paths are specified. More than one _changes type in a file are allowed but they need to be part of the same _choose and not be accessible simultaneously in any situation.

  2. Checks if there is any variable containing add_ in the main sections of a file and labels it as incompatible if the same variable is found inside a choose_ block. add_<variable>``s are compatible as long as they are inside ``choose_ blocks, but if you want to include something as a default, please just do it inside the <variable>.

    Warning

    add_<variable>``s are not checked for incompatibility when they are included inside ``choose_ blocks. Merging of these add_<variable>``s is done using ``deep_update, meaning that the merge is arbitrary (i.e. if two choose_ blocks are modifying the same variable using add_, the final value would be decided arbitrarily). It is up to the developer/user to make good use of add_``s inside ``choose_ blocks.

Parameters
  • yamldict_all (dict) – Dictionary read from the yaml file

  • fpath (str) – Path to the yaml file

esm_parser.yaml_to_dict.check_duplicates(src)[source]

Checks that there are no duplicates in a yaml file, and if there are returns an error stating which key is repeated and in which file the duplication occurs.

Parameters
  • src (object) – Source file object

  • Exceptions

  • ----------

  • ConstructorError – If duplicated keys are found, returns an error

esm_parser.yaml_to_dict.create_env_loader(tag='!ENV', loader=<class 'yaml.loader.SafeLoader'>)[source]
esm_parser.yaml_to_dict.find_last_choose(var_path)[source]

Locates the last choose_ on a string containing the path to a variable separated by “,”, and returns the path to the choose_ (also separated by “,”) and the case that follows the choose_.

Parameters

var_path (str) – String containing the path to the last choose_ separated by “,”.

Returns

  • path2choose (str) – Path to the last choose_.

  • case (str) – Case after the choose.

esm_parser.yaml_to_dict.yaml_file_to_dict(filepath)[source]

Given a yaml file, returns a corresponding dictionary.

If you do not give an extension, tries again after appending one. It raises an EsmConfigFileError exception if yaml files contain tabs.

Parameters

filepath (str) – Where to get the YAML file from

Returns

A dictionary representation of the yaml file.

Return type

dict

Raises
  • EsmConfigFileError – Raised when YAML file contains tabs or other syntax issues.

  • FileNotFoundError – Raised when the YAML file cannot be found and all extensions have been tried.