Config
Implementation for yaml class to write configuration files.
YamlConfig(file_path, data_dict=None)
¶
Class to handle YAML configuration files.
Initialize with the path to the YAML file. Args: file_path str: Path to the YAML configuration file. data_dict (dict | None) : Dictionary to create the YAML file if it doesn't exist.
data_dict = data_dict
¶
file_path = file_path
¶
delete_key(key)
¶
Delete a key from the YAML configuration file. Args: key (str): The key to delete from the configuration.
read_config()
¶
Read the YAML configuration file and return its contents as a dictionary.
to_cli(data=None, prefix='--')
¶
Convert the YAML configuration to a command-line argument string. Args: data (Dict | None) : Dictionary to convert. If None, uses self.data_dict. prefix (str): Prefix for command-line arguments. Default is "--".
update_config(updates, parent_key=None)
¶
Update the YAML configuration file with the given dictionary. Allow both surface and deep updates. Args: updates : Dictionary containing updates to apply. parent_key : Key or key path to descend into. None updates at the top level.
validate()
¶
Validate the YAML configuration file. This method can be overridden in subclasses to implement specific validation logic.
write_config(config)
¶
Write the given dictionary to the YAML configuration file. Args: config (dict): Dictionary to write to the YAML file.