summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2024-11-14 16:27:26 +0100
committerWolfgang Müller2024-11-14 16:51:56 +0100
commit34a759b8044123bbf5d0aa66dedd3b563fe3a014 (patch)
tree9c956df2a973fb738d36fee1b46e7813c7541440
parent9e4f47b3dbc64d9328f3d7532ecfe0cd9432f21c (diff)
downloadhircine-34a759b8044123bbf5d0aa66dedd3b563fe3a014.tar.gz
backend/lint: Implement flake8-simplify suggestions
Diffstat (limited to '')
-rw-r--r--src/hircine/plugins/__init__.py2
-rw-r--r--src/hircine/plugins/scrapers/gallery_dl.py2
-rw-r--r--src/hircine/scanner.py27
-rw-r--r--src/hircine/scraper/utils.py5
-rw-r--r--tests/api/test_sort.py2
-rw-r--r--tests/scanner/test_scanner.py23
6 files changed, 29 insertions, 32 deletions
diff --git a/src/hircine/plugins/__init__.py b/src/hircine/plugins/__init__.py
index 27e55a7..ea1a262 100644
--- a/src/hircine/plugins/__init__.py
+++ b/src/hircine/plugins/__init__.py
@@ -8,7 +8,7 @@ transformers = []
def get_scraper(name):
- return scraper_registry.get(name, None)
+ return scraper_registry.get(name)
def get_scrapers():
diff --git a/src/hircine/plugins/scrapers/gallery_dl.py b/src/hircine/plugins/scrapers/gallery_dl.py
index a6cebc4..17f85d0 100644
--- a/src/hircine/plugins/scrapers/gallery_dl.py
+++ b/src/hircine/plugins/scrapers/gallery_dl.py
@@ -36,7 +36,7 @@ class GalleryDLScraper(Scraper):
self.data = self.load()
category = self.data.get("category")
- if category in HANDLERS.keys():
+ if category in HANDLERS:
self.is_available = True
self.handler = HANDLERS.get(category)()
diff --git a/src/hircine/scanner.py b/src/hircine/scanner.py
index 162e1f0..d1077ed 100644
--- a/src/hircine/scanner.py
+++ b/src/hircine/scanner.py
@@ -302,19 +302,18 @@ class Scanner:
def process_member(self, input):
path, name = input
- with ZipFile(path, mode="r") as zip:
- with zip.open(name, mode="r") as member:
- _, ext = os.path.splitext(name)
- digest = file_digest(member, blake3).digest()
-
- if self.thumbnailer.can_process(ext):
- hash = digest.hex()
-
- width, height = self.thumbnailer.process(
- member, hash, reprocess=self.reprocess
- )
- return digest, Member(
- path=member.name, hash=hash, width=width, height=height
- )
+ with ZipFile(path, mode="r") as zip, zip.open(name, mode="r") as member:
+ _, ext = os.path.splitext(name)
+ digest = file_digest(member, blake3).digest()
+
+ if self.thumbnailer.can_process(ext):
+ hash = digest.hex()
+
+ width, height = self.thumbnailer.process(
+ member, hash, reprocess=self.reprocess
+ )
+ return digest, Member(
+ path=member.name, hash=hash, width=width, height=height
+ )
return digest, None
diff --git a/src/hircine/scraper/utils.py b/src/hircine/scraper/utils.py
index 1c1fbee..d3fa6d6 100644
--- a/src/hircine/scraper/utils.py
+++ b/src/hircine/scraper/utils.py
@@ -57,6 +57,5 @@ def open_archive_file(archive, member, check_sidecar=True): # pragma: no cover
return
- with ZipFile(archive.path, "r") as zip:
- with zip.open(member, "r") as file:
- yield file
+ with ZipFile(archive.path, "r") as zip, zip.open(member, "r") as file:
+ yield file
diff --git a/tests/api/test_sort.py b/tests/api/test_sort.py
index 9cafe82..404e3d6 100644
--- a/tests/api/test_sort.py
+++ b/tests/api/test_sort.py
@@ -135,4 +135,4 @@ async def test_query_namespace_sort_sort_name(query_namespace_sort):
response = Response(await query_namespace_sort({"on": "SORT_NAME"}))
response.assert_is("NamespaceFilterResult")
- assert ["two", "one"] == [edge["name"] for edge in response.edges]
+ assert [edge["name"] for edge in response.edges] == ["two", "one"]
diff --git a/tests/scanner/test_scanner.py b/tests/scanner/test_scanner.py
index a70c4d8..6fc6650 100644
--- a/tests/scanner/test_scanner.py
+++ b/tests/scanner/test_scanner.py
@@ -104,18 +104,17 @@ async def test_scanner_dedups_archive_contents(archive, scanner, capsys):
archive = await DB.add(archive)
dedup_path = archive.path + ".dedup"
- with ZipFile(archive.path, "r") as zin:
- with ZipFile(dedup_path, "w") as zout:
- for info in zin.infolist():
- base, ext = os.path.splitext(info.filename)
-
- if base == "03":
- continue
-
- if ext == ".png":
- zout.writestr(f"0{base}.png", zin.read(info))
- else:
- zout.writestr(info.filename, zin.read(info))
+ with ZipFile(archive.path, "r") as zin, ZipFile(dedup_path, "w") as zout:
+ for info in zin.infolist():
+ base, ext = os.path.splitext(info.filename)
+
+ if base == "03":
+ continue
+
+ if ext == ".png":
+ zout.writestr(f"0{base}.png", zin.read(info))
+ else:
+ zout.writestr(info.filename, zin.read(info))
await scanner.scan()
added_archive = await DB.get(Archive, 2, full=True)