mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-06-06 17:10:16 -04: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:
@@ -1,5 +1,6 @@
|
||||
import shutil
|
||||
import tempfile
|
||||
from collections.abc import AsyncGenerator, Callable, Generator
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
@@ -94,10 +95,11 @@ def validate_long_live_token(session: Session, client_token: str, id: int) -> Pr
|
||||
tokens: list[LongLiveTokenInDB] = repos.api_tokens.get(id, "user_id", limit=9999)
|
||||
|
||||
for token in tokens:
|
||||
token: LongLiveTokenInDB
|
||||
if token.token == client_token:
|
||||
return token.user
|
||||
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid Token")
|
||||
|
||||
|
||||
def validate_file_token(token: Optional[str] = None) -> Path:
|
||||
credentials_exception = HTTPException(
|
||||
@@ -133,7 +135,7 @@ def validate_recipe_token(token: Optional[str] = None) -> str:
|
||||
return slug
|
||||
|
||||
|
||||
async def temporary_zip_path() -> Path:
|
||||
async def temporary_zip_path() -> AsyncGenerator[Path, None]:
|
||||
app_dirs.TEMP_DIR.mkdir(exist_ok=True, parents=True)
|
||||
temp_path = app_dirs.TEMP_DIR.joinpath("my_zip_archive.zip")
|
||||
|
||||
@@ -143,7 +145,7 @@ async def temporary_zip_path() -> Path:
|
||||
temp_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
async def temporary_dir() -> Path:
|
||||
async def temporary_dir() -> AsyncGenerator[Path, None]:
|
||||
temp_path = app_dirs.TEMP_DIR.joinpath(uuid4().hex)
|
||||
temp_path.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
@@ -153,12 +155,12 @@ async def temporary_dir() -> Path:
|
||||
shutil.rmtree(temp_path)
|
||||
|
||||
|
||||
def temporary_file(ext: str = "") -> Path:
|
||||
def temporary_file(ext: str = "") -> Callable[[], Generator[tempfile._TemporaryFileWrapper, None, None]]:
|
||||
"""
|
||||
Returns a temporary file with the specified extension
|
||||
"""
|
||||
|
||||
def func() -> Path:
|
||||
def func():
|
||||
temp_path = app_dirs.TEMP_DIR.joinpath(uuid4().hex + ext)
|
||||
temp_path.touch()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user