mafw.lazy_import

This module provides classes for lazy importing of plugins, ensuring thread-safe access and transparent usage.

Classes:
  • LazyImportPlugin: A generic class for lazy importing of plugin classes.

  • LazyImportProcessor: A specialised class for lazy importing of Processor plugins.

  • LazyImportUserInterface: A specialised class for lazy importing of UserInterface plugins.

Protocols:
  • ProcessorClassProtocol: Defines the expected interface for Processor classes.

  • UserInterfaceClassProtocol: Defines the expected interface for UserInterface classes.

Added in version v2.0.0.

Module Attributes

T

The class type to be used for the generic lazy import plugin.

R

The instance type to be used for the generic lazy import plugin.

Classes

LazyImportPlugin(module, class_name)

Proxy object that lazily imports a plugin class only when accessed.

LazyImportProcessor(module, class_name)

Lazy import proxy for Processor classes.

LazyImportUserInterface(module, class_name, ...)

Lazy import proxy for UserInterface classes.

ProcessorClassProtocol(*args, **kwargs)

Protocol for Processor classes.

UserInterfaceClassProtocol(*args, **kwargs)

Protocol for UserInterface classes.

class mafw.lazy_import.LazyImportPlugin(module: str, class_name: str)[source]

Bases: Generic[T, R], ABC

Proxy object that lazily imports a plugin class only when accessed. Thread-safe and transparent to the user.

Added in version v2.0.0.

Constructor parameter:

Parameters:
  • module (str) – The module name where the class is located.

  • class_name (str) – The name of the class to be lazily imported.

_load() Type[T][source]

Load the class from the specified module.

Returns:

The loaded class type.

Return type:

Type[T]

abstractmethod _post_load(cls: Type[T]) Type[T][source]

Perform operations after loading the class.

Parameters:

cls (Type[T]) – The class type that has been loaded.

Returns:

The class type after post-load operations.

Return type:

Type[T]

class mafw.lazy_import.LazyImportProcessor(module: str, class_name: str)[source]

Bases: LazyImportPlugin[Processor, Processor]

Lazy import proxy for Processor classes.

Added in version v2.0.0.

Constructor parameter:

Parameters:
  • module (str) – The module name where the class is located.

  • class_name (str) – The name of the class to be lazily imported.

_post_load(cls: Type[Processor]) Type[Processor][source]

Perform operations after loading the Processor class.

Parameters:

cls (Type[Processor]) – The Processor class type that has been loaded.

Returns:

The Processor class type after post-load operations.

Return type:

Type[Processor]

class mafw.lazy_import.LazyImportUserInterface(module: str, class_name: str, ui_name: str)[source]

Bases: LazyImportPlugin[UserInterfaceBase, UserInterfaceBase]

Lazy import proxy for UserInterface classes.

Added in version v2.0.0.

Constructor parameter:

Parameters:
  • module (str) – The module name where the class is located.

  • class_name (str) – The name of the class to be lazily imported.

  • ui_name (str) – The expected name of the user interface.

_post_load(cls: Type[UserInterfaceBase]) Type[UserInterfaceBase][source]

Perform operations after loading the UserInterface class.

Parameters:

cls (Type[UserInterfaceBase]) – The UserInterface class type that has been loaded.

Returns:

The UserInterface class type after post-load operations.

Return type:

Type[UserInterfaceBase]

Raises:

ValueError – If the class name is inconsistent with the expected name.

class mafw.lazy_import.ProcessorClassProtocol(*args, **kwargs)[source]

Bases: Protocol

Protocol for Processor classes.

Added in version v2.0.0.

Variables:
  • plugin_name – The name of the plugin.

  • plugin_qualname – The qualified name of the plugin.

  • __name__ – The name of the class.

class mafw.lazy_import.R

The instance type to be used for the generic lazy import plugin.

alias of TypeVar(‘R’)

class mafw.lazy_import.T

The class type to be used for the generic lazy import plugin.

alias of TypeVar(‘T’)

class mafw.lazy_import.UserInterfaceClassProtocol(*args, **kwargs)[source]

Bases: Protocol

Protocol for UserInterface classes.

Added in version v2.0.0.

Variables:
  • plugin_name – The name of the plugin.

  • plugin_qualname – The qualified name of the plugin.

  • name – The name of the user interface.