Allow pre-rendered HTML

未关闭
#930 15 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@MaximilianSoerenPollak 已经在做这个了。

开始于 2026年11月23日。

  • #1133 来自 @MaximilianSoerenPollak —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

Start with _resolve_data_mounts and the builder-inited and build-finished handlers in src/extensions/score_mounts/, then read bzl/bundle_rules.bzl and bzl/mount_rules.bzl to see how bundle data reaches the manifest. The open questions on destination overlap and live-preview rebuilds need maintainer input before coding. Done means index.html from a root and a mounted tree lands at the expected paths in the html_extra scenario under src/tests/docs_bzl/scenarios/, and needs_json builds without the tree.

由索引模型根据 Issue 内容生成。

描述

Problem

Since 8.3.0, files in docs(data = ...) belong to the root :docs_bundle and travel with it into every site that mounts that bundle.
A pre-rendered HTML tree listed there, such as a Doxygen API reference staged with filegroup, breaks every site that mounts the bundle.

# component/BUILD
filegroup
    name = "doxygen_staged",
    srcs = [":doxygen"],  # rules_doxygen, declares `html` as a directory artifact
)

docs(
    source_dir = "docs",
    data = [":doxygen_staged"],  # conf.py: html_extra_path = ["../../bazel-bin/component/docs/_doxygen"]
)

# product/BUILD
docs(
    source_dir = "docs",
    bundles = [{"bundle": "//component:docs_bundle", "mount_at": "component"}],
)

bazel run //component:docs succeeds, while bazel run //product:docs fails in config-inited:

ValueError: score_mounts: resolved data file does not exist: <execroot>/bazel-out/k8-opt/bin/component/docs/_doxygen/api (mount_at=component)

The directory exists, but _resolve_data_mounts requires every data entry of a mounted bundle to pass Path.is_file().
Accepting directories there is not enough, because bundle data is mounted as a Sphinx source directory and HTML in it never reaches the output.
The same setup builds with 7.1.0.

No existing argument fits:

  • docs_bundle(srcs = ...) takes Sphinx sources with known file names, not a directory to copy.
  • html_extra_path copies to the output root of one site, so every mounting site has to restage each child's tree under the child's mount_at.
  • A py_library(data = [...]) passed through docs(deps = ...) builds the tree without it entering the bundle, which is the workaround in use, but it misuses Python deps and keeps the per-site staging.

Proposal

Add html_extra to docs() and docs_bundle(), a dict from a label that provides one directory to a destination relative to the bundle's pages.

filegroup(
    name = "doxygen_html",
    srcs = [":doxygen"],
    output_group = "html",
)

docs(
    source_dir = "docs",
    html_extra = {":doxygen_html": "api"},
)
  • Every site that builds or mounts the bundle copies the directory's contents to <outdir>/<mount_at>/<destination>/, so relative links such as api/index.html resolve everywhere.
  • The destination is a non-empty relative path without .. and without a leading /.
  • Only HTML-format builders receive the trees, and the Needs actions, docs_check and docs_link_check neither build nor copy them.
  • Mounting sites need no staging target and no html_extra_path.
Target Component tree lands at
bazel run //component:docs component/_build/api/
bazel run //product:docs product/_build/component/api/

Implementation sketch

  • bzl/bundle_rules.bzl
    • Add html_extra = attr.label_keyed_string_dict(allow_files = True) to _docs_bundle, and validate one is_directory file per label and the destination.
    • Store [struct(tree, dest)] on the bundle's entry, also for a bundle without sources or data, and carry it unchanged through _rebase_bundle_entry.
    • Expose all trees as DocsBundleInfo.html_extra_files, kept out of DefaultInfo and data so needs_json never waits for Doxygen.
  • bzl/mount_rules.bzl: emit "html_extra": [{"path": ..., "dest": ...}] per manifest entry.
  • docs.bzl
    • Add the html_extra parameter to docs() and docs_bundle().
    • Add an internal target that exposes html_extra_files, to the data of the docs and live_preview binaries only.
  • src/extensions/score_mounts/_resolver.py
    • Parse an optional html_extra list into MountSpec, so manifests without the key stay readable.
    • Move the bazel-out/<config>/bin path translation out of resolve_walk_dir into a helper shared with _resolve_data_mounts and mounted_watch_dirs, which drops their hard-coded k8-fastbuild prefix.
  • src/extensions/score_mounts/__init__.py
    • On builder-inited, for HTML-format builders only, resolve every tree to <mount_at>/<dest> and fail on a missing source or a duplicate target.
    • On build-finished without an exception, copy each tree with shutil.copytree(..., dirs_exist_ok=True).
    • Report a directory in bundle data as "is a directory, use html_extra" in place of "does not exist".

Tests

  • Unit tests in src/extensions/score_mounts/tests/: target paths for root and mounted bundles, missing source, duplicate target, non-HTML builder, failed build, and a manifest without the key.
  • Analysis tests in bzl/tests/: invalid labels and destinations, and no trees among the needs_json inputs.
  • An integration scenario in src/tests/docs_bzl/scenarios/html_extra/: a root and a mounted bundle each carry a tree, both index.html files land at their expected paths, and needs_json builds without the tree.
  • Documentation in docs/reference/bazel_macros.rst and docs/how-to/generated_docs.rst.

Estimated effort is about 1.5 days.

Open questions

  • html_extra follows Sphinx's html_extra_path, and extra_html or html_trees are the alternatives.
  • A destination may or may not be allowed to overlap a directory of Sphinx-generated pages, which the copy would overwrite.
  • Live preview runs build-finished on every rebuild, so the copy may need to skip unchanged trees.
主要语言
Python
星标
11
派生
39
平均合并
1 天 13 小时
30 天内合并 PR
65

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

eclipse-score/docs-as-code 的其他 Issue

查看 eclipse-score/docs-as-code 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。