mdbook preprocessor written as a `py_binary` is silently skipped

Open
#4,227 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
build-system

Research direction

Start with the mdbook rule loaded from @rules_rust_mdbook//:defs.bzl and trace how the plugins attribute handles the py_binary target and its executable. Reproduce the issue with the provided MODULE.bazel, BUILD.bazel, book.toml, and sample files; done means the preprocessor expands {{secret}} to 42 and the build output reflects the expansion.

Written by the indexing model from the issue text.

Description

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

Dominant language
Starlark
Stars
857
Forks
701
Avg merge
4d 7h
Merged PRs (30d)
46

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_rust

All issues in bazelbuild/rules_rust

Similar issues

More Build System issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.