mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-16 23:07:32 -04:00
fix: Lint Python code with ruff (#3799)
This commit is contained in:
@@ -26,7 +26,7 @@ class SQLiteProvider(AbstractDBProvider, BaseModel):
|
||||
|
||||
@property
|
||||
def db_url(self) -> str:
|
||||
return f"sqlite:///{str(self.db_path.absolute())}"
|
||||
return f"sqlite:///{self.db_path.absolute()!s}"
|
||||
|
||||
@property
|
||||
def db_url_public(self) -> str:
|
||||
|
||||
@@ -70,7 +70,7 @@ async def get_token(
|
||||
@user_router.get("/refresh")
|
||||
async def refresh_token(current_user: PrivateUser = Depends(get_current_user)):
|
||||
"""Use a valid token to get another token"""
|
||||
access_token = security.create_access_token(data=dict(sub=str(current_user.id)))
|
||||
access_token = security.create_access_token(data={"sub": str(current_user.id)})
|
||||
return MealieAuthToken.respond(access_token)
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def make_dependable(cls):
|
||||
return cls(*args, **kwargs)
|
||||
except (ValidationError, RequestValidationError) as e:
|
||||
for error in e.errors():
|
||||
error["loc"] = ["query"] + list(error["loc"])
|
||||
error["loc"] = ["query", *list(error["loc"])]
|
||||
raise HTTPException(422, detail=[format_exception(ex) for ex in e.errors()]) from None
|
||||
|
||||
init_cls_and_handle_errors.__signature__ = signature(cls)
|
||||
|
||||
@@ -53,7 +53,7 @@ class GroupService(BaseService):
|
||||
all_ids = self.repos.recipes.all_ids(target_id)
|
||||
|
||||
used_size = sum(
|
||||
fs_stats.get_dir_size(f"{self.directories.RECIPE_DATA_DIR}/{str(recipe_id)}") for recipe_id in all_ids
|
||||
fs_stats.get_dir_size(f"{self.directories.RECIPE_DATA_DIR}/{recipe_id!s}") for recipe_id in all_ids
|
||||
)
|
||||
|
||||
return GroupStorage.bytes(used_size, ALLOWED_SIZE)
|
||||
|
||||
@@ -191,7 +191,7 @@ class ShoppingListService:
|
||||
created_items = self.list_items.create_many(filtered_create_items) if filtered_create_items else []
|
||||
updated_items = self.list_items.update_many(update_items) if update_items else []
|
||||
|
||||
for list_id in set(item.shopping_list_id for item in created_items + updated_items):
|
||||
for list_id in {item.shopping_list_id for item in created_items + updated_items}:
|
||||
self.remove_unused_recipe_references(list_id)
|
||||
|
||||
return ShoppingListItemsCollectionOut(
|
||||
@@ -278,7 +278,7 @@ class ShoppingListService:
|
||||
self.list_items.delete_many(delete_items) if delete_items else [], # type: ignore
|
||||
)
|
||||
|
||||
for list_id in set(item.shopping_list_id for item in updated_items + deleted_items):
|
||||
for list_id in {item.shopping_list_id for item in updated_items + deleted_items}:
|
||||
self.remove_unused_recipe_references(list_id)
|
||||
|
||||
return ShoppingListItemsCollectionOut(
|
||||
@@ -291,7 +291,7 @@ class ShoppingListService:
|
||||
self.list_items.delete_many(set(delete_items)) if delete_items else [], # type: ignore
|
||||
)
|
||||
|
||||
for list_id in set(item.shopping_list_id for item in deleted_items):
|
||||
for list_id in {item.shopping_list_id for item in deleted_items}:
|
||||
self.remove_unused_recipe_references(list_id)
|
||||
|
||||
return ShoppingListItemsCollectionOut(created_items=[], updated_items=[], deleted_items=deleted_items)
|
||||
|
||||
@@ -122,7 +122,7 @@ def parse_ingredient(tokens) -> tuple[str, str]:
|
||||
# no opening bracket anywhere -> just ignore the last bracket
|
||||
ingredient, note = parse_ingredient_with_comma(tokens)
|
||||
else:
|
||||
# opening bracket found -> split in ingredient and note, remove brackets from note # noqa: E501
|
||||
# opening bracket found -> split in ingredient and note, remove brackets from note
|
||||
note = " ".join(tokens[start:])[1:-1]
|
||||
ingredient = " ".join(tokens[:start])
|
||||
else:
|
||||
|
||||
@@ -95,7 +95,7 @@ def insideParenthesis(token, tokens):
|
||||
else:
|
||||
line = " ".join(tokens)
|
||||
return (
|
||||
re.match(r".*\(.*" + re.escape(token) + r".*\).*", line) is not None # noqa: W605 - invalid dscape sequence
|
||||
re.match(r".*\(.*" + re.escape(token) + r".*\).*", line) is not None # - invalid dscape sequence
|
||||
)
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ def import_data(lines):
|
||||
|
||||
# turn B-NAME/123 back into "name"
|
||||
tag, confidence = re.split(r"/", columns[-1], maxsplit=1)
|
||||
tag = re.sub(r"^[BI]\-", "", tag).lower() # noqa: W605 - invalid dscape sequence
|
||||
tag = re.sub(r"^[BI]\-", "", tag).lower() # - invalid dscape sequence
|
||||
|
||||
# ====================
|
||||
# Confidence Getter
|
||||
@@ -261,6 +261,6 @@ def export_data(lines):
|
||||
|
||||
for i, token in enumerate(tokens):
|
||||
features = getFeatures(token, i + 1, tokens)
|
||||
output.append(joinLine([token] + features))
|
||||
output.append(joinLine([token, *features]))
|
||||
output.append("")
|
||||
return "\n".join(output)
|
||||
|
||||
@@ -136,7 +136,7 @@ class RecipeDataService(BaseService):
|
||||
if ext not in img.IMAGE_EXTENSIONS:
|
||||
ext = "jpg" # Guess the extension
|
||||
|
||||
file_name = f"{str(self.recipe_id)}.{ext}"
|
||||
file_name = f"{self.recipe_id!s}.{ext}"
|
||||
file_path = Recipe.directory_from_id(self.recipe_id).joinpath("images", file_name)
|
||||
|
||||
async with AsyncClient(transport=AsyncSafeTransport()) as client:
|
||||
|
||||
@@ -162,7 +162,7 @@ def clean_instructions(steps_object: list | dict | str, default: list | None = N
|
||||
# }
|
||||
#
|
||||
steps_object = typing.cast(dict, steps_object)
|
||||
return clean_instructions([x for x in steps_object.values()])
|
||||
return clean_instructions(list(steps_object.values()))
|
||||
case str(step_as_str):
|
||||
# Strings are weird, some sites return a single string with newlines
|
||||
# others returns a json string for some reasons
|
||||
@@ -481,7 +481,7 @@ def clean_tags(data: str | list[str]) -> list[str]:
|
||||
case [str(), *_]:
|
||||
return [tag.strip().title() for tag in data if tag.strip()]
|
||||
case str(data):
|
||||
return clean_tags([t for t in data.split(",")])
|
||||
return clean_tags(data.split(","))
|
||||
case _:
|
||||
return []
|
||||
# should probably raise exception
|
||||
|
||||
@@ -55,7 +55,7 @@ async def create_from_url(url: str, translator: Translator) -> tuple[Recipe, Scr
|
||||
new_recipe.image = "no image"
|
||||
|
||||
if new_recipe.name is None or new_recipe.name == "":
|
||||
new_recipe.name = f"No Recipe Name Found - {str(uuid4())}"
|
||||
new_recipe.name = f"No Recipe Name Found - {uuid4()!s}"
|
||||
new_recipe.slug = slugify(new_recipe.name)
|
||||
|
||||
return new_recipe, extras
|
||||
|
||||
Reference in New Issue
Block a user