Skip to content

Commit

Permalink
feat: add plugin autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Mar 13, 2021
1 parent 5e6563e commit 9cac58e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions beet/toolchain/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from copy import deepcopy
from dataclasses import dataclass
from importlib.metadata import entry_points
from pathlib import Path
from typing import Iterable, Iterator, List, Optional, Sequence
from typing import ClassVar, Iterable, Iterator, List, Optional, Sequence

from beet.contrib.render import render
from beet.core.cache import MultiCache
Expand Down Expand Up @@ -189,10 +190,17 @@ class ProjectBuilder:
project: Project
config: ProjectConfig

autoload: ClassVar[Optional[List[str]]] = None

def __init__(self, project: Project):
self.project = project
self.config = self.project.config

if ProjectBuilder.autoload is None:
ProjectBuilder.autoload = [
ep.value for ep in entry_points()["beet"] if ep.name == "autoload"
]

def build(self) -> Context:
"""Create the context, run the pipeline, and return the context."""

Expand Down Expand Up @@ -232,7 +240,9 @@ def build(self) -> Context:

def bootstrap(self, ctx: Context):
"""Plugin that handles the project configuration."""
for plugin in self.config.require:
plugins = (self.autoload or []) + self.config.require

for plugin in plugins:
ctx.require(plugin)

pack_configs = [self.config.resource_pack, self.config.data_pack]
Expand Down

0 comments on commit 9cac58e

Please sign in to comment.