style: apply safe ruff auto-fixes and exempt startup late imports

Run `ruff check app tests scripts --fix` with the configured rule set
(E4/E7/E9/F/I): import sorting (I001), f-strings without placeholders
(F541), lambda/variable/unused-import cleanups that ruff marks safe.
Nine files whose only ruff debt sits next to pre-existing pylint
import-resolution errors (lazy exports, sys.path script imports) or
whose "unused" imports are reached through attribute access by tests are
left untouched so the changed-file pylint gate and the benchmark tests
stay green; their diagnostics remain in the baseline.

app/startup/lifecycle/__init__.py and app/main.py import business
modules after cache composition, import-path and stdio setup on purpose
(the source comments document the contract), so declare E402
per-file-ignores for them instead of adding per-line noqa.

Ruff ratchet watermark drops from 498 to 100; sync the baseline fixture
and the optimization checklist figure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
freeman
2026-10-09 13:29:09 +08:00
parent 1c1db41222
commit f3ad81b39e
267 changed files with 648 additions and 1555 deletions

View File

@@ -6,7 +6,6 @@ import ast
from dataclasses import dataclass, field
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[2]
TASK_METHODS = frozenset(
{"create", "create_sync", "register", "submit_threadsafe"}

View File

@@ -4,8 +4,8 @@ Benchmark SiteSpider indexer parsing with real MoviePilot-Build site configs.
"""
import argparse
import copy
import contextlib
import copy
import io
import statistics
import sys

View File

@@ -9,10 +9,10 @@ from types import SimpleNamespace
PROJECT_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(PROJECT_ROOT))
from app.adapters.network.http import RequestUtils
from app.adapters.system import rust as rust_accel
from app.application import rss as rss_module
from app.application.rss import RssHelper
from app.adapters.system import rust as rust_accel
from app.adapters.network.http import RequestUtils
class FakeRequestUtils:

View File

@@ -9,7 +9,6 @@ from pathlib import Path
from typing import Optional
from urllib.parse import urlparse
OFFICIAL_PLUGIN_MARKET = "https://github.com/jxxghp/MoviePilot-Plugins"
PLUGIN_MARKET_WIKI_START = "<!-- plugin-market-repos:start -->"
PLUGIN_MARKET_WIKI_END = "<!-- plugin-market-repos:end -->"

View File

@@ -26,7 +26,6 @@ from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, Optional
ROOT = Path(__file__).resolve().parents[1]
LEGACY_CONFIG_DIR = ROOT / "config"
SITE_RESOURCE_DIR = ROOT / "app" / "application" / "site"
@@ -2536,13 +2535,13 @@ def _apply_local_system_config_inner(config_payload: dict[str, Any]) -> None:
)
from app.application.configuration import SystemConfigService
from app.application.directory import normalize_directory_system_config_value
from app.schemas.category import ClassificationPolicyState
from app.startup.initializers.database import prepare_database
from app.db.adapters.transaction import TransactionalWriteRunner
from app.db.oper.systemconfig import SystemConfigOper
from app.schemas.types import SystemConfigKey
from app.db.session import SessionFactory, async_session_scope
from app.db.uow import configure_transaction_runners
from app.db.adapters.transaction import TransactionalWriteRunner
from app.schemas.category import ClassificationPolicyState
from app.schemas.types import SystemConfigKey
from app.startup.initializers.database import prepare_database
except ModuleNotFoundError as exc:
raise RuntimeError(
"当前环境尚未安装 MoviePilot 运行依赖,请先执行 moviepilot install deps 或 moviepilot setup"
@@ -2725,8 +2724,8 @@ def _ensure_superuser_account_inner() -> None:
def _prepare_superuser_password_for_bootstrap() -> Optional[str]:
from app.runtime.config import settings
from app.db.oper.user import UserOper
from app.runtime.config import settings
username = str(settings.SUPERUSER or "").strip()
username_error = _validate_superuser_name(username)
@@ -3960,9 +3959,9 @@ def run_agent_request(
sys.path.insert(0, str(ROOT))
try:
from app.startup.initializers.database import prepare_database
from app.agent.orchestrator import MoviePilotAgent
from app.runtime.config import settings
from app.startup.initializers.database import prepare_database
except ModuleNotFoundError as exc:
raise RuntimeError(
"当前环境尚未安装 MoviePilot 运行依赖,请先执行 moviepilot install deps 或 moviepilot setup"

View File

@@ -7,7 +7,6 @@ import re
import tomllib
from pathlib import Path
DIRECT_REFERENCE = re.compile(
r"^(?P<indent>\s*)(?P<name>[A-Za-z0-9_.-]+)\s+@\s+"
r"(?P<url>\S+)(?P<suffix>.*)$"

View File

@@ -10,7 +10,6 @@ import random
import re
import statistics
import subprocess
import sys
import tempfile
import time
from datetime import datetime, timezone

View File

@@ -6,7 +6,6 @@ import importlib
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[2]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))

View File

@@ -26,7 +26,6 @@ import requests
import websocket
from bs4 import BeautifulSoup, Comment, NavigableString, Tag
COLLECTOR_VERSION = "1.0.1"
FORMAT_VERSION = 1
MAX_RESPONSE_BYTES = 5 * 1024 * 1024

View File

@@ -12,7 +12,6 @@ from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Optional
PROJECT_ROOT = Path(__file__).resolve().parents[2]
DEFAULT_OUTPUT = (
PROJECT_ROOT