Archived
为什么:podcast_api.py(560 行) 与 qr_login.py(397 行) 既不属于任何包、也不是 入口脚本,却同时被 services 层与 web 层引用——`services/downloads.py` 直接 `from qr_login import ...`、`services/podcast.py` 直接 `import podcast_api`, 业务层反向依赖顶层游离模块,是本次架构体检里唯一的无争议分层倒置。 两者本就依赖 music_api(前者取 url_v1/APIConstants/APIException,后者取 QRLoginManager),与 music_api 下已有的 qr.py / compat.py 是同一层的同类物。 迁移(git 保留重命名历史): - podcast_api.py -> music_api/podcast.py - qr_login.py -> music_api/qr_client.py **命名避让**:不叫 music_api/qr_login.py——music_api/__init__ 已经从 .compat 导出了一个**同名函数** qr_login,同名子模块会与之互相遮蔽。改叫 qr_client (其核心导出即 QRLoginClient),并在验证里专门确认 music_api.qr_login 仍是 可调用函数、music_api.podcast 是模块,两者不冲突。 内部导入顺带改为精确子模块,不再绕道包门面: - podcast.py:from music_api import APIConstants/APIException/url_v1 → from .compat import url_v1 / from .constants import ... / from .errors import ... - qr_client.py:删掉那层 try/except ImportError 包装(它给的是「请确保 music_api.py 文件存在」这类顶层脚本时代的提示,作为包内模块已无意义), 改 from .cookies/.errors/.qr 相对导入 - CLI 用法文本 python qr_login.py → python -m music_api.qr_client (相对导入后直接跑脚本会失败,必须走 -m;全仓确认无脚本/文档引用旧入口) - 路径安全性已核对:qr_client 用的是 CWD 相对的 cookie.txt,不是 __file__ 相对, 迁移不改其解析结果 引用点全部更新(AST 扫描确认覆盖全集,替换后残留 0): - podcast:services/podcast.py(1 + 5 处调用) · web/routers/podcast.py(1 + 6) · web/routers/download.py(2 处函数内 + 3),导入名统一为 `podcast` - qr_login:services/downloads.py · web/routers/admin.py · web/routers/user.py(×2) - services/__init__.py 依赖自检列表去掉这两个名字(已并入 music_api) - pyproject include 去掉两个顶层文件名(music_api 目录已覆盖) 验证: - 11 + 3 个符号在新位置全部 hasattr 通过;podcast_api / qr_login 已 ModuleNotFoundError;6 个调用方模块均可 import;services 依赖自检仍生效 - 门禁:ruff 0 · pyright 0 errors/0 warnings · pytest 184 passed - 真实 uvicorn 冒烟 10/10,含 /podcast/parse 与 /podcast/hot 返回 401 (模块导入失败会是 500,路由缺失会是 404,401 证明两者都正常) - 生产 data/ 指纹 before == after
115 lines
4.4 KiB
TOML
115 lines
4.4 KiB
TOML
# -*- coding: utf-8 -*-
|
||
[project]
|
||
name = "yunmusic-assistant"
|
||
version = "3.0.0"
|
||
description = "云村小助手 · 网易云音乐解析/下载服务(FastAPI + asyncio + aiohttp)"
|
||
requires-python = ">=3.12"
|
||
dependencies = [
|
||
"fastapi>=0.115,<1.0",
|
||
"uvicorn[standard]>=0.30,<1.0",
|
||
"aiohttp>=3.10,<4.0",
|
||
"aiosqlite>=0.20,<1.0",
|
||
"aiofiles>=24.1",
|
||
"itsdangerous>=2.2,<3.0",
|
||
"cryptography>=50.0,<51.0",
|
||
"qrcode>=7.0,<8.3",
|
||
"python-multipart>=0.0.9",
|
||
"jinja2>=3.1,<4.0",
|
||
"filetype>=1.2.0",
|
||
"aria2p>=0.12.1",
|
||
"mutagen>=1.48.1",
|
||
]
|
||
|
||
[dependency-groups]
|
||
dev = [
|
||
"pytest>=8.0",
|
||
"pytest-asyncio>=0.24",
|
||
"ruff>=0.6",
|
||
"pyright>=1.1.390",
|
||
"httpx>=0.27",
|
||
"httpx2>=2.13.1",
|
||
]
|
||
|
||
# 应用工程(非库):不把自身装进环境,避免 uv 扫描顶层模块
|
||
[tool.uv]
|
||
package = false
|
||
|
||
# ============ Ruff:静态检查 + 导入排序 + 格式化 ============
|
||
[tool.ruff]
|
||
target-version = "py312"
|
||
line-length = 120
|
||
extend-exclude = [".venv", ".zcode", "templates", "static", "data"]
|
||
|
||
[tool.ruff.lint]
|
||
# E/F 基础错误、I 导入排序、B bugbear、UP 升级、C4 推导式、ASYNC 异步陷阱、S 安全、RUF
|
||
select = ["E", "F", "W", "I", "B", "UP", "C4", "ASYNC", "S", "RUF"]
|
||
ignore = [
|
||
"E501", # 行宽交给 formatter,不强制
|
||
"S101", # 生产代码外的 assert(测试/断言脚本)
|
||
"S104", # 绑定 0.0.0.0(服务端有意为之)
|
||
"S110", # try/except/pass(本项目「失败静默降级」策略)
|
||
"S112", # try/except/continue
|
||
"S324", # hashlib.md5 用于非安全场景(上游签名口径)
|
||
"S603", "S607", # subprocess(打包/运维脚本)
|
||
"UP009", # 保留 `# -*- coding: utf-8 -*-` 文件头(全项目既有约定)
|
||
"RUF001", "RUF002", "RUF003", # 全角字符(中文注释/文案,误报)
|
||
# ---- 以下为「有意保留」,已被逐条论证为协议/设计约束,非待修缺陷 ----
|
||
"RUF012", # 常量类可变默认值:APIConstants/PodcastConstants 是常量表,非实例状态
|
||
"S305", # AES-ECB:网易云 weapi 协议**要求**的加密模式,非可自由选择
|
||
"S311", # randrange:生成上游 requestId(协议随机数),非安全用途
|
||
"ASYNC250", # input():music_api.qr_client 交互式 CLI 的人类输入,异步化无意义
|
||
"S310", # urllib:仅用于音频 Range 代理的 URL 校验路径
|
||
]
|
||
|
||
[tool.ruff.lint.per-file-ignores]
|
||
"tests/**" = ["S", "ASYNC"]
|
||
".zcode/**" = ["S", "ASYNC", "F"]
|
||
# ASYNC109:timeout 参数是有意 API——直接转发给 aiohttp 的 ClientTimeout,
|
||
# 不是「用 sleep 当超时」的反模式。
|
||
"core/http_client.py" = ["ASYNC109"]
|
||
"core/aiohttp_compat.py" = ["ASYNC109"]
|
||
|
||
[tool.ruff.lint.isort]
|
||
known-first-party = ["core", "web", "services", "music_api", "auth_system", "music_downloader"]
|
||
|
||
[tool.ruff.format]
|
||
quote-style = "preserve"
|
||
|
||
# ============ Pyright:类型检查 ============
|
||
[tool.pyright]
|
||
# 全量纳入(Flask 巨石删除后不再有例外清单)
|
||
# 顶层模块与 tests 此前不在名单里——「pyright 0 错误」只覆盖了 core/web/services,
|
||
# 而 requests→sync_http 迁移的遗留恰好全部躲在漏检的顶层模块中,故补齐。
|
||
include = [
|
||
"core",
|
||
"web",
|
||
"services",
|
||
"tests",
|
||
"music_api",
|
||
"auth_system",
|
||
"music_downloader",
|
||
"_mkpkg.py",
|
||
]
|
||
exclude = [".venv", ".zcode", "data", "downloads", "templates", "static"]
|
||
venvPath = "."
|
||
venv = ".venv"
|
||
pythonVersion = "3.12"
|
||
typeCheckingMode = "standard"
|
||
reportMissingImports = true
|
||
# standard 比 basic 多出「变量可能未绑定 / 实参类型不符 / 无意义重定义 / 未使用符号」
|
||
# 等**可执行缺陷**(basic 全部漏报,实测 standard 多报 7 处真实缺陷),
|
||
# 故作为门禁级别;strict 的 reportUnknown* 需要给全部第三方库补存根,暂不启用。
|
||
# 以下三项在 standard 下已由类型系统覆盖,降为 warning 以避免第三方存根不全的噪声
|
||
reportOptionalMemberAccess = "warning"
|
||
reportAttributeAccessIssue = "warning"
|
||
|
||
# ============ Pytest ============
|
||
[tool.pytest.ini_options]
|
||
asyncio_mode = "auto"
|
||
testpaths = ["tests"]
|
||
addopts = "-q"
|
||
# 本工程不装进环境(package = false),且 tests/ 无 __init__.py,
|
||
# 故必须显式把项目根加入 import 路径——否则裸跑 `pytest` 时
|
||
# `import core` 必然 ModuleNotFoundError(只有 `python -m pytest` 才碰巧能用)。
|
||
pythonpath = ["."]
|