Context

Contents

Context#

class processor_tools.context.Context(config: str | List[str] | dict | None = None, supercontext: List[Context | Tuple[Context, str]] | None = None, config_init: ConfigInit | None = None)[source]#

Class to determine and store processing state

Parameters:

config – processing configuration data, either:

  • dictionary of configuration data

  • path of configuration file or directory containing set of configuration files

  • list of dicts/paths (earlier in the list overwrites later in the list)

Parameters:

supercontext – context supercontext or list of supercontexts (earlier in the list overwrites later in the list), configuration values of which override those defined in the context. Each defined as context object or tuple of:

  • supercontext (Context) - supercontext object

  • section (str) - name of section of supercontext to apply as supercontext

Parameters:

config_init – config initialiser for setting up default config files/directories to be loaded every time the class is initialised, as well as providing methods for generating config file/directory paths. See processor_tools.config.init_config.ConfigInit for more details.

For example:

supercontext = Context({"section": {"val1": 1 , "val2", 2}})
(supercontext, "section")

Methods

__init__

get

Get config value if defined, else return default

get_config_names

Get available config value names

keys

Get available config value names

set

Sets config data

update

Update config values

update_from_file

Update config values from file

write_config

Write config values to file

Attributes

config_values

Returns defined configuration values

default_config

supercontext

Return context supercontexts