def write_yaml_file()

in google_cloud_automlops/utils/utils.py [0:0]


def write_yaml_file(filepath: str, contents: dict, mode: str):
    """Writes a dictionary to yaml. Defaults to utf-8 encoding.

    Args:
        filepath (str): Path to the file.
        contents (dict): Dictionary to be written to yaml.
        mode (str): Read/write mode to be used.

    Raises:
        Exception: An error is encountered while writing the file.
    """
    try:
        with open(filepath, mode, encoding='utf-8') as file:
            yaml.safe_dump(contents, file, sort_keys=False)
        file.close()
    except yaml.YAMLError as err:
        raise yaml.YAMLError(f'Error writing to file. {err}') from err