This repository has been archived on 2026-10-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
NeteaseUrl/pyproject.toml
T
snowy-yang 6288a98ecc refactor: 拆分 4 个巨石模块为包,清理过时注释并删除作废文档
为什么:单文件 1100~1900 行的巨石模块让「改一处要通读全文」;同时注释里残留
大量已删台账的编号,以及「Flask/FastAPI 双栈迁移期」这类已失实的架构描述,
会误导后来者按不复存在的架构去改代码。

拆分(对外导入路径不变,行为零变更):
- music_downloader.py  -> music_downloader/(models/downloader/cover/_http/_log/_concurrency)
- auth_system.py       -> auth_system/(db/security/users/credits/ledger/mail/cards/backup...)
- music_api.py         -> music_api/(api/client/crypto/qr/cookies/compat/constants/errors)
- services/runtime.py  -> services/(api_service/_shared/_taskcore/downloads/batch/podcast/
  streaming/tasks);services/runtime.py 保留为兼容门面

兼容性做法:各包用 __init__.py 以 __all__ 原样再导出全部符号,既有调用点
(auth_system.xxx / services.xxx / from music_api import Y)零改动;路径常量改为经包属性
动态读取(auth_system.DB_PATH),否则测试的 monkeypatch 会静默失效并写到生产库。

修复 9 处代码损伤(上一轮注释清理把 `()` 当「空括号残留」删掉所致;用「与拆分前逐字
等价」校验逐一定位,静态检查只会报出其中 4 处):
- core/config.py  ).strip() or '*'
- core/state.py   threading.Lock() x2
- qr_login.py     datetime.now() / .strip()
- music_downloader/downloader.py  .lower()
- services/podcast.py  set() / time.time() x2

清理与删除:
- 删除 部署文档.md / 功能介绍.md / README_私有包警告.txt
- 清理指向已删台账与文档的过时编号注释;把「迁移期 / 两栈 / 双框架 / 已迁移」等
  失实描述改写为现状描述(保留 `<-> Flask /path` 映射表等仍有价值的契约来源说明)
- _mkpkg.py:公开包剔除清单去掉已不存在的文档名;私有包警告改为自包含
- pyproject.toml:补 pythonpath = ["."],使裸跑 pytest 不再 import core 失败

验证:ruff 全通过;pyright 0 errors / 0 warnings(102 文件);pytest 144 passed;
真实 uvicorn 冒烟 6 条路由符合预期且生产 data/ 指纹未变;忽略注释的逐字等价性校验通过。
2026-09-26 12:37:48 +08:00

110 lines
3.9 KiB
TOML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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",
]
[dependency-groups]
dev = [
"pytest>=8.0",
"pytest-asyncio>=0.24",
"ruff>=0.6",
"pyright>=1.1.390",
"httpx>=0.27",
]
# 应用工程(非库):不把自身装进环境,避免 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():qr_login 交互式 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",
"podcast_api.py",
"qr_login.py",
"_mkpkg.py",
]
exclude = [".venv", ".zcode", "data", "downloads", "templates", "static"]
venvPath = "."
venv = ".venv"
pythonVersion = "3.12"
typeCheckingMode = "basic"
reportMissingImports = true
reportOptionalMemberAccess = "warning"
reportAttributeAccessIssue = "warning"
reportGeneralTypeIssues = "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 = ["."]