epymorph.settings
The module to organize epymorph's configuration settings and related functionality.
InvalidBooleanError
Bases: Exception
Raised when a value cannot be interpreted as a boolean.
Setting
Bases: NamedTuple, Generic[ValueT]
An epymorph configuration setting.
strtobool
Interpret a string as a boolean, if possible.
We use the widely-adopted distutils.util.strtobool convention for
strings which can be interpreted as booleans. To quote the documentation:
"True values are y, yes, t, true, on, and 1;
false values are n, no, f, false, off, and 0."
Whitespace will be stripped and values are case-insensitive.
Parameters:
-
value(str) –The string to interpret.
Returns:
-
bool–The boolean value if valid.
Raises:
-
InvalidBooleanError–If the string is not an accepted boolean value format.
env_flag
Load an environment variable assuming it represents a boolean setting.
See the strtobool function for the set of strings which are allowed
for True and False.
Parameters:
-
name(str) –The name of the environment variable to load.
-
default_value(bool | None, default:None) –A default value to use in case the variable is not present or can't be interpreted as a boolean.
Returns:
-
bool | None–If the named variable is present and if the value can be interpreted as a boolean, return the boolean. Else return
default_value.
declare_setting
Declare an application configuration setting.
Parameters:
-
name(str) –The setting name.
-
description(str) –The setting description.
-
getter(Callable[[], ValueT]) –A function to get the value of the setting.
Returns:
Raises:
-
ValueError–If a setting of the same name has been previously declared.