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

@@ -30,15 +30,17 @@ Routes:
- GET /code-quality/violations/{violation_id} → Violation details (auth required)
"""
from typing import Optional
from fastapi import APIRouter, Depends, Path, Request
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session
from app.api.deps import (get_current_admin_from_cookie_or_header,
get_current_admin_optional, get_db)
from app.api.deps import (
get_current_admin_from_cookie_or_header,
get_current_admin_optional,
get_db,
)
from models.database.user import User
router = APIRouter()
@@ -52,7 +54,7 @@ templates = Jinja2Templates(directory="app/templates")
@router.get("/", response_class=RedirectResponse, include_in_schema=False)
async def admin_root(
current_user: Optional[User] = Depends(get_current_admin_optional),
current_user: User | None = Depends(get_current_admin_optional),
):
"""
Redirect /admin/ based on authentication status.
@@ -69,7 +71,7 @@ async def admin_root(
@router.get("/login", response_class=HTMLResponse, include_in_schema=False)
async def admin_login_page(
request: Request, current_user: Optional[User] = Depends(get_current_admin_optional)
request: Request, current_user: User | None = Depends(get_current_admin_optional)
):
"""
Render admin login page.

View File

@@ -129,7 +129,7 @@ def get_shop_context(request: Request, db: Session = None, **extra_context) -> d
)
except Exception as e:
logger.error(
f"[SHOP_CONTEXT] Failed to load navigation pages",
"[SHOP_CONTEXT] Failed to load navigation pages",
extra={"error": str(e), "vendor_id": vendor.id if vendor else None},
)
@@ -149,7 +149,7 @@ def get_shop_context(request: Request, db: Session = None, **extra_context) -> d
context.update(extra_context)
logger.debug(
f"[SHOP_CONTEXT] Context built",
"[SHOP_CONTEXT] Context built",
extra={
"vendor_id": vendor.id if vendor else None,
"vendor_name": vendor.name if vendor else None,
@@ -179,7 +179,7 @@ async def shop_products_page(request: Request, db: Session = Depends(get_db)):
Shows featured products and categories.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -203,7 +203,7 @@ async def shop_product_detail_page(
Shows product information, images, reviews, and buy options.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -227,7 +227,7 @@ async def shop_category_page(
Shows all products in a specific category.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -247,7 +247,7 @@ async def shop_cart_page(request: Request):
Shows cart items and allows quantity updates.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -265,7 +265,7 @@ async def shop_checkout_page(request: Request):
Handles shipping, payment, and order confirmation.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -283,7 +283,7 @@ async def shop_search_page(request: Request):
Shows products matching search query.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -306,7 +306,7 @@ async def shop_register_page(request: Request):
No authentication required.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -326,7 +326,7 @@ async def shop_login_page(request: Request):
No authentication required.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -348,7 +348,7 @@ async def shop_forgot_password_page(request: Request):
Allows customers to reset their password.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -373,7 +373,7 @@ async def shop_account_root(request: Request):
Redirect /shop/account or /shop/account/ to dashboard.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -414,7 +414,7 @@ async def shop_account_dashboard_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -439,7 +439,7 @@ async def shop_orders_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -467,7 +467,7 @@ async def shop_order_detail_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -493,7 +493,7 @@ async def shop_profile_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -518,7 +518,7 @@ async def shop_addresses_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -543,7 +543,7 @@ async def shop_wishlist_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -568,7 +568,7 @@ async def shop_settings_page(
Requires customer authentication.
"""
logger.debug(
f"[SHOP_HANDLER] shop_products_page REACHED",
"[SHOP_HANDLER] shop_products_page REACHED",
extra={
"path": request.url.path,
"vendor": getattr(request.state, "vendor", "NOT SET"),
@@ -609,7 +609,7 @@ async def generic_content_page(
from fastapi import HTTPException
logger.debug(
f"[SHOP_HANDLER] generic_content_page REACHED",
"[SHOP_HANDLER] generic_content_page REACHED",
extra={
"path": request.url.path,
"slug": slug,
@@ -628,7 +628,7 @@ async def generic_content_page(
if not page:
logger.warning(
f"[SHOP_HANDLER] Content page not found",
"[SHOP_HANDLER] Content page not found",
extra={
"slug": slug,
"vendor_id": vendor_id,
@@ -638,7 +638,7 @@ async def generic_content_page(
raise HTTPException(status_code=404, detail=f"Page not found: {slug}")
logger.info(
f"[SHOP_HANDLER] Content page found",
"[SHOP_HANDLER] Content page found",
extra={
"slug": slug,
"page_id": page.id,
@@ -709,14 +709,14 @@ async def debug_context(request: Request):
<pre>{json.dumps(debug_info, indent=2)}</pre>
<h2>Status</h2>
<p class="{'good' if vendor else 'bad'}">
Vendor: {'✓ Found' if vendor else '✗ Not Found'}
<p class="{"good" if vendor else "bad"}">
Vendor: {"✓ Found" if vendor else "✗ Not Found"}
</p>
<p class="{'good' if theme else 'bad'}">
Theme: {'✓ Found' if theme else '✗ Not Found'}
<p class="{"good" if theme else "bad"}">
Theme: {"✓ Found" if theme else "✗ Not Found"}
</p>
<p class="{'good' if str(getattr(request.state, 'context_type', 'NOT SET')) == 'shop' else 'bad'}">
Context Type: {str(getattr(request.state, 'context_type', 'NOT SET'))}
<p class="{"good" if str(getattr(request.state, "context_type", "NOT SET")) == "shop" else "bad"}">
Context Type: {str(getattr(request.state, "context_type", "NOT SET"))}
</p>
</body>
</html>

View File

@@ -22,15 +22,17 @@ Routes:
"""
import logging
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Path, Request
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session
from app.api.deps import (get_current_vendor_from_cookie_or_header,
get_current_vendor_optional, get_db)
from app.api.deps import (
get_current_vendor_from_cookie_or_header,
get_current_vendor_optional,
get_db,
)
from app.services.content_page_service import content_page_service
from models.database.user import User
@@ -57,7 +59,7 @@ async def vendor_root_no_slash(vendor_code: str = Path(..., description="Vendor
@router.get("/{vendor_code}/", response_class=RedirectResponse, include_in_schema=False)
async def vendor_root(
vendor_code: str = Path(..., description="Vendor code"),
current_user: Optional[User] = Depends(get_current_vendor_optional),
current_user: User | None = Depends(get_current_vendor_optional),
):
"""
Redirect /vendor/{code}/ based on authentication status.
@@ -78,7 +80,7 @@ async def vendor_root(
async def vendor_login_page(
request: Request,
vendor_code: str = Path(..., description="Vendor code"),
current_user: Optional[User] = Depends(get_current_vendor_optional),
current_user: User | None = Depends(get_current_vendor_optional),
):
"""
Render vendor login page.
@@ -374,7 +376,7 @@ async def vendor_content_page(
shadowing other specific routes.
"""
logger.debug(
f"[VENDOR_HANDLER] vendor_content_page REACHED",
"[VENDOR_HANDLER] vendor_content_page REACHED",
extra={
"path": request.url.path,
"vendor_code": vendor_code,