From 9b384e8afc5aa832ae8de14af672f1c1bd15fed3 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 5 Aug 2026 07:37:54 +0000 Subject: [PATCH 1/2] test(sphinxdocs): add regression test for generated conf.py in separate directory --- .../sphinx_docs_conf_in_other_dir/BUILD.bazel | 38 +++++++++++++++++++ .../sphinx_docs_conf_in_other_dir/index.md | 3 ++ .../sphinx_docs_conf_in_other_dir/src_conf.py | 4 ++ 3 files changed, 45 insertions(+) create mode 100644 sphinxdocs/tests/sphinx_docs_conf_in_other_dir/BUILD.bazel create mode 100644 sphinxdocs/tests/sphinx_docs_conf_in_other_dir/index.md create mode 100644 sphinxdocs/tests/sphinx_docs_conf_in_other_dir/src_conf.py diff --git a/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/BUILD.bazel b/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/BUILD.bazel new file mode 100644 index 0000000000..eecbb90897 --- /dev/null +++ b/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/BUILD.bazel @@ -0,0 +1,38 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs") + +_TARGET_COMPATIBLE_WITH = select({ + "@platforms//os:linux": [], + "@platforms//os:macos": [], + "//conditions:default": ["@platforms//:incompatible"], +}) + +genrule( + name = "gen_conf", + srcs = ["src_conf.py"], + outs = ["other_dir/conf.py"], + cmd = "cp $(location src_conf.py) $@", +) + +sphinx_docs( + name = "docs", + srcs = ["index.md"], + config = ":gen_conf", + formats = ["html"], + sphinx = ":sphinx-build", + target_compatible_with = _TARGET_COMPATIBLE_WITH, +) + +sphinx_build_binary( + name = "sphinx-build", + tags = ["manual"], + deps = [ + "@dev_pip//myst_parser", + "@dev_pip//sphinx", + ], +) + +build_test( + name = "docs_build_test", + targets = [":docs"], +) diff --git a/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/index.md b/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/index.md new file mode 100644 index 0000000000..cd7d8b4188 --- /dev/null +++ b/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/index.md @@ -0,0 +1,3 @@ +# Test Documentation + +This is a test document for reproducing conf.py in a separate directory. diff --git a/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/src_conf.py b/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/src_conf.py new file mode 100644 index 0000000000..d4f2f45d31 --- /dev/null +++ b/sphinxdocs/tests/sphinx_docs_conf_in_other_dir/src_conf.py @@ -0,0 +1,4 @@ +project = "Repro Test" +copyright = "2026, Test" +author = "Test" +extensions = ["myst_parser"] From 0f899aaff818ba02dfc9494029e7e0decdac53a1 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 5 Aug 2026 07:57:54 +0000 Subject: [PATCH 2/2] fix(sphinxdocs): fix path resolution for conf.py in separate directory Sphinx documentation builds failed when conf.py was generated or located in a separate directory because _relocate used the relative short_path of config, setting sphinx_source_dir_path to the config subdirectory rather than the source tree root. Relocate ctx.file.config using paths.basename(ctx.file.config.path) so it is always placed at the root of the generated _sources directory. Work towards #3977. --- sphinxdocs/sphinxdocs/private/sphinx.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinxdocs/sphinxdocs/private/sphinx.bzl b/sphinxdocs/sphinxdocs/private/sphinx.bzl index b7c051a154..ea4c5e4501 100644 --- a/sphinxdocs/sphinxdocs/private/sphinx.bzl +++ b/sphinxdocs/sphinxdocs/private/sphinx.bzl @@ -373,7 +373,7 @@ def _sphinx_source_tree_impl(ctx): # Though Sphinx has a -c flag, we move the config file into the sources # directory to make the config more intuitive because some configuration # options are relative to the config location, not the sources directory. - source_conf_file = _relocate(ctx.file.config) + source_conf_file = _relocate(ctx.file.config, paths.basename(ctx.file.config.path)) sphinx_source_dir_path = paths.dirname(source_conf_file.path) for src in ctx.attr.srcs: