From 2bd6b6f994074cf8e5906bc1887a37da1919e281 Mon Sep 17 00:00:00 2001 From: Laurens Hobert Date: Fri, 2 Jan 2026 13:17:30 +0100 Subject: [PATCH 1/2] fix: prevent a 404 error when serving Sphinx docs and Bazel is configured with a --symlink_prefix option When Bazel is configured with a symlink_prefix option, the execpath Make variable does not resolve to the correct directory for generated HTML files. This change updates the logic to use rpathlocation instead, ensuring the correct path is used regardless of the symlink configuration. --- CHANGELOG.md | 2 ++ sphinxdocs/private/sphinx.bzl | 3 ++- sphinxdocs/private/sphinx_server.py | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40d1affe0f..0df0de8cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,6 +135,8 @@ END_UNRELEASED_TEMPLATE * (gazelle) Fix `gazelle_python_manifest.test` so that it accesses manifest files via `runfile` path handling rather than directly ([#3397](https://github.com/bazel-contrib/rules_python/issues/3397)). * (core rules) For the system_python bootstrap, the runfiles root is added to sys.path. +* (sphinxdocs) The sphinxdocs `.serve` target is now compatible with Bazel's `--symlink_prefix` + flag ([#3410](https://github.com/bazel-contrib/rules_python/issues/3410)). {#v1-8-0-added} ### Added diff --git a/sphinxdocs/private/sphinx.bzl b/sphinxdocs/private/sphinx.bzl index e444429233..0efbc269c5 100644 --- a/sphinxdocs/private/sphinx.bzl +++ b/sphinxdocs/private/sphinx.bzl @@ -189,8 +189,9 @@ def sphinx_docs( srcs = [_SPHINX_SERVE_MAIN_SRC], main = _SPHINX_SERVE_MAIN_SRC, data = [html_name], + deps = [Label("//python/runfiles")], args = [ - "$(execpath {})".format(html_name), + "$(rlocationpath {})".format(html_name), ], **common_kwargs_with_manual_tag ) diff --git a/sphinxdocs/private/sphinx_server.py b/sphinxdocs/private/sphinx_server.py index 1f4fae86de..78f1ea2e63 100644 --- a/sphinxdocs/private/sphinx_server.py +++ b/sphinxdocs/private/sphinx_server.py @@ -5,11 +5,12 @@ import time from http import server +from python.runfiles import Runfiles + def main(argv): - build_workspace_directory = os.environ["BUILD_WORKSPACE_DIRECTORY"] - docs_directory = argv[1] - serve_directory = os.path.join(build_workspace_directory, docs_directory) + r = Runfiles.Create() + serve_directory = r.Rlocation(argv[1]) class DirectoryHandler(server.SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs): From 2fb7841cdc2c3115d497d50f58c6208527aa90fe Mon Sep 17 00:00:00 2001 From: Laurens Hobert Date: Fri, 2 Jan 2026 14:27:05 +0100 Subject: [PATCH 2/2] fix: Apply code review feedback by adding a check for None on the return value of Rlocation. --- sphinxdocs/private/sphinx_server.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sphinxdocs/private/sphinx_server.py b/sphinxdocs/private/sphinx_server.py index 78f1ea2e63..1bd6ee5550 100644 --- a/sphinxdocs/private/sphinx_server.py +++ b/sphinxdocs/private/sphinx_server.py @@ -11,6 +11,9 @@ def main(argv): r = Runfiles.Create() serve_directory = r.Rlocation(argv[1]) + if not serve_directory: + print(f"Error: could not find runfile for '{argv[1]}'", file=sys.stderr) + return 1 class DirectoryHandler(server.SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs):