From 217adb85edc4f68f923a55702d4572143b6620d3 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sun, 14 May 2023 16:06:01 +0200 Subject: [PATCH] Use uvloop --- .pre-commit-config.yaml | 7 +++---- fastapi_file_server/app/views.py | 1 + fastapi_file_server/core/app.py | 2 ++ fastapi_file_server/core/auth.py | 1 + fastapi_file_server/core/config.py | 1 + fastapi_file_server/core/db.py | 1 + fastapi_file_server/main.py | 1 + pyproject.toml | 13 ++++++------- scripts/healthcheck.py | 1 + scripts/start_production.sh | 2 +- 10 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f2d22e..839fe4a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,18 +2,17 @@ exclude: 'docs|node_modules|migrations|.git|.tox' repos: - repo: https://github.com/ambv/black - rev: 22.12.0 + rev: 23.3.0 hooks: - id: black language_version: python3.11 - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.216' + rev: 'v0.0.267' hooks: - id: ruff - args: ["--force-exclude"] - repo: https://github.com/crate-ci/typos - rev: v1.13.6 + rev: typos-dict-v0.9.26 hooks: - id: typos diff --git a/fastapi_file_server/app/views.py b/fastapi_file_server/app/views.py index b3fbddb..f7e1bb0 100644 --- a/fastapi_file_server/app/views.py +++ b/fastapi_file_server/app/views.py @@ -9,6 +9,7 @@ from app.serializers import CreateUploadedFile, UploadedFile from app.services.file_downloader import FileDownloader from app.services.file_uploader import FileUploader + router = APIRouter( prefix="/api/v1/files", dependencies=[Depends(check_token)], tags=["files"] ) diff --git a/fastapi_file_server/core/app.py b/fastapi_file_server/core/app.py index 33dc997..3992eef 100644 --- a/fastapi_file_server/core/app.py +++ b/fastapi_file_server/core/app.py @@ -1,5 +1,6 @@ from fastapi import FastAPI from fastapi.responses import ORJSONResponse + from prometheus_fastapi_instrumentator import Instrumentator import sentry_sdk @@ -8,6 +9,7 @@ from app.views import healthcheck_router, router from core.config import env_config from core.db import database + sentry_sdk.init( env_config.SENTRY_DSN, ) diff --git a/fastapi_file_server/core/auth.py b/fastapi_file_server/core/auth.py index 61bfbb1..7cc07b5 100644 --- a/fastapi_file_server/core/auth.py +++ b/fastapi_file_server/core/auth.py @@ -1,3 +1,4 @@ from fastapi.security import APIKeyHeader + default_security = APIKeyHeader(name="Authorization") diff --git a/fastapi_file_server/core/config.py b/fastapi_file_server/core/config.py index a740eed..8548c8e 100644 --- a/fastapi_file_server/core/config.py +++ b/fastapi_file_server/core/config.py @@ -2,6 +2,7 @@ from typing import Optional from pydantic import BaseModel, BaseSettings + BotToken = str TelethonSessionName = str diff --git a/fastapi_file_server/core/db.py b/fastapi_file_server/core/db.py index 0f4b553..0879e69 100644 --- a/fastapi_file_server/core/db.py +++ b/fastapi_file_server/core/db.py @@ -5,6 +5,7 @@ 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}" diff --git a/fastapi_file_server/main.py b/fastapi_file_server/main.py index 2739482..0a4385b 100644 --- a/fastapi_file_server/main.py +++ b/fastapi_file_server/main.py @@ -1,3 +1,4 @@ from core.app import start_app + app = start_app() diff --git a/pyproject.toml b/pyproject.toml index c75a752..d451ab9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,14 +65,13 @@ max-complexity = 15 [tool.ruff.isort] known-first-party = ["core", "app"] force-sort-within-sections = true +force-wrap-aliases = true +section-order = ["future", "standard-library", "base_framework", "framework_ext", "third-party", "first-party", "local-folder"] +lines-after-imports = 2 -# 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.isort.sections] +base_framework = ["fastapi",] +framework_ext = ["starlette"] [tool.ruff.pyupgrade] keep-runtime-typing = true diff --git a/scripts/healthcheck.py b/scripts/healthcheck.py index 873827d..395ae27 100644 --- a/scripts/healthcheck.py +++ b/scripts/healthcheck.py @@ -1,5 +1,6 @@ import httpx + response = httpx.get("http://localhost:8080/healthcheck") print(f"HEALTHCHECK STATUS: {response.status_code}") exit(0 if response.status_code == 200 else 1) diff --git a/scripts/start_production.sh b/scripts/start_production.sh index 2321823..5757e75 100644 --- a/scripts/start_production.sh +++ b/scripts/start_production.sh @@ -4,4 +4,4 @@ rm -rf prometheus mkdir prometheus alembic -c ./app/alembic.ini upgrade head -uvicorn main:app --host 0.0.0.0 --port 8080 +uvicorn main:app --host 0.0.0.0 --port 8080 --loop uvloop