peltak.core.context
¶
Runtime context implementation.
Runtime context is a unified place to store dynamic global configuration. The
verbosity and pretend
is a good example of that.
Works like peltak.core.conf but the configuration can be dynamically modified in runtime.
- class peltak.core.context.RunContext(*args, **kw)[source]¶
Runtime context.
This class is the equivalent of conf but for values that can be modified in runtime. This is for all the settings that can be set on the command line and can span many commands or APIs.
- get(name, *default)[source]¶
Get context value with the given name and optional default.
- Parameters
name (str) – The name of the context value.
*default (Any) – If given and the key doesn’t not exist, this will be returned instead. If it’s not given and the context value does not exist,
AttributeError
will be raised
- Return type
- Returns
The requested context value. If the value does not exist it will return default if give or raise
AttributeError
.- Raises
AttributeError – If the value does not exist and default was not given.
- peltak.core.context.get(name, *default)[source]¶
Get context value with the given name and optional default.
- Parameters
name (str) – The name of the context value.
*default (Any) – If given and the key doesn’t not exist, this will be returned instead. If it’s not given and the context value does not exist,
AttributeError
will be raised
- Return type
- Returns
The requested context value. If the value does not exist it will return default if give or raise
AttributeError
.- Raises
AttributeError – If the value does not exist and default was not given.