Added Ruff linting
This commit is contained in:
1 parent
8f6f65b143
commit
4e088547ff
5 files changed
+54
-21
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
[tool.ruff]
|
||||||
|
line-length = 120
|
||||||
|
target-version = "py312"
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = [
|
||||||
|
"E", "F", # pycodestyle errors, pyflakes (unused imports/variables, undefined names)
|
||||||
|
"I", # import sorting (replaces isort)
|
||||||
|
"B", # bugbear: likely bugs
|
||||||
|
"ASYNC", # async mistakes
|
||||||
|
"RUF006", # un-referenced asyncio.create_task (tasks can be garbage-collected)
|
||||||
|
]
|
||||||
|
ignore = ["E501"]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
known-first-party = ["db_module", "metrics_server", "rabbitmq_handler", "secret_manager",
|
||||||
|
"simple_logger_handler", "uvicorn_logger_config", "validator"]
|
||||||
|
|
||||||
|
[tool.ruff.format]
|
||||||
|
indent-style = "tab"
|
||||||
|
|
||||||
|
[tool.ruff.lint.flake8-bugbear]
|
||||||
|
extend-immutable-calls = [
|
||||||
|
"fastapi.Depends",
|
||||||
|
"fastapi.Query",
|
||||||
|
"fastapi.Header",
|
||||||
|
"fastapi.Body",
|
||||||
|
"fastapi.Security",
|
||||||
|
]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ruff==0.17.0
|
||||||
+21
-19
@@ -1,23 +1,25 @@
|
|||||||
from fastapi import FastAPI, Depends, HTTPException, Request
|
import asyncio
|
||||||
|
import os
|
||||||
|
import uuid
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
from hashlib import sha256
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
import uvicorn
|
||||||
|
from fastapi import Depends, FastAPI, HTTPException, Request
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from fastapi.security.api_key import APIKeyHeader
|
from fastapi.security.api_key import APIKeyHeader
|
||||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
||||||
from typing import Optional,List
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from validator import is_valid_platform,is_valid_token,verify_api_key
|
from starlette.exceptions import HTTPException as StarletteHTTPException
|
||||||
from secret_manager.fernet_encryption import encrypt_token
|
|
||||||
from secret_manager import cleanup_secret_files, return_credentials
|
from db_module import close_connection_pool, create_connection_pool, get_db, start_healthcheck_thread
|
||||||
from db_module import get_db, create_connection_pool, close_connection_pool, start_healthcheck_thread
|
|
||||||
from simple_logger_handler import setup_logger, LOG_LEVEL
|
|
||||||
import uuid
|
|
||||||
from hashlib import sha256
|
|
||||||
import uvicorn
|
|
||||||
from contextlib import asynccontextmanager
|
|
||||||
from metrics_server import REQUEST_COUNTER
|
from metrics_server import REQUEST_COUNTER
|
||||||
import asyncio
|
from secret_manager import cleanup_secret_files, return_credentials
|
||||||
|
from secret_manager.fernet_encryption import encrypt_token
|
||||||
|
from simple_logger_handler import LOG_LEVEL, setup_logger
|
||||||
from uvicorn_logger_config import LOGGING_CONFIG
|
from uvicorn_logger_config import LOGGING_CONFIG
|
||||||
import httpx
|
from validator import is_valid_platform, is_valid_token, verify_api_key
|
||||||
import os
|
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
api_key_header = APIKeyHeader(name="X-API-Key")
|
api_key_header = APIKeyHeader(name="X-API-Key")
|
||||||
@@ -207,7 +209,7 @@ def register_token(
|
|||||||
logger.info(f"[FastAPI] Success: Registering token for user_id={user_id}, platform={request_data.platform}")
|
logger.info(f"[FastAPI] Success: Registering token for user_id={user_id}, platform={request_data.platform}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"[FastAPI] Failed to register token for user_id={user_id}: {e}")
|
logger.exception(f"[FastAPI] Failed to register token for user_id={user_id}: {e}")
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||||
|
|
||||||
return {"status":"registered"}
|
return {"status":"registered"}
|
||||||
|
|
||||||
@@ -230,7 +232,7 @@ def unregister_token(
|
|||||||
""", ('expired', hashed_token))
|
""", ('expired', hashed_token))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"[FastAPI] Failed to unregister token for user_id={user_id}: {e}")
|
logger.exception(f"[FastAPI] Failed to unregister token for user_id={user_id}: {e}")
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||||
logger.info(f"[FastAPI] Success: Unregistering token for user_id={user_id}, platform={request_data.platform}")
|
logger.info(f"[FastAPI] Success: Unregistering token for user_id={user_id}, platform={request_data.platform}")
|
||||||
return {"status":"unregistered"}
|
return {"status":"unregistered"}
|
||||||
|
|
||||||
@@ -248,10 +250,10 @@ async def pull_notifications(
|
|||||||
data = PullResponse.model_validate(resp.json())
|
data = PullResponse.model_validate(resp.json())
|
||||||
except httpx.HTTPStatusError as e:
|
except httpx.HTTPStatusError as e:
|
||||||
logger.error(f"[FastAPI] Upstream returned {e.response.status_code} for user_id={user_id}")
|
logger.error(f"[FastAPI] Upstream returned {e.response.status_code} for user_id={user_id}")
|
||||||
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable")
|
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable") from e
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error(f"[FastAPI] Backend-API-Internal call failed with ValueError for user_id={user_id}: {e!r}")
|
logger.error(f"[FastAPI] Backend-API-Internal call failed with ValueError for user_id={user_id}: {e!r}")
|
||||||
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable")
|
raise HTTPException(status_code=502, detail="Backend-API-Internal unavailable") from e
|
||||||
|
|
||||||
logger.info(f"[FastAPI] Returning {len(data.messages)} message(s) for user_id={user_id}, has_more={data.has_more}")
|
logger.info(f"[FastAPI] Returning {len(data.messages)} message(s) for user_id={user_id}, has_more={data.has_more}")
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from fastapi import FastAPI, Response
|
from fastapi import FastAPI, Response
|
||||||
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, Counter
|
from prometheus_client import CONTENT_TYPE_LATEST, Counter, generate_latest
|
||||||
|
|
||||||
metrics_api = FastAPI(title="Metrics Server", description="Prometheus metrics endpoint")
|
metrics_api = FastAPI(title="Metrics Server", description="Prometheus metrics endpoint")
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
from argon2 import PasswordHasher
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from argon2 import PasswordHasher
|
||||||
|
|
||||||
from simple_logger_handler import setup_logger
|
from simple_logger_handler import setup_logger
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
|
|||||||
Reference in new issue
Block a user