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

@@ -9,20 +9,18 @@ This module provides:
"""
import logging
from datetime import datetime, timezone
from typing import Dict, List, Optional
from sqlalchemy import and_
from sqlalchemy.orm import Session
from app.exceptions import (CartItemNotFoundException, CartValidationException,
InsufficientInventoryForCartException,
InvalidCartQuantityException,
ProductNotAvailableForCartException,
ProductNotFoundException)
from app.exceptions import (
CartItemNotFoundException,
InsufficientInventoryForCartException,
InvalidCartQuantityException,
ProductNotFoundException,
)
from models.database.cart import CartItem
from models.database.product import Product
from models.database.vendor import Vendor
logger = logging.getLogger(__name__)
@@ -30,7 +28,7 @@ logger = logging.getLogger(__name__)
class CartService:
"""Service for managing shopping carts."""
def get_cart(self, db: Session, vendor_id: int, session_id: str) -> Dict:
def get_cart(self, db: Session, vendor_id: int, session_id: str) -> dict:
"""
Get cart contents for a session.
@@ -43,7 +41,7 @@ class CartService:
Cart data with items and totals
"""
logger.info(
f"[CART_SERVICE] get_cart called",
"[CART_SERVICE] get_cart called",
extra={
"vendor_id": vendor_id,
"session_id": session_id,
@@ -111,7 +109,7 @@ class CartService:
session_id: str,
product_id: int,
quantity: int = 1,
) -> Dict:
) -> dict:
"""
Add product to cart.
@@ -130,7 +128,7 @@ class CartService:
InsufficientInventoryException: If not enough inventory
"""
logger.info(
f"[CART_SERVICE] add_to_cart called",
"[CART_SERVICE] add_to_cart called",
extra={
"vendor_id": vendor_id,
"session_id": session_id,
@@ -154,7 +152,7 @@ class CartService:
if not product:
logger.error(
f"[CART_SERVICE] Product not found",
"[CART_SERVICE] Product not found",
extra={"product_id": product_id, "vendor_id": vendor_id},
)
raise ProductNotFoundException(product_id=product_id, vendor_id=vendor_id)
@@ -191,7 +189,7 @@ class CartService:
# Check inventory for new total quantity
if product.available_inventory < new_quantity:
logger.warning(
f"[CART_SERVICE] Insufficient inventory for update",
"[CART_SERVICE] Insufficient inventory for update",
extra={
"product_id": product_id,
"current_in_cart": existing_item.quantity,
@@ -212,7 +210,7 @@ class CartService:
db.refresh(existing_item)
logger.info(
f"[CART_SERVICE] Updated existing cart item",
"[CART_SERVICE] Updated existing cart item",
extra={"cart_item_id": existing_item.id, "new_quantity": new_quantity},
)
@@ -221,50 +219,49 @@ class CartService:
"product_id": product_id,
"quantity": new_quantity,
}
else:
# Check inventory for new item
if product.available_inventory < quantity:
logger.warning(
f"[CART_SERVICE] Insufficient inventory",
extra={
"product_id": product_id,
"requested": quantity,
"available": product.available_inventory,
},
)
raise InsufficientInventoryForCartException(
product_id=product_id,
product_name=product.marketplace_product.title,
requested=quantity,
available=product.available_inventory,
)
# Create new cart item
cart_item = CartItem(
vendor_id=vendor_id,
session_id=session_id,
product_id=product_id,
quantity=quantity,
price_at_add=current_price,
)
db.add(cart_item)
db.commit()
db.refresh(cart_item)
logger.info(
f"[CART_SERVICE] Created new cart item",
# Check inventory for new item
if product.available_inventory < quantity:
logger.warning(
"[CART_SERVICE] Insufficient inventory",
extra={
"cart_item_id": cart_item.id,
"quantity": quantity,
"price": current_price,
"product_id": product_id,
"requested": quantity,
"available": product.available_inventory,
},
)
raise InsufficientInventoryForCartException(
product_id=product_id,
product_name=product.marketplace_product.title,
requested=quantity,
available=product.available_inventory,
)
return {
"message": "Product added to cart",
"product_id": product_id,
# Create new cart item
cart_item = CartItem(
vendor_id=vendor_id,
session_id=session_id,
product_id=product_id,
quantity=quantity,
price_at_add=current_price,
)
db.add(cart_item)
db.commit()
db.refresh(cart_item)
logger.info(
"[CART_SERVICE] Created new cart item",
extra={
"cart_item_id": cart_item.id,
"quantity": quantity,
}
"price": current_price,
},
)
return {
"message": "Product added to cart",
"product_id": product_id,
"quantity": quantity,
}
def update_cart_item(
self,
@@ -273,7 +270,7 @@ class CartService:
session_id: str,
product_id: int,
quantity: int,
) -> Dict:
) -> dict:
"""
Update quantity of item in cart.
@@ -344,7 +341,7 @@ class CartService:
db.refresh(cart_item)
logger.info(
f"[CART_SERVICE] Updated cart item quantity",
"[CART_SERVICE] Updated cart item quantity",
extra={
"cart_item_id": cart_item.id,
"product_id": product_id,
@@ -360,7 +357,7 @@ class CartService:
def remove_from_cart(
self, db: Session, vendor_id: int, session_id: str, product_id: int
) -> Dict:
) -> dict:
"""
Remove item from cart.
@@ -398,7 +395,7 @@ class CartService:
db.commit()
logger.info(
f"[CART_SERVICE] Removed item from cart",
"[CART_SERVICE] Removed item from cart",
extra={
"cart_item_id": cart_item.id,
"product_id": product_id,
@@ -408,7 +405,7 @@ class CartService:
return {"message": "Item removed from cart", "product_id": product_id}
def clear_cart(self, db: Session, vendor_id: int, session_id: str) -> Dict:
def clear_cart(self, db: Session, vendor_id: int, session_id: str) -> dict:
"""
Clear all items from cart.
@@ -432,7 +429,7 @@ class CartService:
db.commit()
logger.info(
f"[CART_SERVICE] Cleared cart",
"[CART_SERVICE] Cleared cart",
extra={
"session_id": session_id,
"vendor_id": vendor_id,