toolrack.config
Hold and parse key/value configurations.
The Config
describes valid configuration keys along with their types,
and performs parsing and type conversion from a dict of config options. It
also checks required keys and applies default values if an option is not
provided.
As an example:
config = Config(
ConfigKey('option1', 'int', default=4),
ConfigKey('option2', 'bool', required=True))
config.parse({'option2': 'true'})
returns {'option1': 4, 'option2': True}
.
- class toolrack.config.Config(*keys)
Parse a configuration dictionary.
A configuration has a set of keys of specific types.
- parse(config)
Parse the provided configuration dict.
Returns a dict with configuration keys and values converted to the proper type. The dict includes only keys declared in the Config, with default values if not present in the config dict.
- Return type:
dict
[str
,Any
]
- class toolrack.config.ConfigKey(name, _type, description='', required=False, default=None, validator=None)
A key in the Configuration.
- parse(value)
Convert and validate a value.
- Return type:
Any
- validate(value)
Validate a value based for the key.
Can be overridden by subclasses. It should raise a ValueError if the value is invalid.
- Return type:
None
- class toolrack.config.ConfigKeyTypes
Collection of type converters for ConfigKeys.
- get_converter(_type)
Return the converter method for the specified type.
- Return type:
Callable
[[Any
],Any
]
- exception toolrack.config.InvalidConfigValue(key)
- exception toolrack.config.MissingConfigKey(key)