Skip to content

fix(sphinxdocs): fix path resolution for conf.py in separate directory - #4006

Merged
rickeylev merged 3 commits into
bazel-contrib:mainfrom
rickeylev:repro_sphinx_config_path
Aug 6, 2026
Merged

fix(sphinxdocs): fix path resolution for conf.py in separate directory#4006
rickeylev merged 3 commits into
bazel-contrib:mainfrom
rickeylev:repro_sphinx_config_path

Conversation

@rickeylev

@rickeylev rickeylev commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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.
Fixes #3999

@rickeylev
rickeylev requested a review from aignas as a code owner August 5, 2026 08:12
@rickeylev
rickeylev force-pushed the repro_sphinx_config_path branch from d1bb8b1 to be8f311 Compare August 6, 2026 03:47
@rickeylev
rickeylev marked this pull request as draft August 6, 2026 03:48
@rickeylev
rickeylev force-pushed the repro_sphinx_config_path branch 6 times, most recently from 952fa5a to 02f3b10 Compare August 6, 2026 06:36
…y and default strip_prefix

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 to "conf.py" at the root of the generated _sources directory.

Additionally, align the sphinx_docs macro implementation with its docstring so that strip_prefix defaults to native.package_name() when None, making doc files automatically relative to the rule location.

Work towards bazel-contrib#3977.
@rickeylev
rickeylev force-pushed the repro_sphinx_config_path branch from 02f3b10 to e75de12 Compare August 6, 2026 06:38
@rickeylev
rickeylev requested review from kaycebasques and removed request for aignas August 6, 2026 06:49
@rickeylev
rickeylev marked this pull request as ready for review August 6, 2026 06:49
# 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if the relocation trick should be also done for the lock rule so that the workspaces can be more easily included.

@rickeylev
rickeylev added this pull request to the merge queue Aug 6, 2026
Merged via the queue into bazel-contrib:main with commit 71a7e31 Aug 6, 2026
8 checks passed
@rickeylev
rickeylev deleted the repro_sphinx_config_path branch August 6, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sphinx_docs cannot use a generated conf.py when its output path conflicts with a sibling executable target

2 participants