ConfigFramework.abstract package¶
Submodules¶
-
class
AbstractConfigLoader
(data: Union[Dict, collections.ChainMap, collections.abc.Mapping], defaults: Dict, include_defaults_to_dumps: Optional[bool] = None, *args, **kwargs)[source]¶ Bases:
abc.ABC
,collections.abc.Mapping
Base class for any of your loaders. Initialization can be made through load function, or, if author wants so, through __init__ function.
-
abstract classmethod
load
(*args, **kwargs)[source]¶ Initializes creation of new ConfigLoader. You must provide your arguments that are needed for your first_loader.
- Parameters
args – arguments that can be used for your custom loaders.
kwargs – keyword arguments that can be used for your custom loaders.
-
abstract
dump
(include_defaults: bool = False) → NoReturn[source]¶ Dumps updated variables to loader.
- Parameters
include_defaults – specifies if you want to have default variables to be dumped.
- Returns
nothing.
-
dump_to
(other_loader: ConfigFramework.abstract.abc_loader.AbstractConfigLoader, include_defaults: bool = False) → NoReturn[source]¶ Dumps variables to other first_loader that been already initialized.
- Parameters
other_loader – other first_loader that already initialized and where you want to dump stuff.
include_defaults – include_defaults_to_dumps: specifies if you want to have default variables to be.
- Returns
nothing.
-
get
(key: Union[Hashable, AnyStr, pathlib.Path], default=None) → Any[source]¶ Returns an item under specified key or key as path and if it didn’t find it - returns default variable.
- Parameters
key – a key that points at where you want to grab variable.
default – default config_var.
- Returns
anything lying there.
-
static
key_to_path_cast
(key: Union[AnyStr, Hashable, pathlib.Path]) → Union[Tuple[AnyStr, …], Tuple[Hashable, …]][source]¶ Casts a key to tuple of keys, that should be applied one by one to get to where variable lies. Path pointing example: config_root/database/database_ip
- Parameters
key – string with path, pointing at out variable or hashable.
- Returns
tuple of sub keys.
-
get_to_variable_root
(keys: Union[Tuple[AnyStr, …], Tuple[Hashable, …]], lookup_at: Optional[Dict] = None) → Dict[source]¶ Returns an dictionary with our variable.
- Parameters
keys – keys tuple we apply to get to root of variable.
lookup_at – the location we’re looking at. In case we need to lookup at specific part of our first_loader.
- Returns
a dictionary which layer should contain our variable.
-
abstract classmethod
-
class
AbstractConfigVar
(key: [Hashable, AnyStr, Path], loader: AbstractConfigLoader, *, typehint: Optional[Type] = typing.Any, caster: Optional[Callable] = None, dump_caster: Optional[Callable, DumpCaster] = None, validator: Optional[Callable] = None, default: Optional[Any] = None, constant: bool = False)[source]¶ Bases:
object
Abstract config variable with descriptors interface which is a base type for any of your variables classes.
-
caster
(value: Any) → Any[source]¶ Callable that should return variable casted to specific type (in case you need custom types).
- Parameters
value – config_var to be casted.
- Returns
value casted to whatever type you need.
-
dump_caster
(config_var: ConfigFramework.abstract.abc_variable.AbstractConfigVar) → Any[source]¶ Callable that being called when config being dumped. Nothing being passed as attribute since it should be executed after assigning the config_var to ConfigVar. Through self we can get to config variables value, but not when we use DumpCaster, which allows us to assign specific caster for exact ConfigLoader and so parameter config_var is used to pass config variable that is going to be casted for compatibility with DumpCaster.
- Parameters
config_var – Config variable that going to be casted.
- Returns
value casted to whatever type you need to save value.
-
validate
(value: Any) → bool[source]¶ Callable that validates config_var or defaults in case the original config_var is invalid.
- Parameters
value – config_var to be validated.
- Returns
bool value representing if variable has a valid value.
-
property
value
¶ Gives access to casted value.
- Returns
any value from config, that been casted and validated.
-