grove.helpers package

Grove helpers.

Submodules

grove.helpers.parsing module

Provides helpers for parsing.

grove.helpers.parsing.quick_copy(value: Any)[source]

Performs a quick deep copy by marshalling and unmarshalling to JSON.

This operation, although strange, is significantly quicker than copy.deepcopy(). This has been moved into a helper to enable potential performance improvements in future without code changes in processors being required.

Parameters:

value – The value to perform a deep copy of.

Returns:

The deep copy of the input value.

grove.helpers.parsing.quote_aware_split(value: str, delimiter='.') List[str][source]

Splits a value by delimiter, returning a list.

This function is quote aware, ensuring that splitting will not occur inside of a value quoted with single-quotes.

Parameters:
  • value – The value to split.

  • delimiter – The delimiter to split using.

Returns:

A list of elements split from the input value.

grove.helpers.parsing.update_path(candidate: Dict[str, Any], path: List[str], value: Any, replace: bool = False) Dict[str, Any][source]

Updates or deletes values under the specified path for the provided candidate.

A path is a list of strings delimited string which express a location within the candidate data. If the location is not nested, a single element list should be provided.

As an example of this, a path of [“A”, “B”, “C”] expresses that the specified value should be set under {“A”: {“B”: {“C”: value } } } within the candidate dictionary.

This function recursively walks the provided candidate dictionary until the location specified by the path has been located. Once found, the provided value will perform on of the following operations:

  1. By default, the provided value will be combined with the existing value.

  2. If replace is True, the existing value will be replaced with the new.

  3. If None is provided as the new value, the specified path will be deleted.

Parameters:
  • candidate – The dictionary to update.

  • path – The path to the key to update, as a list of strings.

  • value – The value to assign to the destination path, or None to delete.

  • replace – Whether to replace the current value with the new value, or combine.

Returns:

The updated dictionary.

grove.helpers.parsing.validation_error(exc: ValidationError)[source]

Parse Pydantic validation exceptions into a user readable string.

Parameters:

exc – The Pydantic ValidationError to parse.

Returns:

The exception as a string, including fields with validation errors.

grove.helpers.plugin module

Provides helpers for plugin loading.

grove.helpers.plugin.load_handler(name: str, group: str, *args: Any, **kwargs: Any) Any[source]

Attempts to locate and load the requested plugin handler.

This is a convenience method which wrappers the lookup operation, and performs the load and instantiation required to hydrate a ‘real’ handler. Any additional arguments passed to load_handler are pass through to the handler during creation.

Parameters:
  • name – The name of the handler to load (e.g. ‘aws_ssm’).

  • group – The group the handler belongs to (e.g. ‘grove.outputs’).

grove.helpers.plugin.lookup_handler(name: str, group: str) EntryPoint[source]

Attempts to locate requested plugin handler.

This utilises setuptools entrypoints to allow handlers to register themselves for use by Grove.

Parameters:
  • name – The name of the handler to load (e.g. ‘aws_ssm’).

  • group – The group the handler belongs to (e.g. ‘grove.outputs’).

Raises:

ConfigurationException – The specified handler could not be located.