refactor: modernize code quality tooling with Ruff

- Replace black, isort, and flake8 with Ruff (all-in-one linter and formatter)
- Add comprehensive pyproject.toml configuration
- Simplify Makefile code quality targets
- Configure exclusions for venv/.venv in pyproject.toml
- Auto-fix 1,359 linting issues across codebase

Benefits:
- Much faster builds (Ruff is written in Rust)
- Single tool replaces multiple tools
- More comprehensive rule set (UP, B, C4, SIM, PIE, RET, Q)
- All configuration centralized in pyproject.toml
- Better import sorting and formatting consistency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 19:37:38 +01:00
parent 21c13ca39b
commit 238c1ec9b8
169 changed files with 2183 additions and 1784 deletions

View File

@@ -12,7 +12,6 @@ Also extracts clean_path for nested routing patterns.
"""
import logging
from typing import Optional
from fastapi import Request
from sqlalchemy import func
@@ -31,7 +30,7 @@ class VendorContextManager:
"""Manages vendor context detection for multi-tenant routing."""
@staticmethod
def detect_vendor_context(request: Request) -> Optional[dict]:
def detect_vendor_context(request: Request) -> dict | None:
"""
Detect vendor context from request.
@@ -106,7 +105,7 @@ class VendorContextManager:
return None
@staticmethod
def get_vendor_from_context(db: Session, context: dict) -> Optional[Vendor]:
def get_vendor_from_context(db: Session, context: dict) -> Vendor | None:
"""
Get vendor from database using context information.
@@ -142,11 +141,10 @@ class VendorContextManager:
f"[OK] Vendor found via custom domain: {domain}{vendor.name}"
)
return vendor
else:
logger.warning(
f"No active vendor found for custom domain: {domain}"
)
return None
logger.warning(
f"No active vendor found for custom domain: {domain}"
)
return None
# Method 2 & 3: Subdomain or path-based lookup
if "subdomain" in context:
@@ -169,7 +167,7 @@ class VendorContextManager:
return vendor
@staticmethod
def extract_clean_path(request: Request, vendor_context: Optional[dict]) -> str:
def extract_clean_path(request: Request, vendor_context: dict | None) -> str:
"""
Extract clean path without vendor prefix for routing.
@@ -217,7 +215,7 @@ class VendorContextManager:
return request.url.path.startswith("/api/v1/shop/")
@staticmethod
def extract_vendor_from_referer(request: Request) -> Optional[dict]:
def extract_vendor_from_referer(request: Request) -> dict | None:
"""
Extract vendor context from Referer header.
@@ -250,7 +248,7 @@ class VendorContextManager:
referer_host = referer_host.split(":")[0]
logger.debug(
f"[VENDOR] Extracting vendor from Referer",
"[VENDOR] Extracting vendor from Referer",
extra={
"referer": referer,
"referer_host": referer_host,
@@ -449,7 +447,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
request.state.clean_path = request.url.path
logger.debug(
f"[VENDOR_CONTEXT] Vendor detected from Referer for shop API",
"[VENDOR_CONTEXT] Vendor detected from Referer for shop API",
extra={
"vendor_id": vendor.id,
"vendor_name": vendor.name,
@@ -463,7 +461,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
)
else:
logger.warning(
f"[WARNING] Vendor context from Referer but vendor not found",
"[WARNING] Vendor context from Referer but vendor not found",
extra={
"context": vendor_context,
"detection_method": vendor_context.get(
@@ -479,7 +477,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
db.close()
else:
logger.warning(
f"[VENDOR] Shop API request without Referer header",
"[VENDOR] Shop API request without Referer header",
extra={"path": request.url.path},
)
request.state.vendor = None
@@ -518,7 +516,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
)
logger.debug(
f"[VENDOR_CONTEXT] Vendor detected",
"[VENDOR_CONTEXT] Vendor detected",
extra={
"vendor_id": vendor.id,
"vendor_name": vendor.name,
@@ -530,7 +528,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
)
else:
logger.warning(
f"[WARNING] Vendor context detected but vendor not found",
"[WARNING] Vendor context detected but vendor not found",
extra={
"context": vendor_context,
"detection_method": vendor_context.get("detection_method"),
@@ -543,7 +541,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
db.close()
else:
logger.debug(
f"[VENDOR] No vendor context detected",
"[VENDOR] No vendor context detected",
extra={
"path": request.url.path,
"host": request.headers.get("host", ""),
@@ -557,7 +555,7 @@ class VendorContextMiddleware(BaseHTTPMiddleware):
return await call_next(request)
def get_current_vendor(request: Request) -> Optional[Vendor]:
def get_current_vendor(request: Request) -> Vendor | None:
"""Helper function to get current vendor from request state."""
return getattr(request.state, "vendor", None)