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.

exception peltak.core.context.ContextError[source]

Base class for context related exceptions.

exception peltak.core.context.InvalidPath(path)[source]

Invalid variable path.

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.

clear()[source]

Clear all existing values.

Return type

None

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

Any

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.

has(name)[source]

Check whether the given name/path is present in the context.

Parameters

name (str) – The name of the value to check for. You can reach nested values using the dot notation. For example some.value.name will internally traverse up to 3 dictionaries to perform ths check.

Return type

bool

Returns

True if the value is stored in the context, False otherwise.

set(name, value)[source]

Set context value.

Parameters
  • name (str) – The name of the context value to change.

  • value (Any) – The new value for the selected context value

Return type

None

peltak.core.context.clear()[source]

Clear all existing values.

Return type

None

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

Any

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.has(name)[source]

Check whether the given name/path is present in the context.

Parameters

name (str) – The name of the value to check for. You can reach nested values using the dot notation. For example some.value.name will internally traverse up to 3 dictionaries to perform ths check.

Return type

bool

Returns

True if the value is stored in the context, False otherwise.

peltak.core.context.set(name, value)[source]

Set context value.

Parameters
  • name (str) – The name of the context value to change.

  • value (Any) – The new value for the selected context value

Return type

None