交付与验收#

4.7 阶段计划#

阶段

内容

验收

预估

P0

包骨架、theme.toml、layout.html、doc/ 最小站点

构建通过;页面无双重导航

0.5 天

P1

全书侧栏(book_nav_scope/book_nav_depth)

三层目录展开正确;dirhtml 下高亮不串页

0.5 天

P2

页眉按钮(5 个基础 + 全屏)

URL 单测;无仓库信息时区段消失

1 天

P3

边注 / margin

行内、块级、嵌套三类用例;开关关闭后与原生脚注一致

1.5 天

P4

单列宽度、页脚组件、Notebook 样式

4 类页面快照稳定

1 天

4.8 构建与打包#

pyproject.toml 的关键段(纯 Python 主题,禁用 CMake):

[build-system]
requires = ["scikit-build-core>=0.11", "setuptools-scm>=8"]
build-backend = "scikit_build_core.build"

[project]
name = "mystx"
dynamic = ["version"]
requires-python = ">=3.11"
dependencies = ["sphinx>=8.2,<10", "pydata-sphinx-theme>=0.24,<0.25"]

[project.entry-points."sphinx.html_themes"]
mystx = "mystx"

[tool.scikit-build]
minimum-version = "0.11"
wheel.cmake = false
sdist.cmake = false
sdist.include = ["src/mystx/theme/**", "README.md", "LICENSE"]

[tool.scikit-build.wheel]
packages = ["src/mystx"]

[tool.setuptools_scm]
version_file = "src/mystx/_version.py"
write_to = "src/mystx/_version.py"

要点

说明

版本号

setuptools-scm 由 git tag 推导;首个 tag 为 v0.0.1 → 发行版 0.0.1;version_file 供 __init__ 读取;无 git 元数据时回退 0.0.0.dev0

CI 取版本

checkout 需 fetch-depth: 0;浅克隆看不到 tag,版本会静默回退为 dev0

无 CMake

wheel.cmake=false 与 sdist.cmake=false 两处显式关闭,构建不要求 cmake/ninja

主题资源

wheel.packages 递归收集 src/mystx,theme/ 下的 .html / .toml / .css 作为包数据入 wheel,无需 MANIFEST.in

sdist

sdist.include 显式列出 theme/**,防止源码包丢模板

不入包

doc/、tests/ 不进入 wheel

4.9 测试策略#

  1. 三个 fixture 站点:basic(无仓库)、book(多层目录)、notebook(myst-nb 输出)。

  2. 构建断言:builder-inited 后无 warning;关键 HTML 片段(nav.bd-sidenav、按钮组、边注 label)。

  3. 纯函数单测:按钮 URL、选项归一化。

  4. 可选:Playwright + axe 冒烟(进 CI 前先跑本地)。

验收标准#

  1. doc/ 在 fail_on_warning 下构建通过,新增 warning = 0。

  2. 依赖树只有 sphinx + pydata-sphinx-theme 两个直接依赖。

  3. 自有 Python 代码 < 900 行;模板覆盖 < 60 行。

  4. 6 个 book_* 选项均有默认值、类型转换与文档示例。

  5. 关闭 book_use_sidenotes 时,输出与未安装本主题的 PST 站点一致(除品牌样式)。

  6. 无 Node 构建步骤。

  7. python -m build 产出 py3-none-any wheel;安装后 theme/mystx/theme.toml 与全部静态资源就位。

  8. sdist 解包后可离线构建;版本号与 git tag 一致(首个 tag v0.0.1 → 0.0.1),无 tag 时为 0.0.0.dev0。