Skip to content

Commit 0b621db

Browse files
committed
ruff lint
1 parent 3d4b114 commit 0b621db

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

src/render_engine_cli/utils.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,17 @@ 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 = (
52-
toml.load(stored_config_file)
53-
.get("tool.render-engine", {})
54-
.get("cli", {})
55-
)
51+
stored_config = toml.load(stored_config_file).get("tool.render-engine", {}).get("cli", {})
5652
except TomlDecodeError as exc:
57-
click.echo(
58-
f"Encountered an error while parsing {config_file} - {exc}."
59-
)
53+
click.echo(f"Encountered an error while parsing {config_file} - {exc}.")
6054
else:
6155
click.echo(f"Config loaded from {config_file}")
6256
except FileNotFoundError:
6357
click.echo(f"No config file found at {config_file}")
6458

6559
if stored_config:
6660
# Populate the argument variables and default values from the config
67-
if (module := stored_config.get("module")) and (
68-
site := stored_config.get("site")
69-
):
61+
if (module := stored_config.get("module")) and (site := stored_config.get("site")):
7062
self._module_site = f"{module}:{site}"
7163
if default_collection := stored_config.get("collection"):
7264
self._collection = default_collection
@@ -84,9 +76,7 @@ def get_site(import_path: str, site: str, reload: bool = False) -> Site:
8476
def get_site_content_paths(site: Site) -> list[Path | str | None]:
8577
"""Get the content paths from the route_list in the Site"""
8678

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

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

131119

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

151139

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

177161

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

186170

187-
def validate_file_name_or_slug(
188-
ctx: click.Context, param: click.Option, value: str
189-
) -> str | None:
171+
def validate_file_name_or_slug(ctx: click.Context, param: click.Option, value: str) -> str | None:
190172
if value:
191173
if " " in value:
192-
raise click.exceptions.BadParameter(
193-
f"Spaces are not allowed in {param.name}."
194-
)
174+
raise click.exceptions.BadParameter(f"Spaces are not allowed in {param.name}.")
195175
click.echo(f"Setting {param.name} to {value}")
196176
return value
197-
if (title_or_slug := ctx.params.get("title")) or (
198-
title_or_slug := ctx.params.get("slug")
199-
):
177+
if (title_or_slug := ctx.params.get("title")) or (title_or_slug := ctx.params.get("slug")):
200178
slugged = slugify(title_or_slug)
201179
value = slugged + ".md" if param.name == "filename" else slugged
202180
click.echo(f"Setting {param.name} to {value}")
203181
return value
204182
if param.name == "filename":
205-
raise click.exceptions.BadParameter(
206-
"One of filename, title, or slug must be provided."
207-
)
183+
raise click.exceptions.BadParameter("One of filename, title, or slug must be provided.")
208184
return None

tests/test_cli.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ 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(
62-
content=None, collection=test_collection, foo="bar"
63-
)
61+
content = create_collection_entry(content=None, collection=test_collection, foo="bar")
6462
post = frontmatter.loads(content)
6563

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

7874
assert post["title"] == "Untitled Entry"
@@ -111,9 +107,7 @@ def test_split_args_error_handling():
111107
def test_config_loading_with_valid_config(tmp_path, monkeypatch):
112108
"""Tests config loading from pyproject.toml (2025.5.1b1 feature)"""
113109
config_content = {
114-
"tool.render-engine": {
115-
"cli": {"module": "myapp", "site": "MySite", "collection": "MyCollection"}
116-
}
110+
"tool.render-engine": {"cli": {"module": "myapp", "site": "MySite", "collection": "MyCollection"}}
117111
}
118112

119113
config_file = tmp_path / "pyproject.toml"
@@ -183,9 +177,7 @@ def test_split_module_site_invalid():
183177
"""Tests split_module_site with invalid input"""
184178
import click
185179

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

191183

0 commit comments

Comments
 (0)