Added Ruff linting

This commit is contained in:
florian committed 2026-10-13 10:27:58 +02:00
1 parent aa612103f4
commit b3c16f78d6
5 files changed
+34 -5

No files matched your search

+28
View File
@@ -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",
]
+1
View File
@@ -0,0 +1 @@
ruff==0.17.0
+2 -2
View File
@@ -106,10 +106,10 @@ async def pull_notifications(
) )
except (AMQPException, OSError) as e: except (AMQPException, OSError) as e:
logger.error(f"[FastAPI] RabbitMQ unavailable for user_id={user_id}: {e}") logger.error(f"[FastAPI] RabbitMQ unavailable for user_id={user_id}: {e}")
raise HTTPException(status_code=503, detail="Message broker unavailable") raise HTTPException(status_code=503, detail="Message broker unavailable") from e
except RuntimeError as e: except RuntimeError as e:
logger.error(f"[FastAPI] Consumer not ready: {e}") logger.error(f"[FastAPI] Consumer not ready: {e}")
raise HTTPException(status_code=503, detail="Service not ready") raise HTTPException(status_code=503, detail="Service not ready") from e
logger.info(f"[FastAPI] Retrieved {len(messages)} message(s) for user_id={user_id}") logger.info(f"[FastAPI] Retrieved {len(messages)} message(s) for user_id={user_id}")
return PullResponse(messages=messages, count=len(messages), has_more=len(messages) >= MAX_MESSAGES) return PullResponse(messages=messages, count=len(messages), has_more=len(messages) >= MAX_MESSAGES)
+1 -1
View File
@@ -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")
+2 -2
View File
@@ -78,11 +78,11 @@ class RabbitMQConsumer:
- Only one fetch per user runs at a time; different users run concurrently. - Only one fetch per user runs at a time; different users run concurrently.
- Messages are acked after the whole batch has been read, so an error mid-read - Messages are acked after the whole batch has been read, so an error mid-read
puts the batch back on the queue and re-raises. puts the batch back on the queue and re-raises.
- Undecodable messages are rejected without requeue (discarded). - Undecodable messages are rejected without requeue (discarded).
- Returns an empty list if nothing is queued. - Returns an empty list if nothing is queued.
- Delivery is at-most-once towards the client: messages are acked before the - Delivery is at-most-once towards the client: messages are acked before the
HTTP response is sent. HTTP response is sent.
""" """
if self._closing: if self._closing: