mirror of
https://github.com/flibusta-apps/users_settings_server.git
synced 2025-12-06 06:35:39 +01:00
Migrate to ruff
This commit is contained in:
@@ -6,15 +6,14 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
language_version: python3.11
|
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:
|
hooks:
|
||||||
- id: isort
|
- id: ruff
|
||||||
- repo: https://github.com/csachs/pyproject-flake8
|
args: ["--force-exclude"]
|
||||||
rev: v6.0.0.post1
|
|
||||||
|
- repo: https://github.com/crate-ci/typos
|
||||||
|
rev: v1.13.6
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyproject-flake8
|
- id: typos
|
||||||
additional_dependencies: [
|
|
||||||
'-e', 'git+https://github.com/pycqa/pyflakes@b37f91a#egg=pyflakes',
|
|
||||||
'-e', 'git+https://github.com/pycqa/pycodestyle@1063db8#egg=pycodestyle',
|
|
||||||
]
|
|
||||||
|
|||||||
949
poetry.lock
generated
949
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -5,22 +5,25 @@ description = ""
|
|||||||
authors = ["Kurbanov Bulat <kurbanovbul@gmail.com>"]
|
authors = ["Kurbanov Bulat <kurbanovbul@gmail.com>"]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.9"
|
python = "^3.11"
|
||||||
fastapi = "^0.85.1"
|
fastapi = "^0.89.0"
|
||||||
fastapi-pagination = {extras = ["ormar"], version = "^0.10.0"}
|
fastapi-pagination = {extras = ["ormar"], version = "^0.11.1"}
|
||||||
alembic = "^1.8.1"
|
alembic = "^1.9.1"
|
||||||
ormar = {extras = ["postgresql"], version = "^0.12.0"}
|
ormar = {extras = ["postgresql"], version = "^0.12.0"}
|
||||||
uvicorn = {extras = ["standart"], version = "^0.19.0"}
|
uvicorn = {extras = ["standard"], version = "^0.20.0"}
|
||||||
httpx = "^0.23.0"
|
httpx = "^0.23.3"
|
||||||
orjson = "^3.8.1"
|
orjson = "^3.8.4"
|
||||||
prometheus-fastapi-instrumentator = "^5.9.1"
|
prometheus-fastapi-instrumentator = "^5.9.1"
|
||||||
uvloop = "^0.17.0"
|
uvloop = "^0.17.0"
|
||||||
gunicorn = "^20.1.0"
|
gunicorn = "^20.1.0"
|
||||||
sentry-sdk = "^1.10.1"
|
sentry-sdk = "^1.12.1"
|
||||||
redis = {extras = ["hiredis"], version = "^4.3.4"}
|
redis = {extras = ["hiredis"], version = "^4.4.0"}
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
pre-commit = "^2.21.0"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=1.0.0"]
|
requires = ["poetry-core>=1.0.0"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
@@ -36,31 +39,38 @@ exclude = '''
|
|||||||
)/
|
)/
|
||||||
'''
|
'''
|
||||||
|
|
||||||
[tool.flake8]
|
[tool.ruff]
|
||||||
ignore = [
|
fix = true
|
||||||
# Whitespace before ':' ( https://www.flake8rules.com/rules/E203.html )
|
target-version = "py311"
|
||||||
"E203"
|
src = ["app"]
|
||||||
]
|
line-length=88
|
||||||
max-line-length=88
|
ignore = []
|
||||||
max-complexity = 15
|
select = ["B", "C", "E", "F", "W", "B9", "I001"]
|
||||||
select = "B,C,E,F,W,T4,B9"
|
|
||||||
exclude = [
|
exclude = [
|
||||||
# No need to traverse our git directory
|
# No need to traverse our git directory
|
||||||
".git",
|
".git",
|
||||||
# There's no value in checking cache directories
|
# There's no value in checking cache directories
|
||||||
"__pycache__",
|
"__pycache__",
|
||||||
# The conf file is mostly autogenerated, ignore it
|
# The conf file is mostly autogenerated, ignore it
|
||||||
"src/app/alembic/*",
|
"src/app/alembic",
|
||||||
# The old directory contains Flake8 2.0
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.isort]
|
[tool.ruff.flake8-bugbear]
|
||||||
profile = "black"
|
extend-immutable-calls = ["fastapi.File", "fastapi.Form", "fastapi.Security"]
|
||||||
only_sections = true
|
|
||||||
force_sort_within_sections = true
|
[tool.ruff.mccabe]
|
||||||
lines_after_imports = 2
|
max-complexity = 15
|
||||||
lexicographical = true
|
|
||||||
sections = ["FUTURE", "STDLIB", "BASEFRAMEWORK", "FRAMEWORKEXT", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
|
[tool.ruff.isort]
|
||||||
known_baseframework = ["fastapi",]
|
known-first-party = ["core", "app"]
|
||||||
known_frameworkext = ["starlette",]
|
|
||||||
src_paths = ["src"]
|
# 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
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
response = httpx.get("http://localhost:8080/healthcheck")
|
response = httpx.get("http://localhost:8080/healthcheck")
|
||||||
print(f"HEALTHCHECK STATUS: {response.status_code}")
|
print(f"HEALTHCHECK STATUS: {response.status_code}")
|
||||||
exit(0 if response.status_code == 200 else 1)
|
exit(0 if response.status_code == 200 else 1)
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
from sqlalchemy.engine import create_engine
|
|
||||||
|
|
||||||
from core.db import DATABASE_URL
|
from core.db import DATABASE_URL
|
||||||
|
from sqlalchemy.engine import create_engine
|
||||||
|
|
||||||
myPath = os.path.dirname(os.path.abspath(__file__))
|
myPath = os.path.dirname(os.path.abspath(__file__))
|
||||||
sys.path.insert(0, myPath + "/../../")
|
sys.path.insert(0, myPath + "/../../")
|
||||||
@@ -15,7 +13,6 @@ config = context.config
|
|||||||
|
|
||||||
from app.models import BaseMeta
|
from app.models import BaseMeta
|
||||||
|
|
||||||
|
|
||||||
target_metadata = BaseMeta.metadata
|
target_metadata = BaseMeta.metadata
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from fastapi import Security, HTTPException, status
|
from fastapi import HTTPException, Security, status
|
||||||
|
|
||||||
from core.auth import default_security
|
from core.auth import default_security
|
||||||
from core.config import env_config
|
from core.config import env_config
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
import ormar
|
import ormar
|
||||||
|
|
||||||
from core.db import metadata, database
|
from core.db import database, metadata
|
||||||
|
|
||||||
|
|
||||||
class BaseMeta(ormar.ModelMeta):
|
class BaseMeta(ormar.ModelMeta):
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from app.models import User, Language
|
from app.models import Language, User
|
||||||
|
|
||||||
|
|
||||||
async def update_user_allowed_langs(user: User, new_allowed_langs: list[str]) -> bool:
|
async def update_user_allowed_langs(user: User, new_allowed_langs: list[str]) -> bool:
|
||||||
user_allowed_langs = cast(list[Language], user.allowed_langs)
|
user_allowed_langs = cast(list[Language], user.allowed_langs)
|
||||||
|
|
||||||
exists_langs = set(lang.code for lang in user_allowed_langs)
|
exists_langs = {lang.code for lang in user_allowed_langs}
|
||||||
new_langs = set(new_allowed_langs)
|
new_langs = set(new_allowed_langs)
|
||||||
|
|
||||||
to_delete = exists_langs - new_langs
|
to_delete = exists_langs - new_langs
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
from fastapi import HTTPException, status
|
|
||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
|
from fastapi import HTTPException, status
|
||||||
from redis import asyncio as aioredis
|
from redis import asyncio as aioredis
|
||||||
|
|
||||||
from app.models import User
|
from app.models import User
|
||||||
@@ -134,9 +133,9 @@ class UsersDataManager:
|
|||||||
if new_data[key] != old_data[key]:
|
if new_data[key] != old_data[key]:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if allowed_langs and set(allowed_langs) != set(
|
if allowed_langs and set(allowed_langs) != {
|
||||||
[lang.code for lang in old_user.allowed_langs]
|
lang.code for lang in old_user.allowed_langs
|
||||||
):
|
}:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from fastapi import APIRouter, HTTPException, status, Depends, Request
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||||
|
|
||||||
from fastapi_pagination import Page, Params
|
from fastapi_pagination import Page, Params
|
||||||
from fastapi_pagination.ext.ormar import paginate
|
from fastapi_pagination.ext.ormar import paginate
|
||||||
from redis import asyncio as aioredis
|
from redis import asyncio as aioredis
|
||||||
|
|
||||||
from app.depends import check_token
|
from app.depends import check_token
|
||||||
from app.models import User, Language, UserActivity
|
from app.models import Language, User, UserActivity
|
||||||
from app.serializers import (
|
from app.serializers import (
|
||||||
UserCreateOrUpdate,
|
|
||||||
UserUpdate,
|
|
||||||
UserDetail,
|
|
||||||
CreateLanguage,
|
CreateLanguage,
|
||||||
LanguageDetail,
|
LanguageDetail,
|
||||||
|
UserCreateOrUpdate,
|
||||||
|
UserDetail,
|
||||||
|
UserUpdate,
|
||||||
)
|
)
|
||||||
from app.services.users_data_manager import UsersDataManager
|
from app.services.users_data_manager import UsersDataManager
|
||||||
|
|
||||||
|
|
||||||
users_router = APIRouter(
|
users_router = APIRouter(
|
||||||
prefix="/users", tags=["users"], dependencies=[Depends(check_token)]
|
prefix="/users", tags=["users"], dependencies=[Depends(check_token)]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.responses import ORJSONResponse
|
from fastapi.responses import ORJSONResponse
|
||||||
|
|
||||||
from fastapi_pagination import add_pagination
|
from fastapi_pagination import add_pagination
|
||||||
from prometheus_fastapi_instrumentator import Instrumentator
|
from prometheus_fastapi_instrumentator import Instrumentator
|
||||||
from redis import asyncio as aioredis
|
from redis import asyncio as aioredis
|
||||||
|
|
||||||
from app.views import users_router, languages_router, healthcheck_router
|
from app.views import healthcheck_router, languages_router, users_router
|
||||||
from core.config import env_config
|
from core.config import env_config
|
||||||
from core.db import database
|
from core.db import database
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from fastapi.security import APIKeyHeader
|
from fastapi.security import APIKeyHeader
|
||||||
|
|
||||||
|
|
||||||
default_security = APIKeyHeader(name="Authorization")
|
default_security = APIKeyHeader(name="Authorization")
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from sqlalchemy import MetaData
|
|||||||
|
|
||||||
from core.config import env_config
|
from core.config import env_config
|
||||||
|
|
||||||
|
|
||||||
DATABASE_URL = (
|
DATABASE_URL = (
|
||||||
f"postgresql://{env_config.POSTGRES_USER}:{quote(env_config.POSTGRES_PASSWORD)}@"
|
f"postgresql://{env_config.POSTGRES_USER}:{quote(env_config.POSTGRES_PASSWORD)}@"
|
||||||
f"{env_config.POSTGRES_HOST}:{env_config.POSTGRES_PORT}/{env_config.POSTGRES_DB}"
|
f"{env_config.POSTGRES_HOST}:{env_config.POSTGRES_PORT}/{env_config.POSTGRES_DB}"
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
|||||||
from core.app import start_app
|
from core.app import start_app
|
||||||
from core.config import env_config
|
from core.config import env_config
|
||||||
|
|
||||||
|
|
||||||
sentry_sdk.init(dsn=env_config.SENTRY_SDN)
|
sentry_sdk.init(dsn=env_config.SENTRY_SDN)
|
||||||
|
|
||||||
app = SentryAsgiMiddleware(start_app())
|
app = SentryAsgiMiddleware(start_app())
|
||||||
|
|||||||
Reference in New Issue
Block a user