Utils#

The Utils module contains several service functions that are commonly used throughout the framework. These functions provide a variety of utility functionality.

pretty_format_component_info_dict(service, show_extra_handlers, offset='', extra_handlers_key='extra_handlers', type_key='type', name_key='name', indent=4)[source]#

Function for dumping any pipeline components info dictionary (received from info_dict property) as a string. Resulting string is formatted with YAML-like format, however it’s not strict and shouldn’t be parsed. However, most preferable usage is via pipeline.pretty_format.

Parameters:
  • service (dict) – (required) Pipeline components info dictionary.

  • show_wrappers – (required) Whether to include Wrappers or not (could be many and/or generated).

  • offset (str) – Current level new line offset.

  • wrappers_key – Key that is mapped to Wrappers lists.

  • type_key (str) – Key that is mapped to components type name.

  • name_key (str) – Key that is mapped to components name.

  • indent (int) – Current level new line offset (whitespace number).

Return type:

str

Returns:

Formatted string

rename_component_incrementing(service, collisions)[source]#

Function for generating new name for a pipeline component, that has similar name with other components in the same group. The name is generated according to these rules:

  • If service’s handler is “ACTOR”, it is named actor.

  • If service’s handler is Callable, it is named after this callable.

  • If it’s a service group, it is named service_group.

  • Otherwise, it is names noname_service.

  • After that, _[NUMBER] is added to the resulting name, where _[NUMBER] is number of components with the same name in current service group.
Parameters:
Return type:

str

Returns:

Generated name

finalize_service_group(service_group, path='.')[source]#

Function that iterates through a service group (and all its subgroups), finalizing component’s names and paths in it. Components are renamed only if user didn’t set a name for them. Their paths are also generated here. It also searches for “ACTOR” in the group, throwing exception if no actor or multiple actors found.

Parameters:
  • service_group (ServiceGroup) – Service group to resolve name collisions in.

  • path (str) – A prefix for component paths – path of component is equal to {path}.{component.name}. Defaults to “.”.

Return type:

bool