ybe package¶
Subpackages¶
Submodules¶
ybe.configuration module¶
Contains the runtime configuration of YBE.
This consists of two parts, functions to get the current runtime settings and configuration actions to update these
settings. To set a new configuration, create a new ConfigAction
and use this within a context environment
using config_context()
. Example:
from ybe.configuration import YamlStringAction, config_context
config = '''
...
'''
with ybe.config_context(YamlStringAction(config)):
...
-
class
ybe.configuration.
ConfigAction
[source]¶ Bases:
object
Defines a configuration action for the use in a configuration context.
This should define an apply and an unapply function that sets and unsets the given configuration options.
The applying action needs to remember the state before applying the action.
-
class
ybe.configuration.
ConfigSectionLoader
[source]¶ Bases:
object
-
load
(value)[source]¶ Load the given configuration value into the current configuration.
Parameters: value – the value to use in the configuration
-
update
(config_dict, updates)[source]¶ Update the given configuration dictionary with the values in the given updates dict.
This enables automating updating a configuration file. Updates are written in place.
Parameters: - config_dict (dict) – the current configuration dict
- updates (dict) – the updated values to add to the given config dict.
-
-
class
ybe.configuration.
LoggingLoader
[source]¶ Bases:
ybe.configuration.ConfigSectionLoader
Loader for the top level key logging.
-
class
ybe.configuration.
SimpleConfigAction
[source]¶ Bases:
ybe.configuration.ConfigAction
Defines a default implementation of a configuration action.
This simple config implements a default apply() method that saves the current state and a default unapply() that restores the previous state.
It is easiest to implement _apply() for extra actions.
-
class
ybe.configuration.
VoidConfigAction
[source]¶ Bases:
ybe.configuration.ConfigAction
Does nothing. Meant as a container to not have to check for None’s everywhere.
Defines a configuration action for the use in a configuration context.
This should define an apply and an unapply function that sets and unsets the given configuration options.
The applying action needs to remember the state before applying the action.
-
ybe.configuration.
config_context
(config_action)[source]¶ Creates a temporary configuration context with the given config action.
This will temporarily alter the given configuration keys to the given values. After the context is executed the configuration will revert to the original settings.
Example usage:
config = ''' ... ''' with ybe.config_context(ybe.configuration.YamlStringAction(config)): ...
or, equivalently:
config = ''' ... ''' with ybe.config_context(config): ...
This loads the configuration from a YAML string and uses that configuration as the context.
Parameters: config_action (ybe.configuration.ConfigAction or str) – the configuration action to apply. If a string is given we will use it using the YamlStringAction config action.
-
ybe.configuration.
ensure_exists
(keys)[source]¶ Ensure the given layer of keys exists.
Parameters: keys (list of str) – the positions to ensure exist
-
ybe.configuration.
get_config_dir
()[source]¶ Get the location of the components.
Returns: the path to the components Return type: str
-
ybe.configuration.
get_config_option
(option_name)[source]¶ Get the current configuration option for the given option name.
Parameters: option_name (list of str or str) – the name of the option, or a path to the option. Returns: the raw configuration value defined for that option Return type: object
-
ybe.configuration.
get_logging_configuration_dict
()[source]¶ Get the configuration dictionary for the logging.dictConfig().
ybe uses a few special logging configuration options to log to the files and GUI’s. These options are defined using a configuration dictionary that this function returns.
Returns: the configuration dict for use with dictConfig of the Python logging modules Return type: dict
-
ybe.configuration.
get_section_loader
(section)[source]¶ Get the section loader to use for the given top level section.
Parameters: section (str) – the section key we want to get the loader for Returns: the config section loader for this top level section of the configuration. Return type: ConfigSectionLoader
-
ybe.configuration.
load_builtin
()[source]¶ Load the config file from the skeleton in ybe/data/ybe.conf
-
ybe.configuration.
load_from_dict
(config_dict)[source]¶ Load configuration options from a given dictionary.
Please note that this will change the global configuration, i.e. this is a persistent change. If you do not want a persistent state change, consider using
config_context()
instead.Parameters: config_dict (dict) – the dictionary from which to use the configurations
-
ybe.configuration.
load_from_yaml
(yaml_str)[source]¶ Can be called to use configuration options from a YAML string.
This will update the current configuration with the new options.
Please note that this will change the global configuration, i.e. this is a persistent change. If you do not want a persistent state change, consider using
config_context()
instead.Parameters: yaml_str (str) – The string containing the YAML config to parse.
-
ybe.configuration.
load_specific
(file_name)[source]¶ Can be called by the application to use the config from a specific file.
This assumes that the given file contains YAML content, that is, we want to process it with the function load_from_yaml().
Please note that the last configuration loaded overwrites the values of the previously loaded config files.
Also, please note that this will change the global configuration, i.e. this is a persistent change. If you do not want a persistent state change, consider using
config_context()
instead.Parameters: file_name (str) – The name of the file to use.
-
ybe.configuration.
set_config_option
(option_name, value)[source]¶ Set the current configuration option for the given option name.
This will overwrite the current configuration for that option with the given value. Be careful, this will change the global configuration value.
Provided values should be objects and not YAML strings. For updating the configuration with YAML strings, please use the function
load_from_yaml()
.Parameters: - option_name (list of str or str) – the name of the option, or a path to the option.
- value – the object to set for that option
Returns: the raw configuration value defined for that option
Return type: object
-
ybe.configuration.
update_write_config
(config_file, update_dict)[source]¶ Update a given configuration file with updated values.
If the configuration file does not exist, a new one is created.
Parameters: - config_file (str) – the location of the config file to update
- update_dict (dict) – the items to update in the config file