Skip to content

Commit 3d4b114

Browse files
committed
[BREAKING] update pyproject label to tool.render-engine
1 parent c5cb1a7 commit 3d4b114

File tree

3 files changed

+545
-504
lines changed

3 files changed

+545
-504
lines changed

src/render_engine_cli/utils.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,25 @@ def load_config(self, config_file: str = CONFIG_FILE_NAME):
4848
try:
4949
with open(config_file) as stored_config_file:
5050
try:
51-
stored_config = toml.load(stored_config_file).get("render-engine", {}).get("cli", {})
51+
stored_config = (
52+
toml.load(stored_config_file)
53+
.get("tool.render-engine", {})
54+
.get("cli", {})
55+
)
5256
except TomlDecodeError as exc:
53-
click.echo(f"Encountered an error while parsing {config_file} - {exc}.")
57+
click.echo(
58+
f"Encountered an error while parsing {config_file} - {exc}."
59+
)
5460
else:
5561
click.echo(f"Config loaded from {config_file}")
5662
except FileNotFoundError:
5763
click.echo(f"No config file found at {config_file}")
5864

5965
if stored_config:
6066
# Populate the argument variables and default values from the config
61-
if (module := stored_config.get("module")) and (site := stored_config.get("site")):
67+
if (module := stored_config.get("module")) and (
68+
site := stored_config.get("site")
69+
):
6270
self._module_site = f"{module}:{site}"
6371
if default_collection := stored_config.get("collection"):
6472
self._collection = default_collection
@@ -76,7 +84,9 @@ def get_site(import_path: str, site: str, reload: bool = False) -> Site:
7684
def get_site_content_paths(site: Site) -> list[Path | str | None]:
7785
"""Get the content paths from the route_list in the Site"""
7886

79-
base_paths = map(lambda x: getattr(x, "content_path", None), site.route_list.values())
87+
base_paths = map(
88+
lambda x: getattr(x, "content_path", None), site.route_list.values()
89+
)
8090
base_paths = list(filter(None, base_paths))
8191
base_paths.extend(site.static_paths)
8292
if site.template_path:
@@ -114,7 +124,9 @@ def get_available_themes(console: Console, site: Site, theme_name: str) -> list[
114124

115125
def create_collection_entry(content: str | None, collection: Collection, **context):
116126
"""Creates a new entry for a collection"""
117-
return collection.Parser.create_entry(content=content, **collection._metadata_attrs(), **context)
127+
return collection.Parser.create_entry(
128+
content=content, **collection._metadata_attrs(), **context
129+
)
118130

119131

120132
def split_args(args: list[str] | None) -> dict[str, str]:
@@ -137,7 +149,9 @@ def split_args(args: list[str] | None) -> dict[str, str]:
137149
return split_arguments
138150

139151

140-
def display_filtered_templates(title: str, templates_list: list[str], filter_value: str) -> None:
152+
def display_filtered_templates(
153+
title: str, templates_list: list[str], filter_value: str
154+
) -> None:
141155
"""Display filtered templates based on a given filter value."""
142156
table = Table(title=title)
143157
table.add_column("[bold blue]Templates[bold blue]")
@@ -156,7 +170,9 @@ def validate_module_site(ctx: dict, param: str, value: str) -> str:
156170
config = CliConfig()
157171
if config.module_site and split_module_site(config.module_site):
158172
return config.module_site
159-
raise click.exceptions.BadParameter("module_site must be in the form of module:site")
173+
raise click.exceptions.BadParameter(
174+
"module_site must be in the form of module:site"
175+
)
160176

161177

162178
def validate_collection(ctx: dict, param: click.Option, value: str) -> str:
@@ -168,17 +184,25 @@ def validate_collection(ctx: dict, param: click.Option, value: str) -> str:
168184
raise click.exceptions.BadParameter("collection must be specified.")
169185

170186

171-
def validate_file_name_or_slug(ctx: click.Context, param: click.Option, value: str) -> str | None:
187+
def validate_file_name_or_slug(
188+
ctx: click.Context, param: click.Option, value: str
189+
) -> str | None:
172190
if value:
173191
if " " in value:
174-
raise click.exceptions.BadParameter(f"Spaces are not allowed in {param.name}.")
192+
raise click.exceptions.BadParameter(
193+
f"Spaces are not allowed in {param.name}."
194+
)
175195
click.echo(f"Setting {param.name} to {value}")
176196
return value
177-
if (title_or_slug := ctx.params.get("title")) or (title_or_slug := ctx.params.get("slug")):
197+
if (title_or_slug := ctx.params.get("title")) or (
198+
title_or_slug := ctx.params.get("slug")
199+
):
178200
slugged = slugify(title_or_slug)
179201
value = slugged + ".md" if param.name == "filename" else slugged
180202
click.echo(f"Setting {param.name} to {value}")
181203
return value
182204
if param.name == "filename":
183-
raise click.exceptions.BadParameter("One of filename, title, or slug must be provided.")
205+
raise click.exceptions.BadParameter(
206+
"One of filename, title, or slug must be provided."
207+
)
184208
return None

tests/test_cli.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def test_import_lib_gets_site():
5858
def test_collection_call():
5959
"""Tests that you can get content from the parser using `new_entry`"""
6060
test_collection = Collection()
61-
content = create_collection_entry(content=None, collection=test_collection, foo="bar")
61+
content = create_collection_entry(
62+
content=None, collection=test_collection, foo="bar"
63+
)
6264
post = frontmatter.loads(content)
6365

6466
assert post["title"] == "Untitled Entry"
@@ -68,7 +70,9 @@ def test_collection_call():
6870
def test_collection_call_with_content():
6971
"""Tests that you can get content from the parser using `new_entry`"""
7072
test_collection = Collection()
71-
content = create_collection_entry(content="This is a test", collection=test_collection, foo="bar")
73+
content = create_collection_entry(
74+
content="This is a test", collection=test_collection, foo="bar"
75+
)
7276
post = frontmatter.loads(content)
7377

7478
assert post["title"] == "Untitled Entry"
@@ -81,7 +85,10 @@ def test_collection_call_with_content():
8185
[
8286
(["key1=value1", "key2=value2"], {"key1": "value1", "key2": "value2"}),
8387
(["key1:value1", "key2:value2"], {"key1": "value1", "key2": "value2"}),
84-
(["author=John Doe", "tags:python,testing"], {"author": "John Doe", "tags": "python,testing"}),
88+
(
89+
["author=John Doe", "tags:python,testing"],
90+
{"author": "John Doe", "tags": "python,testing"},
91+
),
8592
([], {}),
8693
(None, {}),
8794
],
@@ -103,7 +110,11 @@ def test_split_args_error_handling():
103110

104111
def test_config_loading_with_valid_config(tmp_path, monkeypatch):
105112
"""Tests config loading from pyproject.toml (2025.5.1b1 feature)"""
106-
config_content = {"render-engine": {"cli": {"module": "myapp", "site": "MySite", "collection": "MyCollection"}}}
113+
config_content = {
114+
"tool.render-engine": {
115+
"cli": {"module": "myapp", "site": "MySite", "collection": "MyCollection"}
116+
}
117+
}
107118

108119
config_file = tmp_path / "pyproject.toml"
109120
config_file.write_text(toml.dumps(config_content))
@@ -145,7 +156,10 @@ def test_collection_entry_with_custom_attributes():
145156
"""Tests that custom attributes are passed through to collection entry"""
146157
test_collection = Collection()
147158
content = create_collection_entry(
148-
content="Test content", collection=test_collection, author="Test Author", tags="test,example"
159+
content="Test content",
160+
collection=test_collection,
161+
author="Test Author",
162+
tags="test,example",
149163
)
150164
post = frontmatter.loads(content)
151165

@@ -169,7 +183,9 @@ def test_split_module_site_invalid():
169183
"""Tests split_module_site with invalid input"""
170184
import click
171185

172-
with pytest.raises(click.exceptions.BadParameter, match="module_site must be of the form"):
186+
with pytest.raises(
187+
click.exceptions.BadParameter, match="module_site must be of the form"
188+
):
173189
split_module_site("invalid_format")
174190

175191

0 commit comments

Comments
 (0)