fix(lint): auto-fix ruff violations and tune lint rules
- Auto-fixed 4,496 lint issues (import sorting, modern syntax, etc.) - Added ignore rules for patterns intentional in this codebase: E402 (late imports), E712 (SQLAlchemy filters), B904 (raise from), SIM108/SIM105/SIM117 (readability preferences) - Added per-file ignores for tests and scripts - Excluded broken scripts/rename_terminology.py (has curly quotes) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@ def __getattr__(name: str):
|
||||
from app.modules.monitoring.definition import monitoring_module
|
||||
|
||||
return monitoring_module
|
||||
elif name == "get_monitoring_module_with_routers":
|
||||
if name == "get_monitoring_module_with_routers":
|
||||
from app.modules.monitoring.definition import get_monitoring_module_with_routers
|
||||
|
||||
return get_monitoring_module_with_routers
|
||||
|
||||
@@ -16,12 +16,12 @@ from fastapi import APIRouter, Depends
|
||||
from app.api.deps import require_module_access
|
||||
from app.modules.enums import FrontendType
|
||||
|
||||
from .admin_audit import admin_audit_router
|
||||
from .admin_code_quality import admin_code_quality_router
|
||||
from .admin_logs import admin_logs_router
|
||||
from .admin_platform_health import admin_platform_health_router
|
||||
from .admin_tasks import admin_tasks_router
|
||||
from .admin_tests import admin_tests_router
|
||||
from .admin_code_quality import admin_code_quality_router
|
||||
from .admin_audit import admin_audit_router
|
||||
from .admin_platform_health import admin_platform_health_router
|
||||
|
||||
admin_router = APIRouter(
|
||||
dependencies=[Depends(require_module_access("monitoring", FrontendType.ADMIN))],
|
||||
|
||||
@@ -17,12 +17,12 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.monitoring.services.admin_audit_service import admin_audit_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
AdminAuditLogFilters,
|
||||
AdminAuditLogListResponse,
|
||||
AdminAuditLogResponse,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_audit_router = APIRouter(prefix="/audit")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -14,14 +14,17 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.monitoring.exceptions import ScanNotFoundException, ViolationNotFoundException
|
||||
from app.modules.analytics.schemas import CodeQualityDashboardStatsResponse
|
||||
from app.modules.dev_tools.models import ArchitectureScan
|
||||
from app.modules.dev_tools.services.code_quality_service import (
|
||||
VALID_VALIDATOR_TYPES,
|
||||
code_quality_service,
|
||||
)
|
||||
from app.modules.dev_tools.models import ArchitectureScan
|
||||
from app.modules.monitoring.exceptions import (
|
||||
ScanNotFoundException,
|
||||
ViolationNotFoundException,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.analytics.schemas import CodeQualityDashboardStatsResponse
|
||||
|
||||
admin_code_quality_router = APIRouter(prefix="/code-quality")
|
||||
|
||||
|
||||
@@ -19,11 +19,10 @@ from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.core.logging import reload_log_level
|
||||
from app.exceptions import ResourceNotFoundException
|
||||
from app.modules.tenancy.exceptions import ConfirmationRequiredException
|
||||
from app.modules.monitoring.services.admin_audit_service import admin_audit_service
|
||||
from app.modules.core.services.admin_settings_service import admin_settings_service
|
||||
from app.modules.monitoring.services.admin_audit_service import admin_audit_service
|
||||
from app.modules.monitoring.services.log_service import log_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.exceptions import ConfirmationRequiredException
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
ApplicationLogFilters,
|
||||
ApplicationLogListResponse,
|
||||
@@ -36,6 +35,7 @@ from app.modules.tenancy.schemas.admin import (
|
||||
LogSettingsUpdateResponse,
|
||||
LogStatistics,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_logs_router = APIRouter(prefix="/logs")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,7 +16,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.monitoring.services.platform_health_service import platform_health_service
|
||||
from app.modules.monitoring.services.platform_health_service import (
|
||||
platform_health_service,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_platform_health_router = APIRouter(prefix="/platform")
|
||||
@@ -170,7 +172,9 @@ async def get_growth_trends(
|
||||
|
||||
Returns growth rates and projections for key metrics.
|
||||
"""
|
||||
from app.modules.billing.services.capacity_forecast_service import capacity_forecast_service
|
||||
from app.modules.billing.services.capacity_forecast_service import (
|
||||
capacity_forecast_service,
|
||||
)
|
||||
|
||||
return capacity_forecast_service.get_growth_trends(db, days=days)
|
||||
|
||||
@@ -185,7 +189,9 @@ async def get_scaling_recommendations(
|
||||
|
||||
Returns prioritized list of recommendations.
|
||||
"""
|
||||
from app.modules.billing.services.capacity_forecast_service import capacity_forecast_service
|
||||
from app.modules.billing.services.capacity_forecast_service import (
|
||||
capacity_forecast_service,
|
||||
)
|
||||
|
||||
return capacity_forecast_service.get_scaling_recommendations(db)
|
||||
|
||||
@@ -200,7 +206,9 @@ async def capture_snapshot(
|
||||
|
||||
Normally run automatically by daily background job.
|
||||
"""
|
||||
from app.modules.billing.services.capacity_forecast_service import capacity_forecast_service
|
||||
from app.modules.billing.services.capacity_forecast_service import (
|
||||
capacity_forecast_service,
|
||||
)
|
||||
|
||||
snapshot = capacity_forecast_service.capture_daily_snapshot(db)
|
||||
db.commit()
|
||||
|
||||
@@ -12,7 +12,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.monitoring.services.background_tasks_service import background_tasks_service
|
||||
from app.modules.monitoring.services.background_tasks_service import (
|
||||
background_tasks_service,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_tasks_router = APIRouter(prefix="/tasks")
|
||||
|
||||
@@ -13,9 +13,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_db, require_menu_access
|
||||
from app.modules.core.utils.page_context import get_admin_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -6,20 +6,20 @@ This module contains the canonical implementations of monitoring-related service
|
||||
"""
|
||||
|
||||
from app.modules.monitoring.services.admin_audit_service import (
|
||||
admin_audit_service,
|
||||
AdminAuditService,
|
||||
admin_audit_service,
|
||||
)
|
||||
from app.modules.monitoring.services.background_tasks_service import (
|
||||
background_tasks_service,
|
||||
BackgroundTasksService,
|
||||
background_tasks_service,
|
||||
)
|
||||
from app.modules.monitoring.services.log_service import (
|
||||
log_service,
|
||||
LogService,
|
||||
log_service,
|
||||
)
|
||||
from app.modules.monitoring.services.platform_health_service import (
|
||||
platform_health_service,
|
||||
PlatformHealthService,
|
||||
platform_health_service,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -15,9 +15,11 @@ from sqlalchemy import and_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.tenancy.exceptions import AdminOperationException
|
||||
from app.modules.tenancy.models import AdminAuditLog
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.schemas.admin import AdminAuditLogFilters, AdminAuditLogResponse
|
||||
from app.modules.tenancy.models import AdminAuditLog, User
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
AdminAuditLogFilters,
|
||||
AdminAuditLogResponse,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.contracts.audit import AuditEvent, AuditProviderProtocol
|
||||
from app.modules.contracts.audit import AuditEvent
|
||||
from app.modules.tenancy.models import AdminAuditLog
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -9,9 +9,8 @@ from datetime import UTC, datetime
|
||||
from sqlalchemy import case, desc, func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.dev_tools.models import ArchitectureScan
|
||||
from app.modules.dev_tools.models import ArchitectureScan, TestRun
|
||||
from app.modules.marketplace.models import MarketplaceImportJob
|
||||
from app.modules.dev_tools.models import TestRun
|
||||
|
||||
|
||||
class BackgroundTasksService:
|
||||
|
||||
@@ -174,7 +174,7 @@ class LogService:
|
||||
.group_by(ApplicationLog.level)
|
||||
.all()
|
||||
)
|
||||
by_level = {level: count for level, count in by_level_raw}
|
||||
by_level = dict(by_level_raw)
|
||||
|
||||
# Count by module (top 10)
|
||||
by_module_raw = (
|
||||
@@ -186,7 +186,7 @@ class LogService:
|
||||
.limit(10)
|
||||
.all()
|
||||
)
|
||||
by_module = {module: count for module, count in by_module_raw}
|
||||
by_module = dict(by_module_raw)
|
||||
|
||||
# Recent errors (last 5)
|
||||
recent_errors = (
|
||||
@@ -286,10 +286,7 @@ class LogService:
|
||||
try:
|
||||
# Determine log directory
|
||||
log_file_path = settings.log_file
|
||||
if log_file_path:
|
||||
log_dir = Path(log_file_path).parent
|
||||
else:
|
||||
log_dir = Path("logs")
|
||||
log_dir = Path(log_file_path).parent if log_file_path else Path("logs")
|
||||
|
||||
if not log_dir.exists():
|
||||
return []
|
||||
|
||||
@@ -16,10 +16,10 @@ import psutil
|
||||
from sqlalchemy import func, text
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.cms.services.media_service import media_service
|
||||
from app.modules.inventory.models import Inventory
|
||||
from app.modules.orders.models import Order
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.tenancy.models import Store
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -172,7 +172,7 @@ class PlatformHealthService:
|
||||
|
||||
Returns aggregated limits and current usage for capacity planning.
|
||||
"""
|
||||
from app.modules.billing.models import MerchantSubscription, TierFeatureLimit
|
||||
from app.modules.billing.models import MerchantSubscription
|
||||
from app.modules.tenancy.models import StoreUser
|
||||
|
||||
# Get all active subscriptions with tier + feature limits
|
||||
@@ -247,7 +247,7 @@ class PlatformHealthService:
|
||||
"utilization_percent": None,
|
||||
"has_unlimited": True,
|
||||
}
|
||||
elif limit > 0:
|
||||
if limit > 0:
|
||||
return {
|
||||
"actual": actual,
|
||||
"theoretical_limit": limit,
|
||||
@@ -256,14 +256,13 @@ class PlatformHealthService:
|
||||
"headroom": limit - actual,
|
||||
"has_unlimited": False,
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"actual": actual,
|
||||
"theoretical_limit": 0,
|
||||
"unlimited_count": 0,
|
||||
"utilization_percent": 0,
|
||||
"has_unlimited": False,
|
||||
}
|
||||
return {
|
||||
"actual": actual,
|
||||
"theoretical_limit": 0,
|
||||
"unlimited_count": 0,
|
||||
"utilization_percent": 0,
|
||||
"has_unlimited": False,
|
||||
}
|
||||
|
||||
return {
|
||||
"total_subscriptions": len(subscriptions),
|
||||
@@ -527,10 +526,9 @@ class PlatformHealthService:
|
||||
|
||||
if "critical" in statuses:
|
||||
return "critical"
|
||||
elif "warning" in statuses:
|
||||
if "warning" in statuses:
|
||||
return "degraded"
|
||||
else:
|
||||
return "healthy"
|
||||
return "healthy"
|
||||
|
||||
|
||||
# Create service instance
|
||||
|
||||
@@ -27,7 +27,9 @@ def capture_capacity_snapshot(self):
|
||||
Returns:
|
||||
dict: Snapshot summary with store and product counts.
|
||||
"""
|
||||
from app.modules.billing.services.capacity_forecast_service import capacity_forecast_service
|
||||
from app.modules.billing.services.capacity_forecast_service import (
|
||||
capacity_forecast_service,
|
||||
)
|
||||
|
||||
with self.get_db() as db:
|
||||
snapshot = capacity_forecast_service.capture_daily_snapshot(db)
|
||||
|
||||
Reference in New Issue
Block a user