mafw.plugin_manager

Plugin management system for MAFw framework.

This module provides the core functionality for loading and managing plugins within the MAFw framework. It supports loading various types of plugins including processors, standard tables, database models, and user interfaces.

The plugin manager uses the pluggy library to handle plugin discovery and registration through entry points and hooks.

When plugins are loaded using the MAFwPluginManager.load_plugins() function, the job is divided into multiple threads to improve performance.

Key features:
  • Asynchronous plugin loading with progress indication

  • Support for both internal and external plugins

  • Type-safe plugin handling with proper data structures

  • Logging integration for monitoring plugin loading processes

  • Global plugin manager singleton for consistent access

The module defines several key components:
Plugin types supported:
  • Processors (processors): Classes that implement data processing logic

  • Database Modules (db_modules): Model modules for database interaction

  • User Interfaces (ui): UI implementations for different interfaces

Changed in version v2.0.0: Complete refactoring of the plugin manager system.

Module Attributes

PluginTypes

Type alias for accepted types of plugins.

global_mafw_plugin_manager

The global mafw plugin manager dictionary.

Functions

get_plugin_manager([force_recreate])

Create a new or return an existing plugin manager for a given project

Classes

LoadedPlugins(processor_list, ...)

Container class for storing loaded plugins of various types.

MAFwPluginManager([project_name])

The MAFw plugin manager.

class mafw.plugin_manager.LoadedPlugins(processor_list: ~typing.List[~mafw.lazy_import.ProcessorClassProtocol] = <factory>, processor_dict: ~typing.Dict[str, ~mafw.lazy_import.ProcessorClassProtocol] = <factory>, db_model_modules: ~typing.List[str] = <factory>, ui_list: ~typing.List[~mafw.lazy_import.UserInterfaceClassProtocol] = <factory>, ui_dict: ~typing.Dict[str, ~mafw.lazy_import.UserInterfaceClassProtocol] = <factory>)[source]

Bases: object

Container class for storing loaded plugins of various types.

This dataclass holds collections of different plugin types that have been loaded by the MAFwPluginManager. It provides organized storage for processors, database modules, and user interfaces.

Added in version v2.0.0.

db_model_modules: List[str]

List of database model module names.

processor_dict: Dict[str, ProcessorClassProtocol]

Dictionary mapping processor names to their classes.

processor_list: List[ProcessorClassProtocol]

List of loaded processor classes.

ui_dict: Dict[str, UserInterfaceClassProtocol]

Dictionary mapping user interface names to their classes.

ui_list: List[UserInterfaceClassProtocol]

List of loaded user interface classes.

class mafw.plugin_manager.MAFwPluginManager(project_name: str = 'mafw')[source]

Bases: PluginManager

The MAFw plugin manager.

The MAFwPluginManager class manages the loading and registration of plugins within the MAFw framework. It supports asynchronous loading of various plugin types, including processors, database modules, and user interfaces, using a thread pool executor for improved performance.

The class provides methods to load each type of plugin and handles delayed status messages if loading takes longer than expected.

Added in version v2.0.0.

_delayed_status_message(futures: List[Future[Any]]) None[source]

Display a warning message if plugin loading takes longer than expected.

This method is called after a delay to check if all plugin loading operations have completed. If not, it logs a warning message to inform the user that plugin loading is taking longer than expected.

Parameters:

futures (list[concurrent.futures.Future]) – List of futures representing ongoing plugin loading operations

load_db_models_plugins() list[str][source]

Load database model modules from the plugin manager.

This method retrieves all database model modules registered through the plugin manager’s register_db_model_modules() hook and imports them.

Returns:

List of database model module names

Return type:

list[str]

load_plugins(plugins_to_load: Iterable[Literal['processors', 'db_modules', 'ui']]) LoadedPlugins[source]

Load plugins of specified types in multiple threads.

This method loads plugins of the specified types using a thread pool executor for improved performance. It handles different plugin types including processors, standard tables, database modules, and user interfaces.

Parameters:

plugins_to_load (Iterable[PluginTypes]) – Iterable of plugin types to load

Returns:

Container with loaded plugins of all requested types

Return type:

LoadedPlugins

load_processor_plugins() Tuple[List[ProcessorClassProtocol], Dict[str, ProcessorClassProtocol]][source]

Load available processor plugins from the plugin manager.

This method retrieves all processor plugins registered through the plugin manager’s register_processors() hook. register_processors() hook.

Returns:

A tuple containing: - List of available processor classes - Dictionary mapping processor names to their classes

Return type:

tuple[list[type[Processor]], dict[str, type[Processor]]]

load_user_interface_plugins() Tuple[List[UserInterfaceClassProtocol], Dict[str, UserInterfaceClassProtocol]][source]

Load available user interface plugins from the plugin manager.

This method retrieves all user interface plugins registered through the plugin manager’s register_user_interfaces() hook.

Returns:

A tuple containing: - List of available user interface classes - Dictionary mapping user interface names to their classes

Return type:

tuple[list[type[UserInterfaceBase]], dict[str, type[UserInterfaceBase]]]

max_loading_delay = 1

Loading delay before displaying a message.

If the loading of the external plugins is taking more than this value, a message is displayed to inform the user.

mafw.plugin_manager._as_db_module_result(obj: object) list[str][source]

Cast an object to the expected database module result type.

This helper function is used to convert the raw result from plugin loading operations into the expected list format for database modules.

Added in version v2.0.0.

Parameters:

obj (object) – The object to cast

Returns:

A list of database module names

Return type:

list[str]

mafw.plugin_manager._as_processor_result(obj: object) tuple[list[ProcessorClassProtocol], dict[str, ProcessorClassProtocol]][source]

Cast an object to the expected processor result type.

This helper function is used to convert the raw result from plugin loading operations into the expected tuple format for processors.

Added in version v2.0.0.

Parameters:

obj (object) – The object to cast

Returns:

A tuple containing a list of processor classes and a dictionary mapping processor names to their classes

Return type:

tuple[list[ProcessorClassProtocol], dict[str, ProcessorClassProtocol]]

mafw.plugin_manager._as_ui_result(obj: object) tuple[list[UserInterfaceClassProtocol], dict[str, UserInterfaceClassProtocol]][source]

Cast an object to the expected UI result type.

This helper function is used to convert the raw result from plugin loading operations into the expected tuple format for user interfaces.

Added in version v2.0.0.

Parameters:

obj (object) – The object to cast

Returns:

A tuple containing a list of UI classes and a dictionary mapping UI names to their classes

Return type:

tuple[list[UserInterfaceClassProtocol], dict[str, UserInterfaceClassProtocol]]

mafw.plugin_manager.get_plugin_manager(force_recreate: bool = False) MAFwPluginManager[source]

Create a new or return an existing plugin manager for a given project

Parameters:

force_recreate (bool, Optional) – Flag to force the creation of a new plugin manager. Defaults to False

Returns:

The plugin manager

Return type:

pluggy.PluginManager

mafw.plugin_manager.PluginTypes

Type alias for accepted types of plugins.

alias of Literal[‘processors’, ‘db_modules’, ‘ui’]

mafw.plugin_manager.global_mafw_plugin_manager: dict[str, MAFwPluginManager] = {}

The global mafw plugin manager dictionary.