Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/4201.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(sphinxdocs) Fixed `sphinx_docs` `.run` targets failing to locate the `sphinx`
binary when defined in the root package
([#4201](https://github.com/bazel-contrib/rules_python/issues/4201)).
2 changes: 1 addition & 1 deletion sphinxdocs/sphinxdocs/private/sphinx_run_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [[ -z "$source_dir" ]]; then
exit 1
fi

for path in "%SPHINX_RUNFILES_PATH%" "%SPHINX_EXEC_PATH%"; do
for path in "./%SPHINX_RUNFILES_PATH%" "./%SPHINX_EXEC_PATH%"; do
if [[ -e $path ]]; then
sphinx=$path
break
Expand Down
5 changes: 4 additions & 1 deletion sphinxdocs/tests/sphinx_docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ build_test(
py_test(
name = "sphinx_docs_output_test",
srcs = ["sphinx_docs_output_test.py"],
data = [":docs"],
data = [
":docs",
":docs.run",
],
deps = ["@pypi//absl_py"],
)
12 changes: 12 additions & 0 deletions sphinxdocs/tests/sphinx_docs/sphinx_docs_output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def test_custom_sphinx_docs_library_info_transitives(self):
)
self.assertTrue(os.path.exists(str(page_path)), f"Not found at {page_path}")

def test_sphinx_run_script_uses_relative_sphinx_paths(self):
# Verify the generated .run script prefixes the sphinx binary paths with "./"
# so `env` resolves the binary relative to the working directory instead of
# searching $PATH when the target is in the root package (where short_path
# has no slash). See https://github.com/bazel-contrib/rules_python/issues/4201.
docs_run_path = importlib.resources.files(sphinx_docs).joinpath("docs.run")
script_content = docs_run_path.read_text()
self.assertIn(
'for path in "./tests/sphinx_docs/sphinx-build" "./bazel-out/',
script_content,
)


if __name__ == "__main__":
absltest.main()
Loading