craftr.core.plugin

craftr.core.plugin.default

DefaultPluginLoader Objects

@dataclass
class DefaultPluginLoader(IPluginLoader)

Default implementation for loading plugins via the craftr.plugins entrypoint.

craftr.core.plugin.api

TaskFactory Objects

class TaskFactory(t.Generic[T_Task])

This is a helper class that wraps a Task subclass to act as a factory for that class. It is used as a convenience when registering a task as an extension to a Project such that it can be used to define a default task as well as defining a custom named task of the type.

def apply(project: Project, name: str) -> None:
  project.register_extension('myTaskType', TaskFactory(project, 'myTaskType', MyTaskType))

Inside a project, the task can then be instantiated with a configuration closure, and optionally with a custom task name.

myTaskType {
  # ...
}
myTaskType('otherTaskName') {
  # ...
}

assert 'myTaskType' in tasks
assert 'otherTaskName' in tasks

__call__

 | __call__(arg: t.Union[str, Closure], closure: t.Optional[Closure] = None) -> T_Task

Create a new instance of the task type. If a string is specified, it will be used as the task name. If a closure is specified, the default task name will be used and the task will be configured with the closure.

Namespace Objects

class Namespace(Configurable)

Represents a namespace that is directly associated with a project. Plugins register members to the namespace with the add() method or TaskFactorys with the add_task_factory() method.

IPlugin Objects

@t.runtime_checkable
class IPlugin(t.Protocol, metaclass=abc.ABCMeta)

apply

 | @abc.abstractmethod
 | apply(project: 'Project', namespace: Namespace) -> t.Any

Apply the plugin to the given project and register members to the given namespace.

IPluginLoader Objects

@t.runtime_checkable
class IPluginLoader(t.Protocol, metaclass=abc.ABCMeta)

load_plugin

 | @abc.abstractmethod
 | load_plugin(plugin_name: str) -> IPlugin

Load the given plugin by name.