Skip to content

feat: add runtime dependency preflight to PDF pipeline#86

Merged
ShadyUnderLight merged 1 commit into
mainfrom
feat/pdf-pipeline-runtime-preflight
May 11, 2026
Merged

feat: add runtime dependency preflight to PDF pipeline#86
ShadyUnderLight merged 1 commit into
mainfrom
feat/pdf-pipeline-runtime-preflight

Conversation

@ShadyUnderLight
Copy link
Copy Markdown
Owner

@ShadyUnderLight ShadyUnderLight commented May 11, 2026

问题

Closes #80 — 当前 md_to_pdf.py 在下游子进程(markdown_to_html.py / render_pdf.py)依赖缺失时,只抛 ModuleNotFoundError,错误信息不友好。

修改

scripts/md_to_pdf.py

  1. Python 包预检 — 在 main() 入口检查 markdownnh3playwright 是否可 import,缺失时输出带绝对路径的 pip install 命令。
  2. Playwright Chromium 预检 — 使用 Playwright 自己的 sync_playwright() + p.chromium.launch() 做真正的浏览器可用性检查,捕获 "Executable doesn't exist" 异常时输出 playwright install chromium。不再手写缓存路径判断(消除 stale 目录 / 版本不匹配 / headless_shell 差异 / XDG_CACHE_HOME / LOCALAPPDATA / PLAYWRIGHT_BROWSERS_PATH=0 等问题)。
  3. 执行顺序 — preflight 在文件存在性检查之后,避免遮蔽 "File not found"。
  4. 修复命令使用当前解释器 — 所有提示都用 {sys.executable} -m pip / {sys.executable} -m playwright,避免多 Python 环境装歪。

scripts/test_md_to_pdf_preflight.py(新增)

验证:

  • 输入文件不存在时,先报 "File not found"
  • 用 PYTHONPATH shim 模拟 nh3 缺失时,exit=1,stderr 包含 nh3requirements.txt

.github/workflows/ci.yml

  • quick job 增加 test_md_to_pdf_preflight.py
  • smoke job 增加 Chromium 预检测试(PLAYWRIGHT_BROWSERS_PATH 指向空目录,验证 preflight 捕获并输出 chromium

不改的

  • 不修改 markdown_to_html.py / render_pdf.py
  • 不改 README.md / SKILL.md

@ShadyUnderLight ShadyUnderLight force-pushed the feat/pdf-pipeline-runtime-preflight branch 2 times, most recently from 283f936 to 7fb2c7e Compare May 11, 2026 10:03
md_to_pdf.py now checks for markdown, nh3, and playwright at entry
rather than failing deep in a subprocess with ModuleNotFoundError.

When a dependency is missing, the script prints an actionable fix
command instead of a raw Python traceback.
@ShadyUnderLight ShadyUnderLight force-pushed the feat/pdf-pipeline-runtime-preflight branch from 7fb2c7e to 7b5d49d Compare May 11, 2026 10:07
@ShadyUnderLight ShadyUnderLight merged commit fae3cf8 into main May 11, 2026
2 checks passed
@ShadyUnderLight ShadyUnderLight deleted the feat/pdf-pipeline-runtime-preflight branch May 11, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

为 PDF pipeline 增加运行时依赖 preflight,避免缺少 nh3 时交付失败

1 participant