ravestate.argparser

handle_args

handle_args(*args) -> Tuple[List[str], List[Tuple[str, str, Any]], List[str]]

Runs an argument parser for the given args. Returns modules-to-load, config value-overrides and config file-pathes. Note: If the arguments are ill-formatted, or the -h argument is passed, help will be printed to the console and the program will abort.

  • args: Argument list which will be fed into argparse.parse_args.

Returns: A Tuple with three items: 1.) A list of module names which should be imported. 2.) A list of tuples, where each tuple is a module name, a config key name, and a value. 3.) A list of yaml file paths.

ravestate.config

Configuration

Configuration(self, paths: List[str])

The Configuration class maintains a dictionary of key-value stores, which represent configuration entries for specific named modules. The key-value stores may be successively updated with consecutive yaml files, where each yaml document has the following content:


module: module-name config: key-a: value-a key-b: value-b # etc


add_conf

Configuration.add_conf(self, mod: ravestate.module.Module)

Register a set of allowed config entries for a specific module. Correctly typed values for allowed keys, that were previously parsed during construction from the yaml files, will be applied immediately.

  • mod: A module object with a name and a conf dict.

get_conf

Configuration.get_conf(self, module_name: str)

Retrieve updated config values for a module that was previously registered with add_conf.

  • module_name: The module name for which configuration should be retrieved.

Returns: A dictionary which contains exactly the keys that were contained in the module configuration dictionary during add_conf, or an empty dictionary if the module name is unknown.

get

Configuration.get(self, module_name: str, key: str) -> Any

Get the current value of a config entry.

  • module_name: The module that provides the config entry.

  • key: A config key for the module that was previously added through add_conf.

Returns: The current value, or None, if the entry does not exist.

set

Configuration.set(self, module_name: str, key: str, value: Any)

Set the current value of a config entry.

  • module_name: The module of the config entry.

  • key: A config key for the module that was previously added through add_conf.

  • value: The new value for the config entry. An error will be raised, if the type of the new value does not match the type of the old value.

write

Configuration.write(self, path: str)

Write all current config entries to a yaml file.

  • path: The file path to write. Will be overwritten!

read

Configuration.read(self, path: str)

Loads all documents from a yaml file and tries to interpret them as configuration objects as described above.

  • path: The yaml file path from which to load config documents.