Skip to content

Commit 2b0d0b5

Browse files
committed
Fix formatting following move to ruff
1 parent d633972 commit 2b0d0b5

15 files changed

Lines changed: 54 additions & 54 deletions

File tree

src/zimscraperlib/html.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ def find_language_in(content: str | BinaryIO | TextIO, mime_type: str) -> str:
4040
node = soup.find(nodename)
4141
if node:
4242
if not isinstance(
43-
node, element.Tag # pyright:ignore[reportUnnecessaryIsInstance]
43+
node,
44+
element.Tag, # pyright:ignore[reportUnnecessaryIsInstance]
4445
) or not node.has_attr(key):
4546
continue
4647
if (
4748
nodename == "meta"
48-
and not node.attrs.get(
49-
"http-equiv", ""
50-
).lower() # pyright:ignore[reportUnknownMemberType, reportAttributeAccessIssue]
49+
and not node.attrs.get("http-equiv", "").lower() # pyright:ignore[reportUnknownMemberType, reportAttributeAccessIssue]
5150
== "content-language"
5251
):
5352
continue

src/zimscraperlib/i18n.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ def __eq__(self, value: object) -> bool:
167167

168168
def __hash__(self):
169169
return hash(
170-
f"{getattr(self, "iso_639_1", None)}$"
171-
f"{getattr(self, "iso_639_2b", None)}$"
172-
f"{getattr(self, "iso_639_2t", None)}$"
173-
f"{getattr(self, "iso_639_3", None)}$"
174-
f"{getattr(self, "iso_639_5", None)}$"
175-
f"{getattr(self, "english", None)}$"
176-
f"{getattr(self, "native", None)}"
170+
f"{getattr(self, 'iso_639_1', None)}$"
171+
f"{getattr(self, 'iso_639_2b', None)}$"
172+
f"{getattr(self, 'iso_639_2t', None)}$"
173+
f"{getattr(self, 'iso_639_3', None)}$"
174+
f"{getattr(self, 'iso_639_5', None)}$"
175+
f"{getattr(self, 'english', None)}$"
176+
f"{getattr(self, 'native', None)}"
177177
)
178178

179179

src/zimscraperlib/image/probing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def solarize(r: int, g: int, b: int) -> tuple[int, int, int]:
5050
sr, sg, sb = solarize(mr, mg, mb) # pyright: ignore[reportUnknownArgumentType]
5151

5252
return rgb_to_hex(
53-
mr, mg, mb # pyright: ignore[reportUnknownArgumentType]
53+
mr, # pyright: ignore[reportUnknownArgumentType]
54+
mg, # pyright: ignore[reportUnknownArgumentType]
55+
mb, # pyright: ignore[reportUnknownArgumentType]
5456
), rgb_to_hex(sr, sg, sb)
5557

5658

src/zimscraperlib/video/encoding.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def reencode(
5555
"""
5656

5757
with path_from(existing_tmp_path or tempfile.TemporaryDirectory()) as tmp_dir:
58-
5958
tmp_path = pathlib.Path(tmp_dir).joinpath(f"video.tmp{dst_path.suffix}")
6059
args = _build_ffmpeg_args(
6160
src_path=src_path,

src/zimscraperlib/zim/creator.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def mimetype_for(
6565
mimetype = (
6666
get_file_mimetype(fpath)
6767
if fpath
68-
else get_content_mimetype(content[:2048]) if content else None
68+
else get_content_mimetype(content[:2048])
69+
if content
70+
else None
6971
)
7072
# try to guess more-defined mime if it's text
7173
if (
@@ -125,7 +127,9 @@ def __init__(
125127
self.ignore_duplicates = ignore_duplicates
126128

127129
def config_indexing(
128-
self, indexing: bool, language: str | None = None # noqa: FBT001
130+
self,
131+
indexing: bool, # noqa: FBT001
132+
language: str | None = None,
129133
):
130134
"""Toggle full-text indexing of entries
131135
@@ -143,7 +147,6 @@ def config_indexing(
143147
def _log_metadata(self):
144148
"""Log in DEBUG level all metadata key and value"""
145149
for name, metadata in sorted(self._metadata.items()):
146-
147150
if not hasattr(metadata, "value"):
148151
logger.debug(
149152
f"Metadata: {name} is improper metadata type: "
@@ -211,7 +214,7 @@ def start(self):
211214
]
212215
raise ValueError(
213216
"Mandatory metadata are not all set. Missing metadata: "
214-
f'{",".join(missing_keys)}. You should prefer to use '
217+
f"{','.join(missing_keys)}. You should prefer to use "
215218
"StandardMetadataList if possible."
216219
)
217220

src/zimscraperlib/zim/metadata.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ def x_prefixed[U: AnyMetadata](cls: type[U]):
222222

223223

224224
class Metadata(MetadataBase[bytes]):
225-
226225
def get_binary_from(
227226
self,
228227
value: bytes | SupportsRead[bytes] | SupportsSeekableRead[bytes] | io.BytesIO,
@@ -463,7 +462,6 @@ class RelationMetadata(TextBasedMetadata):
463462

464463
@dataclass
465464
class StandardMetadataList:
466-
467465
Name: NameMetadata
468466
Language: LanguageMetadata
469467
Title: TitleMetadata

tests/image/test_image.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,22 +1206,30 @@ def test_optimize_any_image(
12061206
gif=(
12071207
GifMedium.options
12081208
if preset == "low"
1209-
else GifHigh.options if preset == "high" else GifMedium.options
1209+
else GifHigh.options
1210+
if preset == "high"
1211+
else GifMedium.options
12101212
),
12111213
webp=(
12121214
WebpLow.options
12131215
if preset == "low"
1214-
else WebpHigh.options if preset == "high" else WebpMedium.options
1216+
else WebpHigh.options
1217+
if preset == "high"
1218+
else WebpMedium.options
12151219
),
12161220
jpg=(
12171221
JpegLow.options
12181222
if preset == "low"
1219-
else JpegHigh.options if preset == "high" else JpegMedium.options
1223+
else JpegHigh.options
1224+
if preset == "high"
1225+
else JpegMedium.options
12201226
),
12211227
png=(
12221228
PngLow.options
12231229
if preset == "low"
1224-
else PngHigh.options if preset == "high" else PngMedium.options
1230+
else PngHigh.options
1231+
if preset == "high"
1232+
else PngMedium.options
12251233
),
12261234
),
12271235
)

tests/rewriting/conftest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ def __call__(
3333
)
3434

3535
def get_item_path(
36-
self, item_url: str, base_href: str | None # noqa: ARG002
36+
self,
37+
item_url: str, # noqa: ARG002
38+
base_href: str | None, # noqa: ARG002
3739
) -> ZimPath:
3840
return ZimPath("")
3941

4042
def get_document_uri(
41-
self, item_path: ZimPath, item_fragment: str # noqa: ARG002
43+
self,
44+
item_path: ZimPath, # noqa: ARG002
45+
item_fragment: str, # noqa: ARG002
4246
) -> str:
4347
return ""
4448

@@ -54,13 +58,9 @@ def get_simple_url_rewriter(url: str, suffix: str = "") -> ArticleUrlRewriter:
5458

5559

5660
@pytest.fixture(scope="module")
57-
def js_rewriter_gen() -> (
58-
Generator[
59-
Callable[
60-
[ArticleUrlRewriter, str | None, Callable[[ZimPath], None]], JsRewriter
61-
]
62-
]
63-
):
61+
def js_rewriter_gen() -> Generator[
62+
Callable[[ArticleUrlRewriter, str | None, Callable[[ZimPath], None]], JsRewriter]
63+
]:
6464
"""Fixture to create a basic url rewriter returning URLs as-is"""
6565

6666
def get_js_rewriter(
@@ -78,9 +78,9 @@ def get_js_rewriter(
7878

7979

8080
@pytest.fixture(scope="module")
81-
def css_rewriter_gen() -> (
82-
Generator[Callable[[ArticleUrlRewriter, str | None], CssRewriter]]
83-
):
81+
def css_rewriter_gen() -> Generator[
82+
Callable[[ArticleUrlRewriter, str | None], CssRewriter]
83+
]:
8484
"""Fixture to create a basic url rewriter returning URLs as-is"""
8585

8686
def get_css_rewriter(

tests/rewriting/test_html_rewriting.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,7 @@ def test_head_insert():
454454
url_rewriter, "PRE_HEAD_INSERT", "POST_HEAD_INSERT", None
455455
).rewrite(content).content == content.replace(
456456
"<head>", "<head>PRE_HEAD_INSERT"
457-
).replace(
458-
"</head>", "POST_HEAD_INSERT</head>"
459-
)
457+
).replace("</head>", "POST_HEAD_INSERT</head>")
460458

461459

462460
@pytest.mark.parametrize(

tests/rewriting/test_js_rewriting.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def test_js_rewrite_evals(simple_js_rewriter: JsRewriter, raw_js: str, expected:
136136

137137

138138
class WrappedTestContent(ContentForTests):
139-
140139
def __init__(
141140
self,
142141
input_: str | bytes,
@@ -253,7 +252,6 @@ def test_wrapped_rewrite(
253252

254253

255254
class ImportTestContent(ContentForTests):
256-
257255
def __init__(
258256
self,
259257
input_: str | bytes,

0 commit comments

Comments
 (0)