pyra.config#

Responsible for config related functions.

pyra.config.create_config(config_file: str, config_spec: list = _CONFIG_SPEC) ConfigObj[source]#

Create a config file and ConfigObj using a config spec.

The created config is validated against a Validator object. This function will remove keys from the user’s config.ini if they no longer exist in the config spec.

Parameters:
config_filestr

Full filename of config file.

config_speclist, default = _CONFIG_SPEC

Config spec to use.

Returns:
ConfigObj

Dictionary of config keys and values.

Raises:
SystemExit

If config_spec is not valid.

Examples

>>> create_config(config_file='config.ini')
ConfigObj({...})
pyra.config.save_config(config: ConfigObj | None = CONFIG) bool[source]#

Save the config to file.

Saves the ConfigObj to the specified file.

Parameters:
configConfigObj, default = CONFIG

Config to save.

Returns:
bool

True if save successful, otherwise False.

Examples

>>> config_object = create_config(config_file='config.ini')
>>> save_config(config=config_object)
True
pyra.config.validate_config(config: ConfigObj) bool[source]#

Validate ConfigObj dictionary.

Ensures that the given ConfigObj is valid.

Parameters:
configConfigObj

Config to validate.

Returns:
bool

True if validation passes, otherwise False.

Examples

>>> config_object = create_config(config_file='config.ini')
>>> validate_config(config=config_object)
True