Skip to content
Snippets Groups Projects
Commit a23fedd0 authored by Manon Blanco's avatar Manon Blanco
Browse files

Comply with ruff's SIM rule

parent 6cf94bdb
No related branches found
No related tags found
1 merge request!452Comply with ruff's SIM rule
Pipeline #144824 passed
......@@ -143,17 +143,15 @@ class CachedElement(Model):
if max_width is None and max_height is None:
resize = "full"
else:
# Do not resize for polygons that do not exactly match the images
# as the resize is made directly by the IIIF server using the box parameter
if (
# Do not resize for polygons that do not exactly match the images
# as the resize is made directly by the IIIF server using the box parameter
bounding_box.width != self.image.width
or bounding_box.height != self.image.height
):
resize = "full"
# Do not resize when the image is below the maximum size
elif (max_width is None or self.image.width <= max_width) and (
max_height is None or self.image.height <= max_height
) or (
# Do not resize when the image is below the maximum size
(max_width is None or self.image.width <= max_width)
and (max_height is None or self.image.height <= max_height)
):
resize = "full"
else:
......@@ -323,16 +321,15 @@ def check_version(cache_path: str | Path):
:param cache_path: Path towards a local SQLite database
"""
with SqliteDatabase(cache_path) as provided_db:
with provided_db.bind_ctx([Version]):
try:
version = Version.get().version
except OperationalError:
version = None
with SqliteDatabase(cache_path) as provided_db, provided_db.bind_ctx([Version]):
try:
version = Version.get().version
except OperationalError:
version = None
assert (
version == SQL_VERSION
), f"The SQLite database {cache_path} does not have the correct cache version, it should be {SQL_VERSION}"
assert (
version == SQL_VERSION
), f"The SQLite database {cache_path} does not have the correct cache version, it should be {SQL_VERSION}"
def merge_parents_cache(paths: list, current_database: Path):
......@@ -356,9 +353,8 @@ def merge_parents_cache(paths: list, current_database: Path):
# Check that the parent cache uses a compatible version
check_version(path)
with SqliteDatabase(path) as source:
with source.bind_ctx(MODELS):
source.create_tables(MODELS)
with SqliteDatabase(path) as source, source.bind_ctx(MODELS):
source.create_tables(MODELS)
logger.info(f"Merging parent db {path} into {current_database}")
statements = [
......
......@@ -193,10 +193,7 @@ class Element(MagicDict):
else:
resize = f"{max_width or ''},{max_height or ''}"
if use_full_image:
url = self.image_url(resize)
else:
url = self.resize_zone_url(resize)
url = self.image_url(resize) if use_full_image else self.resize_zone_url(resize)
try:
return open_image(
......
"""
Base classes to implement Arkindex workers.
"""
import contextlib
import json
import os
import sys
......@@ -226,10 +226,8 @@ class ElementsWorker(
)
if element:
# Try to update the activity to error state regardless of the response
try:
with contextlib.suppress(Exception):
self.update_activity(element.id, ActivityState.Error)
except Exception:
pass
if failed:
logger.error(
......@@ -496,10 +494,8 @@ class DatasetWorker(BaseWorker, DatasetMixin, TaskMixin):
)
if dataset and self.generator:
# Try to update the state to Error regardless of the response
try:
with contextlib.suppress(Exception):
self.update_dataset_state(dataset, DatasetState.Error)
except Exception:
pass
if failed:
logger.error(
......
......@@ -352,7 +352,8 @@ class BaseWorker:
try:
gpg = gnupg.GPG()
decrypted = gpg.decrypt_file(open(path, "rb"))
with path.open("rb") as gpg_file:
decrypted = gpg.decrypt_file(gpg_file)
assert (
decrypted.ok
), f"GPG error: {decrypted.status} - {decrypted.stderr}"
......
......@@ -17,6 +17,8 @@ select = [
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
]
[tool.ruff.isort]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment