Gila Utils

Custom Errors

This will contain the custom errors Gila uses

exception CircularReference

Bases: Exception

exception ConfigFileNotFound

Bases: Exception

exception ConfigNotSupported

Bases: Exception

Helper Functions

Misc functions to clean up main file

If path = [“foo”, “bar”, “baz”] The assumed values are:

haystack = {
    foo: {
        bar: {
            baz: {}
        }
    }
}

Where the dict that baz points to is returned

If this is not the case, the config haystack is modified in order to facilitate this

Parameters
  • haystackdict - dictionary to search

  • keypathList[str] - path to follow while searching

dict_merge(dict_1: dict, dict_2: dict)

Merge two dictionaries.

dict_1 > dict_2 Creates a dictionary that has all keys and values from dict2 and dict1. For any keys in common, the value from dict1 overwrites the value from dict2 This allows falsey values such as False and 0 to be included as config values.

Params dict_1

the primary dictionary to pull results from

Params dict_2

the secondary dictionary to pull results from

env_to_dict(filepath: str)

Loads in config from a dotenv file to a dictionary using dotenv

NOTE: All values read in as strings.

Params filepath

str - Filepath to dotenv config file to unmarshal

hcl_to_dict(filepath: str)

Loads in config from an hcl file to a dictionary using pyhcl

Params filepath

str - Filepath to hcl config file to unmarshal

json_to_dict(filepath: str)

Loads in config from a json file to a dictionary using json stlib

Params filepath

str - Filepath to json config file to unmarshal

prop_to_dict(filepath: str)

Loads in config from a dotenv file to a dictionary using the configparser stdlib

NOTE: All values read in as strings.

Params filepath

str - Filepath to dotenv config file to unmarshal

toml_to_dict(filepath: str)

Loads in config from a toml file to a dictionary using toml

Params filepath

str - Filepath to toml config file to unmarshal

yaml_to_dict(filepath: str)

Loads in config from a yaml file to a dictionary using pyyaml

Params filepath

str - Filepath to yaml config file to unmarshal