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:
80
main.py
80
main.py
@@ -18,7 +18,7 @@ if sys.platform == "win32":
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")
|
||||
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request, Response
|
||||
@@ -35,11 +35,13 @@ from app.core.database import get_db
|
||||
from app.core.lifespan import lifespan
|
||||
from app.exceptions import ServiceUnavailableException
|
||||
from app.exceptions.handler import setup_exception_handlers
|
||||
|
||||
# Import page routers
|
||||
from app.routes import admin_pages, shop_pages, vendor_pages
|
||||
from middleware.context import ContextMiddleware
|
||||
from middleware.logging import LoggingMiddleware
|
||||
from middleware.theme_context import ThemeContextMiddleware
|
||||
|
||||
# Import REFACTORED class-based middleware
|
||||
from middleware.vendor_context import VendorContextMiddleware
|
||||
|
||||
@@ -259,9 +261,8 @@ async def vendor_root_path(
|
||||
return templates.TemplateResponse(
|
||||
template_path, get_shop_context(request, db=db, page=landing_page)
|
||||
)
|
||||
else:
|
||||
# No landing page - redirect to shop
|
||||
return RedirectResponse(url=f"/vendors/{vendor_code}/shop/", status_code=302)
|
||||
# No landing page - redirect to shop
|
||||
return RedirectResponse(url=f"/vendors/{vendor_code}/shop/", status_code=302)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -317,18 +318,17 @@ async def platform_homepage(request: Request, db: Session = Depends(get_db)):
|
||||
"footer_pages": footer_pages,
|
||||
},
|
||||
)
|
||||
else:
|
||||
# Fallback to default static template
|
||||
logger.info("[PLATFORM] No CMS homepage found, using default template")
|
||||
# Fallback to default static template
|
||||
logger.info("[PLATFORM] No CMS homepage found, using default template")
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"platform/homepage-default.html",
|
||||
{
|
||||
"request": request,
|
||||
"header_pages": header_pages,
|
||||
"footer_pages": footer_pages,
|
||||
},
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
"platform/homepage-default.html",
|
||||
{
|
||||
"request": request,
|
||||
"header_pages": header_pages,
|
||||
"footer_pages": footer_pages,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@app.get("/{slug}", response_class=HTMLResponse, include_in_schema=False)
|
||||
@@ -349,7 +349,10 @@ async def platform_content_page(
|
||||
|
||||
# Load page from CMS
|
||||
page = content_page_service.get_page_for_vendor(
|
||||
db, slug=slug, vendor_id=None, include_unpublished=False # Platform pages only
|
||||
db,
|
||||
slug=slug,
|
||||
vendor_id=None,
|
||||
include_unpublished=False, # Platform pages only
|
||||
)
|
||||
|
||||
if not page:
|
||||
@@ -430,30 +433,27 @@ async def root(request: Request, db: Session = Depends(get_db)):
|
||||
return templates.TemplateResponse(
|
||||
template_path, get_shop_context(request, db=db, page=landing_page)
|
||||
)
|
||||
else:
|
||||
# No landing page - redirect to shop
|
||||
vendor_context = getattr(request.state, "vendor_context", None)
|
||||
access_method = (
|
||||
vendor_context.get("detection_method", "unknown")
|
||||
if vendor_context
|
||||
else "unknown"
|
||||
)
|
||||
# No landing page - redirect to shop
|
||||
vendor_context = getattr(request.state, "vendor_context", None)
|
||||
access_method = (
|
||||
vendor_context.get("detection_method", "unknown")
|
||||
if vendor_context
|
||||
else "unknown"
|
||||
)
|
||||
|
||||
if access_method == "path":
|
||||
full_prefix = (
|
||||
vendor_context.get("full_prefix", "/vendor/")
|
||||
if vendor_context
|
||||
else "/vendor/"
|
||||
)
|
||||
return RedirectResponse(
|
||||
url=f"{full_prefix}{vendor.subdomain}/shop/", status_code=302
|
||||
)
|
||||
else:
|
||||
# Domain/subdomain
|
||||
return RedirectResponse(url="/shop/", status_code=302)
|
||||
else:
|
||||
# No vendor - platform root
|
||||
return RedirectResponse(url="/documentation")
|
||||
if access_method == "path":
|
||||
full_prefix = (
|
||||
vendor_context.get("full_prefix", "/vendor/")
|
||||
if vendor_context
|
||||
else "/vendor/"
|
||||
)
|
||||
return RedirectResponse(
|
||||
url=f"{full_prefix}{vendor.subdomain}/shop/", status_code=302
|
||||
)
|
||||
# Domain/subdomain
|
||||
return RedirectResponse(url="/shop/", status_code=302)
|
||||
# No vendor - platform root
|
||||
return RedirectResponse(url="/documentation")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
@@ -464,7 +464,7 @@ def health_check(db: Session = Depends(get_db)):
|
||||
db.execute(text("SELECT 1"))
|
||||
return {
|
||||
"status": "healthy",
|
||||
"timestamp": datetime.now(timezone.utc),
|
||||
"timestamp": datetime.now(UTC),
|
||||
"message": f"{settings.project_name} v{settings.version}",
|
||||
"docs": {
|
||||
"swagger": "/docs",
|
||||
|
||||
Reference in New Issue
Block a user