Skip to content

Commit

Permalink
fix: join generate argument with current template
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 22, 2021
1 parent 041d1ed commit 074ee28
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions beet/contrib/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
def beet_default(ctx: Context):
config = ctx.meta.get("scoreboard", cast(JsonDict, {}))

function = config.get("function", "{namespace}:{path}scoreboard")
function = config.get("function", "scoreboard")
tags = config.get("tags", ["minecraft:load"])

ctx.require(scoreboard(function, tags))


def scoreboard(
function: str = "{namespace}:{path}scoreboard",
function: str = "scoreboard",
tags: Iterable[str] = ("minecraft:load",),
) -> Plugin:
"""Return a plugin that adds generated scoreboards to the data pack."""
Expand Down
11 changes: 5 additions & 6 deletions beet/toolchain/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def format(self, fmt: str, hash: Optional[StableHashable] = None) -> str:
@overload
def __call__(
self,
template: str,
fmt: str,
file_instance: NamespaceFile,
*,
hash: Optional[StableHashable] = None,
Expand All @@ -93,18 +93,17 @@ def __call__(

def __call__(self, *args: Any, hash: Optional[StableHashable] = None) -> Any:
if len(args) == 2:
template, file_instance = args
fmt, file_instance = args
else:
file_instance = args[0]
template = self.ctx.meta.get(
"generate_format", "{namespace}:{path}generated_{incr}"
)
fmt = "generated_{incr}"

if hash is None:
hash = lambda: file_instance.ensure_serialized()

template = self.ctx.meta.get("generate_file", "{namespace}:{path}")
file_type = type(file_instance)
key = self[file_type].format(template, hash)
key = self[file_type].format(template + fmt, hash)

if file_type in self.ctx.data.namespace_type.field_map:
self.ctx.data[key] = file_instance
Expand Down
14 changes: 7 additions & 7 deletions examples/code_context_generator/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def beet_default(ctx: Context):
with ctx.override(generate_prefix="thing"):
ctx.generate(Function(["say thing"]))

with ctx.override(generate_format="other:{namespace}/{incr}_{hash}"):
with ctx.override(generate_file="other:{namespace}/"):
for j in range(3):
ctx.generate["fish"]["zombie"](Function([f"say {i}{j}"]))
ctx.generate["foo"]("{incr}_{hash}", Function([f"say {i}{j}"]))

key = ctx.generate(
"{namespace}:generated/{short_hash}", Function([f"say {i}"])
)
with ctx.override(generate_file="{namespace}:generated/"):
key = ctx.generate("{short_hash}", Function([f"say {i}"]))

ctx.generate["a"]["b"](Function(["say c", f"function {key}"]))

ctx.generate("creeper{incr}:boom", Function(["say boom"]))
with ctx.override(generate_file="creeper{incr}:"):
ctx.generate("boom", Function(["say boom"]))

ctx.generate["nested"](
"{namespace}:{path}{hash}",
"{hash}",
Function(["say hello"]),
hash=f"something/other thing, {i} blah",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/code_scoreboard/beet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"pipeline": ["demo", "beet.contrib.scoreboard"],
"meta": {
"scoreboard": {
"function": "{namespace}:add_objectives"
"function": "add_objectives"
}
}
}

0 comments on commit 074ee28

Please sign in to comment.