Skip to content

PluginMount

PluginMount

PluginMount(name, bases, attrs)

Bases: ABCMeta

Source code in src/spf/PluginMount.py
def __init__(
    cls: Any, name: str, bases: List[Any], attrs: List[Any]
) -> None:  # sourcery skip: instance-method-first-arg-name
    if not hasattr(cls, "plugins"):
        # This branch only executes when processing the mount point itself.
        # So, since this is a new plugin type, not an implementation, this
        # class shouldn't be registered as a plugin. Instead, it sets up a
        # list where plugins can be registered later.
        cls.plugins = {}
    else:
        # This must be a plugin implementation, which should be registered.
        # Simply appending it to the list is all that's needed to keep
        # track of it later.
        cls.verify()
        cls.plugins[cls.__name__] = cls

load()

Loads all plugins registered under the specified entry point.

RETURNS DESCRIPTION
None

Examples:

>>> MyMountPoint.load()
Source code in src/spf/PluginMount.py
def load(cls) -> None:  # sourcery skip: instance-method-first-arg-name
    """Loads all plugins registered under the specified entry point.

    Returns
    -------
    None

    Examples
    --------
    >>> MyMountPoint.load()
    """
    if cls == PluginMount:
        return None

    eps = (
        pkg_resources.iter_entry_points(cls.entry_point)
        if USE_LEGACY
        else entry_points().select(group=cls.entry_point)
    )

    for ep in eps:
        ep.load()

verify()

Verifies that the required static properties are implemented by the class.

RAISES DESCRIPTION
NotImplementedError

If any of the required static properties are not implemented.

Examples:

>>> MyMountPoint.verify()
Source code in src/spf/PluginMount.py
def verify(cls):  # sourcery skip: instance-method-first-arg-name
    """Verifies that the required static properties are implemented by the class.

    Raises
    ------
    NotImplementedError
        If any of the required static properties are not implemented.

    Examples
    --------

    >>> MyMountPoint.verify()
    """
    base = cls.__mro__[-2]
    if not_implemented := set(cls.REQUIRED_STATIC_PROPERTIES) - set(base.__dict__.keys()):
        raise NotImplementedError(
            f"Attribute(s) {not_implemented} not implemented by class {base.__name__}"
        )