Skip to content

Commit

Permalink
fix: separate normalized project id into its own context attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jun 15, 2021
1 parent 34d7852 commit 1487fcf
Show file tree
Hide file tree
Showing 24 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion beet/contrib/lantern_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def beet_default(ctx: Context):
# The id defaults to the project name and the version to the project version.
config = ctx.meta.get("lantern_load", cast(JsonDict, {}))

id = config.get("id", ctx.project_name)
id = config.get("id", ctx.project_id)
version = config.get("version", ctx.project_version)
dependencies = config.get("dependencies", cast(JsonDict, {}))

Expand Down
2 changes: 2 additions & 0 deletions beet/toolchain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def with_defaults(self, other: "PackConfig") -> "PackConfig":
class ProjectConfig(BaseModel):
"""Beet project configuration."""

id: str = ""
name: str = ""
description: TextComponent = ""
author: str = ""
Expand Down Expand Up @@ -115,6 +116,7 @@ def resolve(self, directory: FileSystemPath) -> "ProjectConfig":
def with_defaults(self, other: "ProjectConfig") -> "ProjectConfig":
"""Combine the current project config with another one."""
return ProjectConfig(
id=self.id or other.id,
name=self.name or other.name,
description=self.description or other.description,
author=self.author or other.author,
Expand Down
1 change: 1 addition & 0 deletions beet/toolchain/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def flush(self):
class Context:
"""The build context."""

project_id: str
project_name: str
project_description: TextComponent
project_author: str
Expand Down
4 changes: 2 additions & 2 deletions beet/toolchain/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ def get_prefix(self, separator: str = ".") -> str:

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)
key = (self.ctx.project_id, *self.scope, *key)
count = self.registry[key]
self.registry[key] += 1
return count

def format(self, fmt: str, hash: Any = None) -> str:
"""Generate a unique key depending on the given template."""
env = {
"namespace": self.ctx.meta.get("generate_namespace", self.ctx.project_name),
"namespace": self.ctx.meta.get("generate_namespace", self.ctx.project_id),
"path": LazyFormat(lambda: self.get_prefix("/")),
"scope": LazyFormat(lambda: self.get_prefix()),
"incr": LazyFormat(lambda: self.get_increment(fmt)),
Expand Down
1 change: 1 addition & 0 deletions beet/toolchain/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def sandbox(*specs: PluginSpec) -> Plugin:

def plugin(ctx: Context):
child_ctx = Context(
project_id=ctx.project_id,
project_name=ctx.project_name,
project_description=ctx.project_description,
project_author=ctx.project_author,
Expand Down
7 changes: 3 additions & 4 deletions beet/toolchain/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,12 @@ def __init__(self, project: Project):

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

name = self.config.name or self.project.directory.stem
normalized_name = normalize_string(name)

with self.project.worker_pool.handle() as worker_pool_handle:
ctx = Context(
project_name=normalized_name,
project_id=self.config.id or normalize_string(name),
project_name=name,
project_description=self.config.description,
project_author=self.config.author,
project_version=self.config.version,
Expand Down Expand Up @@ -308,7 +307,7 @@ def bootstrap(self, ctx: Context):
)

for config, suffix, pack in zip(pack_configs, pack_suffixes, ctx.packs):
default_name = ctx.project_name
default_name = ctx.project_id
if ctx.project_version:
default_name += "_" + ctx.project_version
default_name += suffix
Expand Down
1 change: 1 addition & 0 deletions beet/toolchain/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def resolve_or_missing(self, key: str) -> Any:
return manager.globals[key]

if key in [
"project_id",
"project_name",
"project_description",
"project_author",
Expand Down
3 changes: 2 additions & 1 deletion examples/code_description/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


def beet_default(ctx: Context):
ctx.project_name = "something_else"
ctx.project_id = "something_else"
ctx.project_name = "Something else"
ctx.project_description = {"text": "bold description", "bold": True}
ctx.project_author = "Fizzy"
ctx.project_version = "1.2.3"
Expand Down
3 changes: 2 additions & 1 deletion examples/code_metadata/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


def beet_default(ctx: Context):
ctx.project_name = "demo"
ctx.project_id = "demo"
ctx.project_name = "Demo"
ctx.project_description = "The description of my project"
ctx.project_author = "Example"
ctx.project_version = "1.7.4"
Expand Down
1 change: 1 addition & 0 deletions examples/code_metadata/templates/foo.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
say {{ project_id }}
say {{ project_name }}
say {{ project_description }}
say {{ project_author }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
say {{ project_id }}
say {{ project_name }}
say {{ project_description }}
say {{ project_author }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "my_project",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down Expand Up @@ -28,6 +29,7 @@
},
"pipeline": [
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down Expand Up @@ -66,6 +68,7 @@
"meta": {}
},
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down Expand Up @@ -107,6 +110,7 @@
"meta": {}
},
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "foo",
"description": "foo",
"author": "foo",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "my_project",
"description": "The description of my project",
"author": "N/A",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "foo",
"description": "",
"author": "",
Expand Down Expand Up @@ -30,6 +31,7 @@
},
"pipeline": [
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down Expand Up @@ -35,6 +36,7 @@
"bar",
"hello",
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down Expand Up @@ -71,6 +73,7 @@
"meta": {}
},
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down Expand Up @@ -104,6 +107,7 @@
"meta": {}
},
{
"id": "",
"name": "",
"description": "",
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
say demo
say Demo
say The description of my project
say Example
say 1.7.4
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
say demo
say demo
say The description of my project
say Example
say 1.7.4

0 comments on commit 1487fcf

Please sign in to comment.