Skip to content

Commit

Permalink
fix: don't increment registry keys unless {incr} is present
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 17, 2021
1 parent 00cd667 commit 9786c36
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions beet/toolchain/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ def get_prefix(self, separator: str = ".") -> str:
if part and isinstance(part, str)
)

def format(self, fmt: str, hash: Optional[StableHashable] = None) -> str:
"""Generate a unique key depending on the given template."""
key = (self.ctx.project_name, *self.scope, fmt)

def get_increment(self, *key: Any) -> int:
"""Return the current value for the given key and increment it."""
key = (self.ctx.project_name, *self.scope, *key)
count = self.registry[key]
self.registry[key] += 1
return count

def format(self, fmt: str, hash: Optional[StableHashable] = None) -> str:
"""Generate a unique key depending on the given template."""
env = {
"namespace": self.ctx.meta.get("generate_namespace", self.ctx.project_name),
"path": LazyFormat(lambda: self.get_prefix("/")),
"scope": LazyFormat(lambda: self.get_prefix()),
"incr": count,
"incr": LazyFormat(lambda: self.get_increment(fmt)),
}

if hash is not None:
Expand Down

0 comments on commit 9786c36

Please sign in to comment.