yamlpars package
- class yamlpars.Parameters(yaml_folder: Union[str, Path], auto_load: bool = True)[source]
The Parameters object loads the yaml files from the folder specified in the constructor, and allows easy dot-notation access to the parameters, as well as an useful serialization methods.
- yaml_folder
the folder containing the yaml files.
- Type
- auto_load
if True, the yaml files are loaded automatically when the object is created. The default is True.
- Type
Example
>>> pars = Parameters("path/to/yaml/folder") >>> pars.group_a.a_int 1 >>> pars.group_a.a_float 1.0
- load() None [source]
Load parameters into the object by parsing the yaml files.
- Raises
FileNotFoundError – the folder containing the yaml files does not exist.
- yamlpars.update_yaml_file(yaml_folder: Union[str, Path], file_name: str, update_dict: Dict[str, Any], record_file_name: Optional[str] = None, check_type: bool = True, lint_yaml_file_after_update: bool = True) None [source]
Update the entries in a yaml file according to the update_dict.
- Parameters
yaml_folder (str | pathlib.Path) – the folder containing the yaml files.
file_name (str) – the name of the file to update, without the extension.
update_dict (Dict[str, Any]) – the dictionary containing the updated values.
record_file_name (str, optional) – the name of the file used to keep track of the updates. If None, the record file is not updated.
check_type (bool) – if True, the type of the updated values is checked against the type of the original values. If the type is different, a TypeError is raised. The default is True.
lint_yaml_file_after_update (bool) – if True, the yaml file is linted after the update. The default is True.
- Raises
FileNotFoundError – the file to update does not exist.
KeyError – a key in the update_dict does not exist in the original yaml file.
TypeError – the type of the updated values is different from the original.
Example
>>> update_yaml_file("path/to/yaml/folder", "group_a", {"a_int": 2, "a_float": 2.0})