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:
@@ -33,6 +33,8 @@ from pathlib import Path
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
import contextlib
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -49,10 +51,8 @@ for _mod in [
|
||||
"app.modules.marketplace.models",
|
||||
"app.modules.cms.models",
|
||||
]:
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.modules.cms.models import ContentPage
|
||||
@@ -505,7 +505,7 @@ def create_default_pages(db: Session) -> None:
|
||||
# Check if page already exists (platform default with this slug)
|
||||
existing = db.execute(
|
||||
select(ContentPage).where(
|
||||
ContentPage.store_id == None, ContentPage.slug == page_data["slug"]
|
||||
ContentPage.store_id is None, ContentPage.slug == page_data["slug"]
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Usage:
|
||||
python scripts/create_platform_pages.py
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -36,10 +37,8 @@ for _mod in [
|
||||
"app.modules.marketplace.models",
|
||||
"app.modules.cms.models",
|
||||
]:
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ Run this script to create default logging configuration settings.
|
||||
"""
|
||||
|
||||
# Register all models with SQLAlchemy so string-based relationships resolve
|
||||
import contextlib
|
||||
|
||||
for _mod in [
|
||||
"app.modules.billing.models",
|
||||
"app.modules.inventory.models",
|
||||
@@ -18,10 +20,8 @@ for _mod in [
|
||||
"app.modules.marketplace.models",
|
||||
"app.modules.cms.models",
|
||||
]:
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.modules.tenancy.models import AdminSetting
|
||||
|
||||
@@ -24,6 +24,8 @@ from pathlib import Path
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
import contextlib
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -34,13 +36,12 @@ from app.core.config import (
|
||||
)
|
||||
from app.core.database import SessionLocal
|
||||
from app.core.environment import is_production
|
||||
from app.modules.billing.models.subscription import SubscriptionTier
|
||||
from app.modules.tenancy.models import AdminSetting, Platform, User
|
||||
from app.modules.tenancy.services.permission_discovery_service import (
|
||||
permission_discovery_service,
|
||||
)
|
||||
from middleware.auth import AuthManager
|
||||
from app.modules.tenancy.models import AdminSetting, Platform
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.billing.models.subscription import SubscriptionTier
|
||||
|
||||
# Register all models with SQLAlchemy so string-based relationships resolve
|
||||
for _mod in [
|
||||
@@ -55,10 +56,8 @@ for _mod in [
|
||||
"app.modules.marketplace.models",
|
||||
"app.modules.cms.models",
|
||||
]:
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# =============================================================================
|
||||
# HELPER FUNCTIONS
|
||||
@@ -510,7 +509,7 @@ def initialize_production(db: Session, auth_manager: AuthManager):
|
||||
|
||||
# Step 2: Create admin user
|
||||
print_step(2, "Creating platform admin...")
|
||||
admin = create_admin_user(db, auth_manager)
|
||||
create_admin_user(db, auth_manager)
|
||||
|
||||
# Step 3: Create default platforms
|
||||
print_step(3, "Creating default platforms...")
|
||||
@@ -518,7 +517,7 @@ def initialize_production(db: Session, auth_manager: AuthManager):
|
||||
|
||||
# Step 4: Set up default role templates
|
||||
print_step(4, "Setting up role templates...")
|
||||
role_templates = create_default_role_templates(db)
|
||||
create_default_role_templates(db)
|
||||
|
||||
# Step 5: Create admin settings
|
||||
print_step(5, "Creating admin settings...")
|
||||
|
||||
@@ -18,7 +18,6 @@ Usage:
|
||||
This script is idempotent - safe to run multiple times.
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -107,9 +106,8 @@ def check_env_file() -> tuple[bool, dict]:
|
||||
print_info("Copy .env.example to .env and configure it:")
|
||||
print_info(" cp .env.example .env")
|
||||
return False, {}
|
||||
else:
|
||||
print_warning("Neither .env nor .env.example found")
|
||||
return False, {}
|
||||
print_warning("Neither .env nor .env.example found")
|
||||
return False, {}
|
||||
|
||||
print_success(".env file found")
|
||||
|
||||
@@ -451,11 +449,10 @@ def run_migrations() -> bool:
|
||||
if result.returncode == 0:
|
||||
print_success("Migrations completed successfully")
|
||||
return True
|
||||
else:
|
||||
print_error("Migration failed")
|
||||
if result.stderr:
|
||||
print_info(result.stderr[:500])
|
||||
return False
|
||||
print_error("Migration failed")
|
||||
if result.stderr:
|
||||
print_info(result.stderr[:500])
|
||||
return False
|
||||
except Exception as e:
|
||||
print_error(f"Failed to run migrations: {e}")
|
||||
return False
|
||||
@@ -474,11 +471,10 @@ def run_init_script(script_name: str, description: str) -> bool:
|
||||
if result.returncode == 0:
|
||||
print_success(description)
|
||||
return True
|
||||
else:
|
||||
print_error(f"Failed: {description}")
|
||||
if result.stderr:
|
||||
print_info(result.stderr[:300])
|
||||
return False
|
||||
print_error(f"Failed: {description}")
|
||||
if result.stderr:
|
||||
print_info(result.stderr[:300])
|
||||
return False
|
||||
except Exception as e:
|
||||
print_error(f"Error running {script_name}: {e}")
|
||||
return False
|
||||
@@ -578,7 +574,7 @@ def main():
|
||||
|
||||
print(f"\n {Colors.BOLD}Admin Login:{Colors.ENDC}")
|
||||
admin_email = env_vars.get("ADMIN_EMAIL", "admin@wizamart.com")
|
||||
print(f" URL: /admin/login")
|
||||
print(" URL: /admin/login")
|
||||
print(f" Email: {admin_email}")
|
||||
print(f" Password: {'(configured in .env)' if env_vars.get('ADMIN_PASSWORD') else 'admin123'}")
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ sys.path.insert(0, str(project_root))
|
||||
# =============================================================================
|
||||
# MODE DETECTION (from environment variable set by Makefile)
|
||||
# =============================================================================
|
||||
import contextlib
|
||||
import os
|
||||
|
||||
from sqlalchemy import delete, select
|
||||
@@ -50,25 +51,33 @@ from sqlalchemy.orm import Session
|
||||
from app.core.config import settings
|
||||
from app.core.database import SessionLocal
|
||||
from app.core.environment import get_environment, is_production
|
||||
from middleware.auth import AuthManager
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.cms.models import ContentPage, StoreTheme
|
||||
from app.modules.customers.models.customer import Customer, CustomerAddress
|
||||
from app.modules.marketplace.models import (
|
||||
MarketplaceImportJob,
|
||||
MarketplaceProduct,
|
||||
MarketplaceProductTranslation,
|
||||
)
|
||||
from app.modules.orders.models import Order, OrderItem
|
||||
|
||||
# =============================================================================
|
||||
# MODEL IMPORTS
|
||||
# =============================================================================
|
||||
# ALL models must be imported before any ORM query so SQLAlchemy can resolve
|
||||
# cross-module string relationships (e.g. Store→StoreEmailTemplate,
|
||||
# Platform→SubscriptionTier, Product→Inventory).
|
||||
|
||||
# Core modules
|
||||
from app.modules.tenancy.models import Merchant, PlatformAlert, User, Role, Store, StoreUser, StoreDomain
|
||||
from app.modules.cms.models import ContentPage, StoreTheme
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.customers.models.customer import Customer, CustomerAddress
|
||||
from app.modules.orders.models import Order, OrderItem
|
||||
from app.modules.marketplace.models import (
|
||||
MarketplaceImportJob,
|
||||
MarketplaceProduct,
|
||||
MarketplaceProductTranslation,
|
||||
from app.modules.tenancy.models import (
|
||||
Merchant,
|
||||
PlatformAlert,
|
||||
Role,
|
||||
Store,
|
||||
StoreDomain,
|
||||
StoreUser,
|
||||
User,
|
||||
)
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
# Optional modules — import to register models with SQLAlchemy
|
||||
for _mod in [
|
||||
@@ -78,10 +87,8 @@ for _mod in [
|
||||
"app.modules.messaging.models",
|
||||
"app.modules.loyalty.models",
|
||||
]:
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
SEED_MODE = os.getenv("SEED_MODE", "normal") # normal, minimal, reset
|
||||
FORCE_RESET = os.getenv("FORCE_RESET", "false").lower() in ("true", "1", "yes")
|
||||
@@ -562,7 +569,7 @@ def reset_all_data(db: Session):
|
||||
for table in tables_to_clear:
|
||||
if table == ContentPage:
|
||||
# Only delete store content pages, keep platform defaults
|
||||
db.execute(delete(ContentPage).where(ContentPage.store_id != None))
|
||||
db.execute(delete(ContentPage).where(ContentPage.store_id is not None))
|
||||
else:
|
||||
db.execute(delete(table))
|
||||
|
||||
@@ -1104,8 +1111,8 @@ def print_summary(db: Session):
|
||||
team_member_count = db.query(StoreUser).filter(StoreUser.user_type == "member").count()
|
||||
customer_count = db.query(Customer).count()
|
||||
product_count = db.query(Product).count()
|
||||
platform_pages = db.query(ContentPage).filter(ContentPage.store_id == None).count()
|
||||
store_pages = db.query(ContentPage).filter(ContentPage.store_id != None).count()
|
||||
platform_pages = db.query(ContentPage).filter(ContentPage.store_id is None).count()
|
||||
store_pages = db.query(ContentPage).filter(ContentPage.store_id is not None).count()
|
||||
|
||||
print("\n📊 Database Status:")
|
||||
print(f" Merchants: {merchant_count}")
|
||||
|
||||
@@ -5,6 +5,7 @@ Seed default email templates.
|
||||
Run: python scripts/seed_email_templates.py
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -25,15 +26,12 @@ for _mod in [
|
||||
"app.modules.marketplace.models",
|
||||
"app.modules.cms.models",
|
||||
]:
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.modules.messaging.models import EmailCategory, EmailTemplate
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# EMAIL TEMPLATES
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user