mdbook preprocessor written as a `py_binary` is silently skipped

未关闭
#4,227 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
build-system

调研方向

从 @rules_rust_mdbook//:defs.bzl 加载的 mdbook 规则开始,跟踪 plugins 属性如何处理 py_binary 目标及其可执行文件。使用提供的 MODULE.bazel、BUILD.bazel、book.toml 和示例文件重现问题;当预处理器将 {{secret}} 展开为 42,且构建输出反映这一展开时,即表示完成。

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

描述

awaiting-response mdbook

Description

I have an mdbook target whose preprocessor is a py_binary listed in plugins. The build succeeds, but the preprocessor never runs: the marker it should expand is left unchanged, and nothing appears in the build log to say so.

Reproduction steps

MODULE.bazel

module(name = "repro", version = "0.0.0")

bazel_dep(name = "rules_rust_mdbook", version = "0.73.0")
bazel_dep(name = "rules_python", version = "2.2.0")

BUILD.bazel

load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_rust_mdbook//:defs.bzl", "mdbook")

py_binary(
    name = "mdbook_secret",
    srcs = ["mdbook_secret.py"],
    data = ["secret.txt"],
)

mdbook(
    name = "book",
    srcs = glob(["src/**/*.md"]),
    book = "book.toml",
    plugins = [":mdbook_secret"],
)

book.toml

[book]
title = "Plugin Runfiles Repro"
src = "src"

[preprocessor.secret]
command = "mdbook_secret"

mdbook_secret.py

#!/usr/bin/env python3
"""Replaces {{secret}} with the contents of a data file."""

import json
import sys
from pathlib import Path

SECRET = Path(__file__).parent / "secret.txt"


def main() -> None:
    if len(sys.argv) > 1 and sys.argv[1] == "supports":
        sys.exit(0)

    secret = SECRET.read_text().strip()

    _context, book = json.load(sys.stdin)
    for section in book["sections"]:
        chapter = section.get("Chapter")
        if chapter:
            chapter["content"] = chapter["content"].replace("{{secret}}", secret)

    print(json.dumps(book))


if __name__ == "__main__":
    main()

secret.txt

42

src/SUMMARY.md

# Summary

- [Chapter 1](./chapter_1.md)

src/chapter_1.md

# Chapter 1

The secret is: {{secret}}.

Then:

$ bazel build //:book
INFO: Build completed successfully

$ grep -o "The secret is: [^<]*" bazel-bin/book/chapter_1.html
The secret is: {{secret}}.

Bazel and rules_rust version
Bazel version: 8.7.0
rules_python version 2.2.0
rules_rust_mdbook version: 0.73.0

主要语言
Starlark
星标
857
派生
701
平均合并
4 天 7 小时
30 天内合并 PR
46

环境准备

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

从这里开始

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

bazelbuild/rules_rust 的其他 Issue

查看 bazelbuild/rules_rust 的全部 Issue

相似的 Issue

更多 Build System Issue

把新 issue 发到你的邮箱

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