Utility Functions#

The Utility Functions module contains several utility functions that are commonly used throughout the DFF. These functions provide a variety of utility functionality.

async wrap_sync_function_in_async(func, *args, **kwargs)[source]#

Utility function, that wraps both functions and coroutines in coroutines. Invokes func if it is just a callable and awaits, if this is a coroutine.

Parameters:
  • func (Callable) – Callable to wrap.

  • *args – Function args.

  • **kwargs – Function kwargs.

Return type:

Any

Returns:

What function returns.

_get_attrs_with_updates(obj, drop_attrs=None, replace_attrs=None, add_attrs=None)[source]#

Advanced customizable version of built-in __dict__ property. Sometimes during Pipeline construction Services (or ServiceGroups) should be rebuilt, e.g. in case of some fields overriding. This method can be customized to return a dict, that can be spread (** operator) and passed to Service or ServiceGroup constructor. Base dict is formed via vars built-in function. All “private” or “dunder” fields are omitted.

Parameters:
  • drop_attrs (Optional[Tuple[str, ...]]) – A tuple of key names that should be removed from the resulting dict.

  • replace_attrs (Optional[Mapping[str, str]]) – A mapping that should be replaced in the resulting dict.

  • add_attrs (Optional[Mapping[str, Any]]) – A mapping that should be added to the resulting dict.

Return type:

dict

Returns:

Resulting dict.

collect_defined_constructor_parameters_to_dict(**kwargs)[source]#

Function, that creates dict from non-None constructor parameters of pipeline component. It is used in overriding component parameters, when service handler or service group service is instance of Service or ServiceGroup (or dict). It accepts same named parameters as component constructor.

Returns:

Dict, containing key-value pairs of these parameters, that are not None.