glorpen.config
API Documentation¶
glorpen.config
¶
-
glorpen.config.
__version__
¶ Current package version.
-
class
glorpen.config.
Config
(spec, loader=None, split_character='.')[source]¶ Config validator and normalizer.
-
finalize
(data=None)[source]¶ Load and resolve configuration in one go.
If data argument is given loader specified in constructor will not be used.
-
glorpen.config.fields.base
¶
-
class
glorpen.config.fields.base.
Field
[source]¶ Single field in configuration file.
Custom fields should register own resolvers/validators/normalizers by extending
make_resolvable()
.For handling registered callbacks, see
ResolvableObject
.-
make_resolvable
(r)[source]¶ Used to register normalizes in current
ResolvableObject
.
-
resolve
(v, checked=False)[source]¶ Wraps value in
ResolvableObject
optionally checking whether provided value is supported.
-
-
class
glorpen.config.fields.base.
FieldWithDefault
(default=<class glorpen.config.fields.base._UnsetValue>, allow_blank=False)[source]¶ Base class for nullable fields with defaults.
-
class
glorpen.config.fields.base.
ResolvableObject
(o)[source]¶ Configuration value ready to be resolved.
Callbacks are registered by calling
on_resolve
.To each callback are passed:
- currently handled value
Config
instance
By using
Config
instance you can realize value based on any other value in configuration.If value is invalid, callback should raise
ValidationError
with appropriate error message.-
on_resolve
(f)[source]¶ Registers given callback to run when resolving values. Passed function should accept following arguments:
- value - may be a value or
ResolvableObject
- a
Config
instance
- value - may be a value or
glorpen.config.fields.simple
¶
-
class
glorpen.config.fields.simple.
Any
(default=<class glorpen.config.fields.base._UnsetValue>, allow_blank=False)[source]¶ Field that accepts any value.
-
class
glorpen.config.fields.simple.
Dict
(schema=None, keys=None, values=None, **kwargs)[source]¶ Converts values to
collections.OrderedDict
Supports setting whole schema (specific keys and specific values) or just keys type and values type.
Dict values are lazy resolved.
-
class
glorpen.config.fields.simple.
List
(schema, **kwargs)[source]¶ Converts value to list.
List values are lazy resolved.
-
class
glorpen.config.fields.simple.
Number
(default=<class glorpen.config.fields.base._UnsetValue>, allow_blank=False)[source]¶ Converts value to numbers.
-
class
glorpen.config.fields.simple.
Path
(default=<class glorpen.config.fields.base._UnsetValue>, allow_blank=False)[source]¶ Converts given value to disk path.
-
class
glorpen.config.fields.simple.
PathObj
(default=<class glorpen.config.fields.base._UnsetValue>, allow_blank=False)[source]¶ Converts value to
pathlib.Path
object
-
class
glorpen.config.fields.simple.
String
(default=<class glorpen.config.fields.base._UnsetValue>, allow_blank=False)[source]¶ Converts value to string with optional interpolation.
-
class
glorpen.config.fields.simple.
Variant
(schema, try_resolving=False)[source]¶ Converts value to normalized state using one
Field
chosen from multiple provided.To allow blank values you have to pass child field with enabled blank values. First field which supports value (
Field.is_value_supported()
) will be used to convert it.When
try_resolving
mode is disabled (default), value for child fields will only be checked withis_value_supported
, so resulting field will be based only of data type, not value.When enabled, in addition to checking for supported values data will be resolved and first non error result used.
glorpen.config.fields.version
¶
glorpen.config.loaders
¶
glorpen.config.exceptions
¶
-
exception
glorpen.config.exceptions.
CircularDependency
(*args, **kwargs)[source]¶ Thrown when interpolation causes loop.
-
exception
glorpen.config.exceptions.
PathValidationError
(validation_error)[source]¶ Exception for improved readability - uses
ValidationError
to provide full path to field with error.