mirror of
https://github.com/flibusta-apps/book_library_server.git
synced 2025-12-06 07:05:36 +01:00
Migrate to ruff
This commit is contained in:
@@ -6,15 +6,14 @@ repos:
|
||||
hooks:
|
||||
- id: black
|
||||
language_version: python3.11
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: v5.11.3
|
||||
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
rev: 'v0.0.213'
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/csachs/pyproject-flake8
|
||||
rev: v6.0.0.post1
|
||||
- id: ruff
|
||||
args: ["--force-exclude"]
|
||||
|
||||
- repo: https://github.com/crate-ci/typos
|
||||
rev: v1.13.6
|
||||
hooks:
|
||||
- id: pyproject-flake8
|
||||
additional_dependencies: [
|
||||
'-e', 'git+https://github.com/pycqa/pyflakes@b37f91a#egg=pyflakes',
|
||||
'-e', 'git+https://github.com/pycqa/pycodestyle@1063db8#egg=pycodestyle',
|
||||
]
|
||||
- id: typos
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import Security, HTTPException, Query, status
|
||||
from fastapi import HTTPException, Query, Security, status
|
||||
|
||||
from core.auth import default_security
|
||||
from core.config import env_config
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import date
|
||||
from typing import Optional
|
||||
|
||||
from fastapi.params import Query
|
||||
from fastapi import Query
|
||||
|
||||
from app.depends import get_allowed_langs
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Optional
|
||||
import ormar
|
||||
from sqlalchemy import text
|
||||
|
||||
from core.db import metadata, database
|
||||
from core.db import database, metadata
|
||||
|
||||
|
||||
class BaseMeta(ormar.ModelMeta):
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from typing import TypedDict
|
||||
|
||||
from app.models import Author
|
||||
from app.services.common import TRGMSearchService, MeiliSearchService, GetRandomService
|
||||
|
||||
from app.services.common import GetRandomService, MeiliSearchService, TRGMSearchService
|
||||
|
||||
GET_OBJECT_IDS_QUERY = """
|
||||
SELECT ARRAY(
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from typing import TypedDict, Optional
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
from app.models import Book as BookDB
|
||||
from app.services.common import (
|
||||
TRGMSearchService,
|
||||
MeiliSearchService,
|
||||
GetRandomService,
|
||||
BaseFilterService,
|
||||
GetRandomService,
|
||||
MeiliSearchService,
|
||||
TRGMSearchService,
|
||||
)
|
||||
|
||||
|
||||
GET_OBJECT_IDS_QUERY = """
|
||||
SELECT ARRAY(
|
||||
WITH filtered_books AS (
|
||||
|
||||
@@ -2,20 +2,19 @@ import abc
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from random import choice
|
||||
from typing import Optional, Generic, TypeVar, TypedDict, Union
|
||||
from typing import Generic, Optional, TypedDict, TypeVar, Union
|
||||
|
||||
import meilisearch
|
||||
from databases import Database
|
||||
from fastapi_pagination.api import resolve_params
|
||||
from fastapi_pagination.bases import AbstractParams, RawParams
|
||||
import meilisearch
|
||||
from ormar import Model, QuerySet
|
||||
from redis import asyncio as aioredis
|
||||
from sqlalchemy import Table
|
||||
|
||||
from app.utils.pagination import Page, CustomPage
|
||||
from app.utils.pagination import CustomPage, Page
|
||||
from core.config import env_config
|
||||
|
||||
|
||||
MODEL = TypeVar("MODEL", bound=Model)
|
||||
QUERY = TypeVar("QUERY", bound=TypedDict)
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from typing import TypedDict
|
||||
|
||||
from app.models import Sequence
|
||||
from app.services.common import TRGMSearchService, MeiliSearchService, GetRandomService
|
||||
|
||||
from app.services.common import GetRandomService, MeiliSearchService, TRGMSearchService
|
||||
|
||||
GET_OBJECT_IDS_QUERY = """
|
||||
SELECT ARRAY (
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from app.models import Author
|
||||
from app.services.common import TRGMSearchService, MeiliSearchService
|
||||
|
||||
from app.services.common import MeiliSearchService, TRGMSearchService
|
||||
|
||||
GET_OBJECT_IDS_QUERY = """
|
||||
SELECT ARRAY(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Protocol, TypeVar, Any, Generic, Sequence, runtime_checkable
|
||||
from typing import Any, Generic, Protocol, Sequence, TypeVar, runtime_checkable
|
||||
|
||||
from fastapi_pagination import Page, Params
|
||||
from fastapi_pagination.bases import AbstractParams
|
||||
|
||||
@@ -8,7 +8,6 @@ from app.views.sequence import sequence_router
|
||||
from app.views.source import source_router
|
||||
from app.views.translation import translation_router
|
||||
|
||||
|
||||
routers = [
|
||||
source_router,
|
||||
author_router,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, Request, HTTPException, status
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
@@ -13,7 +12,6 @@ from app.services.author import AuthorMeiliSearchService, GetRandomAuthorService
|
||||
from app.services.translator import TranslatorMeiliSearchService
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
author_router = APIRouter(
|
||||
prefix="/api/v1/authors",
|
||||
tags=["author"],
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination import Page, Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.depends import check_token
|
||||
from app.models import AuthorAnnotation as AuthorAnnotationDB
|
||||
from app.serializers.author_annotation import AuthorAnnotation
|
||||
|
||||
|
||||
author_annotation_router = APIRouter(
|
||||
prefix="/api/v1/author_annotations",
|
||||
tags=["author_annotation"],
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Request, HTTPException, status
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from fastapi_pagination import Params
|
||||
|
||||
from app.depends import check_token, get_allowed_langs
|
||||
from app.filters.book import get_book_filter
|
||||
from app.models import Book as BookDB
|
||||
from app.models import BookAnnotation as BookAnnotationDB
|
||||
from app.serializers.book import Book, RemoteBook, BookDetail
|
||||
from app.serializers.book import Book, BookDetail, RemoteBook
|
||||
from app.serializers.book_annotation import BookAnnotation
|
||||
from app.services.book import (
|
||||
BookMeiliSearchService,
|
||||
BookFilterService,
|
||||
BookMeiliSearchService,
|
||||
GetRandomBookService,
|
||||
)
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
book_router = APIRouter(
|
||||
prefix="/api/v1/books",
|
||||
tags=["book"],
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination import Page, Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.depends import check_token
|
||||
from app.models import BookAnnotation as BookAnnotationDB
|
||||
from app.serializers.book_annotation import BookAnnotation
|
||||
|
||||
|
||||
book_annotation_router = APIRouter(
|
||||
prefix="/api/v1/book_annotations",
|
||||
tags=["book_annotation"],
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Request
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
@@ -10,7 +9,6 @@ from app.serializers.genre import Genre
|
||||
from app.services.genre import GenreMeiliSearchService
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
genre_router = APIRouter(
|
||||
prefix="/api/v1/genres", tags=["genres"], dependencies=[Depends(check_token)]
|
||||
)
|
||||
@@ -31,7 +29,8 @@ async def get_genres(genre_filter: dict = Depends(get_genre_filter)):
|
||||
@genre_router.get("/metas", response_model=list[str])
|
||||
async def get_genre_metas():
|
||||
genres = await GenreDB.objects.fields("meta").values_list(flatten=True)
|
||||
return sorted(list(set(genres)))
|
||||
genres.sort()
|
||||
return list(set(genres))
|
||||
|
||||
|
||||
@genre_router.get("/{id}", response_model=Genre)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
|
||||
healtcheck_router = APIRouter(tags=["healthcheck"])
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
@@ -8,10 +7,9 @@ from app.models import Book as BookDB
|
||||
from app.models import Sequence as SequenceDB
|
||||
from app.serializers.sequence import Book as SequenceBook
|
||||
from app.serializers.sequence import Sequence
|
||||
from app.services.sequence import SequenceMeiliSearchService, GetRandomSequenceService
|
||||
from app.services.sequence import GetRandomSequenceService, SequenceMeiliSearchService
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
sequence_router = APIRouter(
|
||||
prefix="/api/v1/sequences",
|
||||
tags=["sequence"],
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from fastapi_pagination import Params, Page
|
||||
from fastapi_pagination import Page, Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
from app.depends import check_token
|
||||
from app.models import Source as SourceDB
|
||||
from app.serializers.source import Source
|
||||
|
||||
|
||||
source_router = APIRouter(
|
||||
prefix="/api/v1/sources",
|
||||
tags=["source"],
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.ormar import paginate
|
||||
|
||||
@@ -8,7 +7,6 @@ from app.models import Translation as TranslationDB
|
||||
from app.serializers.translation import Translation
|
||||
from app.utils.pagination import CustomPage
|
||||
|
||||
|
||||
translation_router = APIRouter(
|
||||
prefix="/api/v1/translation",
|
||||
tags=["translation"],
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import sentry_sdk
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import ORJSONResponse
|
||||
|
||||
from fastapi_pagination import add_pagination
|
||||
from prometheus_fastapi_instrumentator import Instrumentator
|
||||
from redis import asyncio as aioredis
|
||||
import sentry_sdk
|
||||
|
||||
from app.views import routers
|
||||
from core.config import env_config
|
||||
from core.db import database
|
||||
|
||||
|
||||
sentry_sdk.init(
|
||||
env_config.SENTRY_SDN,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from fastapi.security import APIKeyHeader
|
||||
|
||||
|
||||
default_security = APIKeyHeader(name="Authorization")
|
||||
|
||||
@@ -5,7 +5,6 @@ from sqlalchemy import MetaData
|
||||
|
||||
from core.config import env_config
|
||||
|
||||
|
||||
DATABASE_URL = (
|
||||
f"postgresql://{env_config.POSTGRES_USER}:{quote(env_config.POSTGRES_PASSWORD)}@"
|
||||
f"{env_config.POSTGRES_HOST}:{env_config.POSTGRES_PORT}/{env_config.POSTGRES_DB}"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from core.app import start_app
|
||||
|
||||
|
||||
app = start_app()
|
||||
|
||||
797
poetry.lock
generated
797
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -5,10 +5,10 @@ description = ""
|
||||
authors = ["Kurbanov Bulat <kurbanovbul@gmail.com>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
fastapi = "^0.88.0"
|
||||
python = "^3.11"
|
||||
fastapi = "^0.89.0"
|
||||
pydantic = "^1.10.2"
|
||||
uvicorn = {extras = ["standart"], version = "^0.20.0"}
|
||||
uvicorn = {extras = ["standard"], version = "^0.20.0"}
|
||||
ormar = {extras = ["postgresql"], version = "^0.12.0"}
|
||||
alembic = "^1.9.1"
|
||||
fastapi-pagination = {extras = ["ormar"], version = "^0.11.1"}
|
||||
@@ -21,8 +21,8 @@ gunicorn = "^20.1.0"
|
||||
sentry-sdk = "^1.12.1"
|
||||
redis = {extras = ["hiredis"], version = "^4.4.0"}
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = "^7.1.2"
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pre-commit = "^2.21.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
@@ -39,31 +39,38 @@ exclude = '''
|
||||
)/
|
||||
'''
|
||||
|
||||
[tool.flake8]
|
||||
ignore = [
|
||||
# Whitespace before ':' ( https://www.flake8rules.com/rules/E203.html )
|
||||
"E203"
|
||||
]
|
||||
max-line-length=88
|
||||
max-complexity = 15
|
||||
select = "B,C,E,F,W,T4,B9"
|
||||
[tool.ruff]
|
||||
fix = true
|
||||
target-version = "py311"
|
||||
src = ["fastapi_book_server"]
|
||||
line-length=88
|
||||
ignore = []
|
||||
select = ["B", "C", "E", "F", "W", "B9", "I001"]
|
||||
exclude = [
|
||||
# No need to traverse our git directory
|
||||
".git",
|
||||
# There's no value in checking cache directories
|
||||
"__pycache__",
|
||||
# The conf file is mostly autogenerated, ignore it
|
||||
"fastapi_book_server/app/alembic/*",
|
||||
# The old directory contains Flake8 2.0
|
||||
"fastapi_book_server/app/alembic",
|
||||
]
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
only_sections = true
|
||||
force_sort_within_sections = true
|
||||
lines_after_imports = 2
|
||||
lexicographical = true
|
||||
sections = ["FUTURE", "STDLIB", "BASEFRAMEWORK", "FRAMEWORKEXT", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
|
||||
known_baseframework = ["fastapi",]
|
||||
known_frameworkext = ["starlette",]
|
||||
src_paths = ["fastapi_book_server"]
|
||||
[tool.ruff.flake8-bugbear]
|
||||
extend-immutable-calls = ["fastapi.File", "fastapi.Form", "fastapi.Security", "fastapi.Query", "fastapi.Depends"]
|
||||
|
||||
[tool.ruff.mccabe]
|
||||
max-complexity = 15
|
||||
|
||||
[tool.ruff.isort]
|
||||
known-first-party = ["core", "app"]
|
||||
|
||||
# only_sections = true
|
||||
# force_sort_within_sections = true
|
||||
# lines_after_imports = 2
|
||||
# lexicographical = true
|
||||
# sections = ["FUTURE", "STDLIB", "BASEFRAMEWORK", "FRAMEWORKEXT", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
|
||||
# known_baseframework = ["fastapi",]
|
||||
# known_frameworkext = ["starlette",]
|
||||
|
||||
[tool.ruff.pyupgrade]
|
||||
keep-runtime-typing = true
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import httpx
|
||||
|
||||
|
||||
response = httpx.get(
|
||||
"http://localhost:8080/healthcheck",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user