mdbook preprocessor written as a `py_binary` is silently skipped

Đang mở
#4,227 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu với quy tắc mdbook được nạp từ @rules_rust_mdbook//:defs.bzl và theo dõi cách thuộc tính plugins xử lý target py_binary cùng tệp thực thi của nó. Tái hiện vấn đề với các tệp MODULE.bazel, BUILD.bazel, book.toml và các tệp mẫu được cung cấp; hoàn thành khi bộ tiền xử lý mở rộng {{secret}} thành 42 và đầu ra build phản ánh sự mở rộng đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Starlark
Star
857
Fork
701
Merge trung bình
4 ngày 7 giờ
Pull request đã merge (30 ngày)
46

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bazelbuild/rules_rust

Tất cả issue của bazelbuild/rules_rust

Issue tương tự

Thêm issue về Build System

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.