Skip to content

Commit

Permalink
fix: no longer rely on pack attributes for render plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 12, 2022
1 parent e9c487c commit 6636094
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions beet/contrib/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pydantic import BaseModel

from beet import Context, configurable
from beet.core.utils import snake_case


class RenderOptions(BaseModel):
Expand All @@ -26,15 +27,25 @@ def beet_default(ctx: Context):
@configurable(validator=RenderOptions)
def render(ctx: Context, opts: RenderOptions):
"""Plugin that processes the data pack and the resource pack with Jinja."""

for groups, pack in zip([opts.resource_pack, opts.data_pack], ctx.packs):
file_types = {
file_type for namespace in pack.values() for file_type in namespace
}

group_map = {
snake_case(file_type.__name__): file_type for file_type in file_types
}
for singular in list(group_map):
group_map[f"{singular}s"] = group_map[singular]

for group, patterns in groups.items():
try:
proxy = getattr(pack, group)
file_type = group_map[group]
proxy = pack[file_type]
file_paths = proxy.match(*patterns)
except:
raise ValueError(f"Invalid render group {group!r}.") from None
else:
for path in file_paths:
with ctx.override(render_path=path, render_group=group):
ctx.template.render_file(proxy[path])
ctx.template.render_file(proxy[path]) # type: ignore

0 comments on commit 6636094

Please sign in to comment.