esm_parser package
Submodules
esm_parser.esm_parser module
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
andadd_
:Finds variables containing
_changes
(but excludingadd_
) 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.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 achoose_
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 theseadd_<variable>``s is done using ``deep_update
, meaning that the merge is arbitrary (i.e. if twochoose_
blocks are modifying the same variable usingadd_
, the final value would be decided arbitrarily). It is up to the developer/user to make good use ofadd_``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
- Raises
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 thechoose_
(also separated by “,”) and the case that follows thechoose_
.- 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.