Skip to content

Commit

Permalink
style: ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dairiki committed Sep 4, 2024
1 parent 16f35d3 commit 9ca8ad5
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 24 deletions.
3 changes: 1 addition & 2 deletions lektor_index_pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
""" Index pages for Lektor
"""
"""Index pages for Lektor"""

from .plugin import IndexPagesPlugin # noqa: F401
3 changes: 1 addition & 2 deletions lektor_index_pages/buildprog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Build program for the index pages.
"""
"""Build program for the index pages."""

from __future__ import annotations

Expand Down
4 changes: 1 addition & 3 deletions lektor_index_pages/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""" Configuration and config-related logic.
"""
"""Configuration and config-related logic."""

from __future__ import annotations

Expand Down
11 changes: 5 additions & 6 deletions lektor_index_pages/indexmodel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""" Configurable logic that controls how indexes work
"""
"""Configurable logic that controls how indexes work"""

from __future__ import annotations

Expand All @@ -19,10 +17,11 @@
if TYPE_CHECKING:
from _typeshed import StrPath
from inifile import IniFile
from lektor.environment import Environment
from lektor.db import Query
from lektor.db import Record
from lektor.environment import Environment
from lektor.sourceobj import SourceObject

from .sourceobj import IndexBase
from .sourceobj import IndexRoot
from .sourceobj import IndexSource
Expand Down Expand Up @@ -154,7 +153,7 @@ def __init__(
self.key_expr = expr("key", key)
self.slug_expr = expr("slug_format", slug_format) if slug_format else None

fields_section = "%s.fields" % index_name
fields_section = f"{index_name}.fields"
field = ExpressionCompiler(
env, section=fields_section, filename=config_filename
)
Expand Down Expand Up @@ -231,7 +230,7 @@ def __call__(self, name: str, expr: str) -> FieldDescriptor:
f"Jinja expression syntax error in config file: {exc}\n"
f" in expression {expr!r}\n"
f" for name {name!r}{self.location}"
)
) from exc


class FieldDescriptor:
Expand Down
2 changes: 1 addition & 1 deletion lektor_index_pages/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def index_pages(
try:
index_root = config.get_index_root(index_name, pad, alt)
except NoSuchIndex as exc:
return jinja_ctx.environment.undefined("index_pages: %s" % exc)
return jinja_ctx.environment.undefined(f"index_pages: {exc}")
return IndexPages(index_root)

env.jinja_env.globals["index_pages"] = index_pages
Expand Down
5 changes: 2 additions & 3 deletions lektor_index_pages/sourceobj.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
""" Virtual source objects for the indexes.
"""
"""Virtual source objects for the indexes."""

from __future__ import annotations

Expand Down Expand Up @@ -33,6 +31,7 @@
from lektor.builder import PathCache
from lektor.db import Record
from lektor.pagination import Pagination

from .indexmodel import IndexModel
from .indexmodel import IndexRootModel
from .plugin import Cache
Expand Down
3 changes: 1 addition & 2 deletions pdm_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""PDM build hook to generate dynamic README.
"""
"""PDM build hook to generate dynamic README."""

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def junk_ini(tmp_path_factory):
@pytest.fixture
def inifile(site_path, junk_ini, my_plugin_id, pagination_enabled, month_index_enabled):
# Make a temporary copy of our .ini file
config_name = "%s.ini" % my_plugin_id
config_name = f"{my_plugin_id}.ini"
orig_ini = site_path / "configs" / config_name
inifile = IniFile(str(orig_ini))
inifile.filename = str(junk_ini)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_indexmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def compiler(self, lektor_env, filename, section):
@pytest.mark.parametrize("section", ["section", None])
def test_location(self, compiler, filename, section):
if filename:
expect = r"in .*\b%s\b" % re.escape(filename)
expect = rf"in .*\b{re.escape(filename)}\b"
assert re.search(expect, compiler.location)
if section:
expect = r"\[%s\]" % re.escape(section)
expect = rf"\[{re.escape(section)}\]"
assert re.search(expect, compiler.location)

def test_error_report(self, compiler):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sourceobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_pagination(self, year_index, blog_record, pagination_enabled):
assert year_index.pagination.total == blog_record.children.count()
else:
with pytest.raises(RuntimeError):
year_index.pagination
_ = year_index.pagination

def test_subindexes(self, index, index_root):
if index is index_root:
Expand All @@ -140,7 +140,7 @@ def test__subindex_ids_missing_if_no_subindex(self, year_index):
assert not hasattr(year_index, "_subindex_ids")

def test_path(self, index_root):
assert index_root.path == "/blog@%s/year-index" % VIRTUAL_PATH_PREFIX
assert index_root.path == f"/blog@{VIRTUAL_PATH_PREFIX}/year-index"

def test__gid(self, index_root):
# md5("/blog@index-pages/year-index")
Expand Down

0 comments on commit 9ca8ad5

Please sign in to comment.