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:
@@ -13,7 +13,6 @@ Note: Environment detection is handled by app.core.environment module.
|
||||
This module focuses purely on configuration storage and validation.
|
||||
"""
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
@@ -82,7 +81,7 @@ class Settings(BaseSettings):
|
||||
# =============================================================================
|
||||
# MIDDLEWARE & SECURITY
|
||||
# =============================================================================
|
||||
allowed_hosts: List[str] = ["*"] # Configure for production
|
||||
allowed_hosts: list[str] = ["*"] # Configure for production
|
||||
|
||||
# Rate Limiting
|
||||
rate_limit_enabled: bool = True
|
||||
@@ -93,7 +92,7 @@ class Settings(BaseSettings):
|
||||
# LOGGING
|
||||
# =============================================================================
|
||||
log_level: str = "INFO"
|
||||
log_file: Optional[str] = None
|
||||
log_file: str | None = None
|
||||
|
||||
# =============================================================================
|
||||
# PLATFORM DOMAIN CONFIGURATION
|
||||
@@ -138,9 +137,13 @@ settings = Settings()
|
||||
# ENVIRONMENT UTILITIES - Module-level functions
|
||||
# =============================================================================
|
||||
# Import environment detection utilities
|
||||
from app.core.environment import (get_environment, is_development,
|
||||
is_production, is_staging,
|
||||
should_use_secure_cookies)
|
||||
from app.core.environment import (
|
||||
get_environment,
|
||||
is_development,
|
||||
is_production,
|
||||
is_staging,
|
||||
should_use_secure_cookies,
|
||||
)
|
||||
|
||||
|
||||
def get_current_environment() -> str:
|
||||
@@ -188,7 +191,7 @@ def is_staging_environment() -> bool:
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def validate_production_settings() -> List[str]:
|
||||
def validate_production_settings() -> list[str]:
|
||||
"""
|
||||
Validate settings for production environment.
|
||||
|
||||
|
||||
@@ -31,18 +31,18 @@ def get_environment() -> EnvironmentType:
|
||||
env = os.getenv("ENV", "").lower()
|
||||
if env in ["development", "dev", "local"]:
|
||||
return "development"
|
||||
elif env in ["staging", "stage"]:
|
||||
if env in ["staging", "stage"]:
|
||||
return "staging"
|
||||
elif env in ["production", "prod"]:
|
||||
if env in ["production", "prod"]:
|
||||
return "production"
|
||||
|
||||
# Priority 2: ENVIRONMENT variable
|
||||
env = os.getenv("ENVIRONMENT", "").lower()
|
||||
if env in ["development", "dev", "local"]:
|
||||
return "development"
|
||||
elif env in ["staging", "stage"]:
|
||||
if env in ["staging", "stage"]:
|
||||
return "staging"
|
||||
elif env in ["production", "prod"]:
|
||||
if env in ["production", "prod"]:
|
||||
return "production"
|
||||
|
||||
# Priority 3: Auto-detect from common indicators
|
||||
|
||||
@@ -16,7 +16,7 @@ from sqlalchemy import text
|
||||
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
from .database import SessionLocal, engine
|
||||
from .database import engine
|
||||
from .logging import setup_logging
|
||||
|
||||
# Remove this import if not needed: from models.database.base import Base
|
||||
@@ -60,7 +60,6 @@ def check_database_ready():
|
||||
def get_migration_status():
|
||||
"""Get current Alembic migration status."""
|
||||
try:
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
|
||||
@@ -7,8 +7,8 @@ This module defines:
|
||||
- Permission groups (for easier role creation)
|
||||
- Permission checking utilities
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
from typing import List, Set
|
||||
|
||||
|
||||
class VendorPermissions(str, Enum):
|
||||
@@ -78,10 +78,10 @@ class PermissionGroups:
|
||||
"""Pre-defined permission groups for common roles."""
|
||||
|
||||
# Full access (for owners)
|
||||
OWNER: Set[str] = set(p.value for p in VendorPermissions)
|
||||
OWNER: set[str] = set(p.value for p in VendorPermissions)
|
||||
|
||||
# Manager - Can do most things except team management and critical settings
|
||||
MANAGER: Set[str] = {
|
||||
MANAGER: set[str] = {
|
||||
VendorPermissions.DASHBOARD_VIEW.value,
|
||||
VendorPermissions.PRODUCTS_VIEW.value,
|
||||
VendorPermissions.PRODUCTS_CREATE.value,
|
||||
@@ -113,7 +113,7 @@ class PermissionGroups:
|
||||
}
|
||||
|
||||
# Staff - Can view and edit products/orders but limited access
|
||||
STAFF: Set[str] = {
|
||||
STAFF: set[str] = {
|
||||
VendorPermissions.DASHBOARD_VIEW.value,
|
||||
VendorPermissions.PRODUCTS_VIEW.value,
|
||||
VendorPermissions.PRODUCTS_CREATE.value,
|
||||
@@ -127,7 +127,7 @@ class PermissionGroups:
|
||||
}
|
||||
|
||||
# Support - Can view and assist with orders/customers
|
||||
SUPPORT: Set[str] = {
|
||||
SUPPORT: set[str] = {
|
||||
VendorPermissions.DASHBOARD_VIEW.value,
|
||||
VendorPermissions.PRODUCTS_VIEW.value,
|
||||
VendorPermissions.ORDERS_VIEW.value,
|
||||
@@ -137,7 +137,7 @@ class PermissionGroups:
|
||||
}
|
||||
|
||||
# Viewer - Read-only access
|
||||
VIEWER: Set[str] = {
|
||||
VIEWER: set[str] = {
|
||||
VendorPermissions.DASHBOARD_VIEW.value,
|
||||
VendorPermissions.PRODUCTS_VIEW.value,
|
||||
VendorPermissions.STOCK_VIEW.value,
|
||||
@@ -147,7 +147,7 @@ class PermissionGroups:
|
||||
}
|
||||
|
||||
# Marketing - Focused on marketing and customer communication
|
||||
MARKETING: Set[str] = {
|
||||
MARKETING: set[str] = {
|
||||
VendorPermissions.DASHBOARD_VIEW.value,
|
||||
VendorPermissions.CUSTOMERS_VIEW.value,
|
||||
VendorPermissions.CUSTOMERS_EXPORT.value,
|
||||
@@ -162,34 +162,34 @@ class PermissionChecker:
|
||||
"""Utility class for permission checking."""
|
||||
|
||||
@staticmethod
|
||||
def has_permission(permissions: List[str], required_permission: str) -> bool:
|
||||
def has_permission(permissions: list[str], required_permission: str) -> bool:
|
||||
"""Check if a permission list contains a required permission."""
|
||||
return required_permission in permissions
|
||||
|
||||
@staticmethod
|
||||
def has_any_permission(
|
||||
permissions: List[str], required_permissions: List[str]
|
||||
permissions: list[str], required_permissions: list[str]
|
||||
) -> bool:
|
||||
"""Check if a permission list contains ANY of the required permissions."""
|
||||
return any(perm in permissions for perm in required_permissions)
|
||||
|
||||
@staticmethod
|
||||
def has_all_permissions(
|
||||
permissions: List[str], required_permissions: List[str]
|
||||
permissions: list[str], required_permissions: list[str]
|
||||
) -> bool:
|
||||
"""Check if a permission list contains ALL of the required permissions."""
|
||||
return all(perm in permissions for perm in required_permissions)
|
||||
|
||||
@staticmethod
|
||||
def get_missing_permissions(
|
||||
permissions: List[str], required_permissions: List[str]
|
||||
) -> List[str]:
|
||||
permissions: list[str], required_permissions: list[str]
|
||||
) -> list[str]:
|
||||
"""Get list of missing permissions."""
|
||||
return [perm for perm in required_permissions if perm not in permissions]
|
||||
|
||||
|
||||
# Helper function to get permissions for a role preset
|
||||
def get_preset_permissions(preset_name: str) -> Set[str]:
|
||||
def get_preset_permissions(preset_name: str) -> set[str]:
|
||||
"""
|
||||
Get permissions for a preset role.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user