ModuleMix#

class ModuleMix(*args, **kwargs)#

Bases: Generic[T_Mod], Module

A module containing multiple other modules.

This can allow to combine modules to collect different sources, write multiple time in different manners, etc.

This is an abstract class and should be used as a base for creating specific mixes. This abstract class initialize every module in the mix. Mixes are intended to be instantiated with the class method create().

__getattr__(name)#

Dispatch to base module if they have the attribute defined.

This gets called if __getattribute__ fails, ie the attribute is not defined on this instance.

Parameters:

name (str)

Return type:

Any

__init__(*args, **kwargs)#
Return type:

None

__weakref__#

list of weak references to the object

_lines()#

Lines to show in DataManager repr (human readable).

Return type:

list[str]

apply(method: str, all: Literal[True], *args, select: dict[str, Any] | None = None, **kwargs) list[Any]#
apply(method: str, all: Literal[False], *args, select: dict[str, Any] | None = None, **kwargs) Any
apply(method: str, all: bool, *args, select: dict[str, Any] | None = None, **kwargs) Any | list[Any]

Get results from all or one of the base modules.

Parameters:
  • method (str) – Method name to run

  • all (bool) – If True, return results from all modules, otherwise only from a selected one.

  • args – Passed to the method

  • kwargs – Passed to the method

  • select (dict[str, Any] | None) – Mapping of parameters passed to the selection function.

Return type:

Any | list[Any]

apply_all(method, *args, **kwargs)#

Get results from every base module.

Every output is put in a list if not already.

Parameters:

method (str)

Return type:

list[Any]

apply_select(method, *args, select=None, **kwargs)#

Get result from a single base module.

Module is selected with select_func, based on current module and data-manager state.

Parameters:
  • method (str) – Method name to run

  • args – Passed to the method

  • kwargs – Passed to the method

  • select (dict[str, Any] | None) – Mapping of parameters passed to the selection function.

Return type:

list[Any]

base_modules: dict[str, T_Mod]#

List of module instances.

base_types: tuple[type[T_Mod], ...] = ()#

Tuple of types of the constituting modules.

classmethod create(bases, select_func=None)#

Create a new mix-class from base module.

bases

Module types to mix.

select_func

Function to select one of the base module depending on the current module state, and data-manager parameters. It receives the instance of the module mix and additional kwargs, and must return the class-name of one of the base module.

Parameters:
  • bases (abc.Sequence[type[T_Mod]])

  • select_func (abc.Callable[..., str] | None)

Return type:

type[T_Self]

select(**kwargs)#

Return the module to select under current module and data-manager state.

Parameters:

kwargs – Will be passed to the selection function.

Return type:

T_Mod

classmethod set_select(select_func)#

Set the selection function.

select_func

Function to select one of the base module depending on the current module state, and data-manager parameters. It receives the instance of the module mix and additional kwargs, and must return the class-name of one of the base module.

Parameters:

select_func (abc.Callable[..., str])

setup()#

Initialize module.

Return type:

None