mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-29 13:27:09 -05:00
improve developer tooling (backend) (#1051)
* add basic pre-commit file * add flake8 * add isort * add pep585-upgrade (typing upgrades) * use namespace for import * add mypy * update ci for backend * flake8 scope * fix version format * update makefile * disable strict option (temporary) * fix mypy issues * upgrade type hints (pre-commit) * add vscode typing check * add types to dev deps * remote container draft * update setup script * update compose version * run setup on create * dev containers update * remove unused pages * update setup tips * expose ports * Update pre-commit to include flask8-print (#1053) * Add in flake8-print to pre-commit * pin version of flake8-print * formatting * update getting strated docs * add mypy to pre-commit * purge .mypy_cache on clean * drop mypy Co-authored-by: zackbcom <zackbcom@users.noreply.github.com>
This commit is contained in:
@@ -24,7 +24,7 @@ def sql_global_init(db_url: str):
|
||||
return SessionLocal, engine
|
||||
|
||||
|
||||
SessionLocal, engine = sql_global_init(settings.DB_URL)
|
||||
SessionLocal, engine = sql_global_init(settings.DB_URL) # type: ignore
|
||||
|
||||
|
||||
def create_session() -> Session:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from sqlalchemy import engine
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from .group import *
|
||||
from .labels import *
|
||||
from .recipe.recipe import *
|
||||
from .recipe.recipe import * # type: ignore
|
||||
from .server import *
|
||||
from .users import *
|
||||
|
||||
@@ -24,7 +24,7 @@ class BaseMixins:
|
||||
|
||||
@classmethod
|
||||
def get_ref(cls, match_value: str, match_attr: str = None, session: Session = None):
|
||||
match_attr = match_attr = cls.Config.get_attr
|
||||
match_attr = match_attr or cls.Config.get_attr # type: ignore
|
||||
|
||||
if match_value is None or session is None:
|
||||
return None
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from functools import wraps
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, NoneStr
|
||||
from sqlalchemy.orm import MANYTOMANY, MANYTOONE, ONETOMANY, Session
|
||||
from sqlalchemy.orm.decl_api import DeclarativeMeta
|
||||
from sqlalchemy.orm.mapper import Mapper
|
||||
@@ -21,7 +21,7 @@ class AutoInitConfig(BaseModel):
|
||||
Config class for `auto_init` decorator.
|
||||
"""
|
||||
|
||||
get_attr: str = None
|
||||
get_attr: NoneStr = None
|
||||
exclude: set = Field(default_factory=_default_exclusion)
|
||||
# auto_create: bool = False
|
||||
|
||||
@@ -83,12 +83,14 @@ def handle_one_to_many_list(session: Session, get_attr, relation_cls, all_elemen
|
||||
elem_id = elem.get(get_attr, None) if isinstance(elem, dict) else elem
|
||||
existing_elem = session.query(relation_cls).filter_by(**{get_attr: elem_id}).one_or_none()
|
||||
|
||||
if existing_elem is None:
|
||||
elems_to_create.append(elem)
|
||||
is_dict = isinstance(elem, dict)
|
||||
|
||||
if existing_elem is None and is_dict:
|
||||
elems_to_create.append(elem) # type: ignore
|
||||
continue
|
||||
|
||||
elif isinstance(elem, dict):
|
||||
for key, value in elem.items():
|
||||
elif is_dict:
|
||||
for key, value in elem.items(): # type: ignore
|
||||
if key not in cfg.exclude:
|
||||
setattr(existing_elem, key, value)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import inspect
|
||||
from typing import Any, Callable
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
|
||||
def get_valid_call(func: Callable, args_dict) -> dict:
|
||||
@@ -8,7 +9,7 @@ def get_valid_call(func: Callable, args_dict) -> dict:
|
||||
the original dictionary will be returned.
|
||||
"""
|
||||
|
||||
def get_valid_args(func: Callable) -> tuple:
|
||||
def get_valid_args(func: Callable) -> list[str]:
|
||||
"""
|
||||
Returns a tuple of valid arguemnts for the supplied function.
|
||||
"""
|
||||
|
||||
@@ -78,8 +78,8 @@ class Group(SqlAlchemyBase, BaseMixins):
|
||||
def __init__(self, **_) -> None:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_ref(session: Session, name: str):
|
||||
@staticmethod # TODO: Remove this
|
||||
def get_ref(session: Session, name: str): # type: ignore
|
||||
settings = get_app_settings()
|
||||
|
||||
item = session.query(Group).filter(Group.name == name).one_or_none()
|
||||
|
||||
@@ -63,8 +63,8 @@ class Category(SqlAlchemyBase, BaseMixins):
|
||||
self.name = name.strip()
|
||||
self.slug = slugify(name)
|
||||
|
||||
@classmethod
|
||||
def get_ref(cls, match_value: str, session=None):
|
||||
@classmethod # TODO: Remove this
|
||||
def get_ref(cls, match_value: str, session=None): # type: ignore
|
||||
if not session or not match_value:
|
||||
return None
|
||||
|
||||
@@ -76,4 +76,4 @@ class Category(SqlAlchemyBase, BaseMixins):
|
||||
return result
|
||||
else:
|
||||
logger.debug("Category doesn't exists, creating Category")
|
||||
return Category(name=match_value)
|
||||
return Category(name=match_value) # type: ignore
|
||||
|
||||
@@ -22,5 +22,5 @@ class RecipeComment(SqlAlchemyBase, BaseMixins):
|
||||
def __init__(self, **_) -> None:
|
||||
pass
|
||||
|
||||
def update(self, text, **_) -> None:
|
||||
def update(self, text, **_) -> None: # type: ignore
|
||||
self.text = text
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import datetime
|
||||
from datetime import date
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
@@ -107,7 +106,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
extras: list[ApiExtras] = orm.relationship("ApiExtras", cascade="all, delete-orphan")
|
||||
|
||||
# Time Stamp Properties
|
||||
date_added = sa.Column(sa.Date, default=date.today)
|
||||
date_added = sa.Column(sa.Date, default=datetime.date.today)
|
||||
date_updated = sa.Column(sa.DateTime)
|
||||
|
||||
# Shopping List Refs
|
||||
|
||||
@@ -50,8 +50,8 @@ class Tag(SqlAlchemyBase, BaseMixins):
|
||||
self.name = name.strip()
|
||||
self.slug = slugify(self.name)
|
||||
|
||||
@classmethod
|
||||
def get_ref(cls, match_value: str, session=None):
|
||||
@classmethod # TODO: Remove this
|
||||
def get_ref(cls, match_value: str, session=None): # type: ignore
|
||||
if not session or not match_value:
|
||||
return None
|
||||
|
||||
@@ -62,4 +62,4 @@ class Tag(SqlAlchemyBase, BaseMixins):
|
||||
return result
|
||||
else:
|
||||
logger.debug("Category doesn't exists, creating Category")
|
||||
return Tag(name=match_value)
|
||||
return Tag(name=match_value) # type: ignore
|
||||
|
||||
@@ -124,6 +124,6 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
self.can_invite = can_invite
|
||||
self.can_organize = can_organize
|
||||
|
||||
@staticmethod
|
||||
def get_ref(session, id: str):
|
||||
@staticmethod # TODO: Remove This
|
||||
def get_ref(session, id: str): # type: ignore
|
||||
return session.query(User).filter(User.id == id).one()
|
||||
|
||||
Reference in New Issue
Block a user