Skip to content

convoke.mountpoints

Tools for registering Base plugins

convoke.mountpoints.Mountpoint

A Mountpoint, subclassed, provides a place to register objects for a particular use.

This registration collaborates with Base.

Source code in src/convoke/mountpoints.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@dataclass
class Mountpoint:
    """A Mountpoint, subclassed, provides a place to register objects for a particular use.

    This registration collaborates with [`Base`][convoke.bases.Base].
    """

    mounted: list = field(default_factory=list)

    _mountpoints: ClassVar[list[Type[Mountpoint]]] = []

    def __init_subclass__(cls):
        cls._mountpoints.append(cls)
        cls.registry = []

    @classmethod
    def register(cls, func):
        """Register the given function for use with the mountpoint.

        This registration collaborates with [`Base`][convoke.bases.Base].
        """
        mp = getattr(func, "__mountpoints__", [])
        mp.append(cls)
        func.__mountpoints__ = mp
        return func

    def mount(self, func):
        """Mount a registered function on this instance."""
        self.mounted.append(func)

mount(func)

Mount a registered function on this instance.

Source code in src/convoke/mountpoints.py
34
35
36
def mount(self, func):
    """Mount a registered function on this instance."""
    self.mounted.append(func)

register(func) classmethod

Register the given function for use with the mountpoint.

This registration collaborates with Base.

Source code in src/convoke/mountpoints.py
23
24
25
26
27
28
29
30
31
32
@classmethod
def register(cls, func):
    """Register the given function for use with the mountpoint.

    This registration collaborates with [`Base`][convoke.bases.Base].
    """
    mp = getattr(func, "__mountpoints__", [])
    mp.append(cls)
    func.__mountpoints__ = mp
    return func