Class reference¶
ConfigFile¶
-
class
EasyCo.ConfigFile(path=None)¶ -
set_path(path)¶ Set the path to the configuration file. If no file extension is specified
.ymlwill be automatically appended.- Parameters
path (
Union[Path,str]) – Path obj or str
-
load(path=None)¶ Load values from the configuration file. If the file doesn’t exist it will be created. Missing required config entries will also be created.
- Parameters
path (
Optional[Path]) – if not already set a path instance to the config file
-
ConfigContainer¶
-
class
EasyCo.ConfigContainer(key_name=None)¶ -
on_set_value(var_name, new_value)¶ Override this function to perform datatype conversions when values get loaded from the file
- Parameters
var_name (
str) – variable namenew_value – new value which was loaded from file
- Returns
Value which will be set
-
on_all_values_set()¶ Override this function. It’ll be called when all values from the file have been correctly set. Use it e.g. to calculate and set additional variables.
-
subscribe_for_changes(func)¶ When a value in this container changes the passed function will be called.
- Parameters
func – function which will be called
-
PathContainer¶
-
class
EasyCo.PathContainer¶ Container which converts all values with type
strtoPathobjects. Relative paths will be resolved in relation to the folder where the config file is.
ConfigEntry¶
-
class
EasyCo.ConfigEntry(default=MISSING, default_factory=MISSING, validator=MISSING, required=True, description='', key_name=None)¶ -
__init__(default=MISSING, default_factory=MISSING, validator=MISSING, required=True, description='', key_name=None)¶ ConfigEntry
- Parameters
default – Default value for this entry
default_factory (
Callable[[],Any]) – Factory function which creates the default value, use for list, dict, etc.validator – validator which validates the loaded values
required (
bool) – is this entry requireddescription (
str) – description of this entry which will also be added to the config file as a commentkey_name (
Optional[str]) – key name in the config file
-