bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
538 stars 542 forks source link

sphinx_docs_library doesn't support data attribute #2281

Open kaycebasques opened 1 month ago

kaycebasques commented 1 month ago

šŸž bug report

Affected Rule

sphinx_docs_library

Is this a regression?

No. I don't believe sphinx_docs_library has ever supported this attribute but it seems like it should.

Description

We use the literalinclude directive to pull in snippets of code from C++ files into our reStructuredText documentation. It seems like sphinx_docs_library should allow us to specify data dependencies alongside reStructuredText source files.

sphinx_docs_library(
    name = "docs",
    srcs = [
        "backends.rst",
        "docs.rst",
    ],
    data = [
        "examples/basic.cc",
        "examples/once_send_recv.cc",
    ],
    # ...
)

Adding data attribute to our sphinx_docs_library invocations throws errors, however.

literalinclude example: https://cs.opensource.google/pigweed/pigweed/+/385019a0292797dd63f00f008efe36d52d4d698a:pw_async2/docs.rst;l=27;bpv=1

šŸ”¬ Minimal Reproduction

  1. git clone https://pigweed.googlesource.com/pigweed/pigweed
  2. cd pigweed
  3. git fetch https://pigweed.googlesource.com/pigweed/pigweed refs/changes/12/240912/2 && git checkout -b change-240912 FETCH_HEAD
  4. bazelisk build //docs/...

šŸ”„ Exception or Error

ERROR: /home/kayce/pigweed/pigweed/pw_async2/BUILD.bazel:340:20: //pw_async2:docs: no such attribute 'data' in 'sphinx_docs_library' rule
ERROR: /home/kayce/pigweed/pigweed/pw_async2/BUILD.bazel:340:20: Cannot compute config conditions
ERROR: /home/kayce/pigweed/pigweed/docs/BUILD.bazel:27:12: Target '//pw_async2:docs' contains an error and its package is in error and referenced by '//docs:_docs/_sources'
Target //docs:sphinx-build failed to build
ERROR: Analysis of target '//docs:_docs/_sources' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.115s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

šŸŒ Your Environment

Operating System:

(uname -a output)

Linux kayce0 6.9.10-1rodete5-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.9.10-1rodete5 (2024-09-04) x86_64 GNU/Linux

Output of bazel version:

Bazelisk version: v1.19.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Jan 01 00:00:00 1970 (0)
Build timestamp: Thu Jan 01 00:00:00 1970 (0)
Build timestamp as int: 0

Rules_python version:

v0.36.0

Anything else relevant?

this is how we added initial support for rules_python/sphinxdocs stuff last week: https://pwrev.dev/237877

tpudlik commented 1 month ago

@rickeylev FYI

rickeylev commented 1 month ago

You can just put the files in srcs.

The way sphinx works is it basically takes two inputs: the directory of stuff to process (which is expected to have the conf.py file) and the output format to use. The main work the rules do is just creating that directory and relocating all the input files to be under it. Unlike "regular" library targets (like for a programming language), there isn't any distinction between "source files some compiler processes" and "opaque data payloads". It's all just files being staged into a directory.

Also, in case it helps:

kaycebasques commented 1 month ago

I will send a PR proposing some docs updates next week and then we can close this issue out