Skip to content

chore: split sphinxdocs into its own module#3629

Open
rickeylev wants to merge 7 commits intobazel-contrib:mainfrom
rickeylev:sphinxdocs.split
Open

chore: split sphinxdocs into its own module#3629
rickeylev wants to merge 7 commits intobazel-contrib:mainfrom
rickeylev:sphinxdocs.split

Conversation

@rickeylev
Copy link
Collaborator

Splitting sphinxdocs into its own module is desirable to reduce the dependency
footprint of rules_python outside of development mode modules.

Work towards #2511

@rickeylev rickeylev requested a review from aignas as a code owner February 23, 2026 05:32
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rickeylev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the project structure by isolating the sphinxdocs components into a dedicated Bazel module. This separation aims to streamline the core rules_python codebase by externalizing documentation-related dependencies, thereby improving build performance and reducing the overall complexity for users who do not require documentation generation. The changes involve creating a complete Bazel module for sphinxdocs and updating all relevant build files and Starlark code to reflect this new modular architecture.

Highlights

  • Modularity: The sphinxdocs functionality has been extracted into its own independent Bazel module, reducing the dependency footprint of rules_python outside of development contexts.
  • Bazel Configuration: A new sphinxdocs module has been created with its own MODULE.bazel, .bazelrc, .bazelversion, and Bazel Central Registry (BCR) metadata files, establishing it as a distinct entity.
  • Dependency Updates: All internal references to sphinxdocs within rules_python have been updated to use the @sphinxdocs// prefix, treating it as an external module. Dependencies within the new sphinxdocs module now use relative paths.
  • Visibility and Utilities: The visibility of python/private/BUILD.bazel has been extended to allow access from the new sphinxdocs module. A new util.bzl file has been introduced within sphinxdocs/private to house common utility functions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .bazelignore
    • Added sphinxdocs to the ignore list to prevent Bazel from processing it in the main workspace.
  • .bcr/config.yml
    • Included sphinxdocs in the moduleRoots to register it as a discoverable module for the Bazel Central Registry.
  • .bcr/sphinxdocs/metadata.template.json
    • Added a new metadata file defining the sphinxdocs module's details for the Bazel Central Registry.
  • .bcr/sphinxdocs/presubmit.yml
    • Added a new presubmit configuration file for the sphinxdocs module, specifying its testing matrix and commands.
  • .bcr/sphinxdocs/source.template.json
    • Added a new source template file for the sphinxdocs module, detailing how its source code is fetched.
  • MODULE.bazel
    • Removed stardoc as a non-development dependency.
    • Added sphinxdocs as a development dependency with a local path override to its new location.
  • docs/BUILD.bazel
    • Updated load statements to reference readthedocs.bzl, sphinx.bzl, sphinx_docs_library.bzl, and sphinx_stardoc.bzl from the @sphinxdocs external module.
    • Modified renamed_srcs and deps to use the @sphinxdocs//inventories:bazel_inventory and @sphinxdocs//docs:docs_lib labels respectively.
    • Updated sphinx_build_binary dependencies to reference @sphinxdocs//src/sphinx_bzl.
  • docs/conf.py
    • Updated a comment to reflect the new @sphinxdocs//:extra_defines flag syntax.
  • docs/readthedocs_build.sh
    • Modified extra_env and extra_defines flags to use the @sphinxdocs// prefix for module-specific settings.
  • python/private/BUILD.bazel
    • Extended default_visibility to include @sphinxdocs//:__subpackages__ to allow the new module to access private Python rules.
    • Changed the visibility of util_bzl to //visibility:public.
  • sphinxdocs/.bazelrc
    • Added a new Bazel configuration file for the sphinxdocs module, including build and test settings.
  • sphinxdocs/.bazelrc.deleted_packages
    • Added a new configuration file for deleted packages specific to the sphinxdocs module.
  • sphinxdocs/.bazelversion
    • Added a new file specifying Bazel version 8.x for the sphinxdocs module.
  • sphinxdocs/BUILD.bazel
    • Updated load statements to use relative paths for sphinx.bzl, sphinx_docs_library.bzl, sphinx_stardoc.bzl, and readthedocs.bzl within the sphinxdocs module.
    • Adjusted deps for sphinx_bzl, sphinx_docs_library_bzl, sphinx_stardoc_bzl, and readthedocs_bzl to use relative paths.
  • sphinxdocs/MODULE.bazel
    • Added a new module definition for sphinxdocs, including its version, compatibility level, and dependencies like bazel_skylib, stardoc, platforms, protobuf, and rules_python with local path overrides.
  • sphinxdocs/docs/BUILD.bazel
    • Updated load statements to use relative paths for util.bzl, sphinx_docs_library.bzl, and sphinx_stardoc.bzl.
    • Made docs_lib public by adding visibility = ["//visibility:public"].
    • Adjusted srcs for bzl_docs and py_api_srcs to use relative paths within the sphinxdocs module.
  • sphinxdocs/docs/api/sphinxdocs/index.md
    • Updated bzl:currentfile and the main heading to reflect the new module root, changing //sphinxdocs:BUILD.bazel to //:BUILD.bazel.
  • sphinxdocs/docs/api/sphinxdocs/inventories/index.md
    • Updated bzl:currentfile and the main heading to reflect the new module root, changing //sphinxdocs/inventories:BUILD.bazel to //inventories:BUILD.bazel.
  • sphinxdocs/docs/readthedocs.md
    • Updated references to extra_env and extra_defines flags to use the //: prefix instead of @rules_python//sphinxdocs:.
  • sphinxdocs/docs/sphinx-bzl.md
    • Updated the dependency reference for enabling the Sphinx plugin from @rules_python//sphinxdocs/src/sphinx_bzl to //src/sphinx_bzl.
  • sphinxdocs/docs/starlark-docgen.md
    • Updated dependency references for sphinx_bzl plugin from @rules_python//sphinxdocs/src/sphinx_bzl to //src/sphinx_bzl.
  • sphinxdocs/integration_tests/bcr/BUILD.bazel
    • Added a new build file for BCR integration tests within the sphinxdocs module.
  • sphinxdocs/integration_tests/bcr/MODULE.bazel
    • Added a new module definition for BCR integration tests, including local path overrides for sphinxdocs and rules_python.
  • sphinxdocs/integration_tests/bcr/conf.py
    • Added a new Sphinx configuration file for the integration tests.
  • sphinxdocs/integration_tests/bcr/index.md
    • Added a new Markdown file for the Sphinxdocs example documentation.
  • sphinxdocs/inventories/BUILD.bazel
    • Updated the load statement for sphinx_inventory to use a relative path within the sphinxdocs module.
  • sphinxdocs/private/BUILD.bazel
    • Updated load statements for py_binary and py_library to reference @rules_python//python.
    • Adjusted default_visibility to //:__subpackages__.
    • Updated comments to reflect the new module structure.
    • Added a new bzl_library target for util_bzl.
    • Modified deps for sphinx_docs_library_macro_bzl, sphinx_bzl, sphinx_stardoc_bzl, and readthedocs_bzl to use relative paths or @rules_python//python.
  • sphinxdocs/private/readthedocs.bzl
    • Updated load statements for py_binary and add_tag to reference @rules_python//python and //private respectively.
    • Modified _INSTALL_MAIN_SRC to use //private:readthedocs_install.py.
    • Updated add_tag call to use //:readthedocs_install.
    • Changed deps for py_binary to @rules_python//python/runfiles.
  • sphinxdocs/private/sphinx.bzl
    • Updated load statements for py_binary and add_tag to reference @rules_python//python and //private respectively.
    • Modified _SPHINX_BUILD_MAIN_SRC and _SPHINX_SERVE_MAIN_SRC to use //private.
    • Updated add_tag calls to use //:sphinx_build_binary and //:sphinx_docs.
    • Changed deps for py_binary to @rules_python//python/runfiles.
    • Updated default values for _extra_defines_flag, _extra_env_flag, and _quiet_flag to use //:.
  • sphinxdocs/private/sphinx_docs_library_macro.bzl
    • Updated load statement for add_tag to use //private:util.bzl.
    • Modified add_tag call to use //:sphinx_docs_library.
  • sphinxdocs/private/sphinx_stardoc.bzl
    • Updated load statements for add_tag and sphinx_docs_library to use //private.
    • Modified add_tag calls to use //:sphinx_stardocs and //:sphinx_stardoc.
    • Updated default value for _proto_to_markdown to use //private:proto_to_markdown.
  • sphinxdocs/private/util.bzl
    • Added a new utility file containing BZLMOD_ENABLED, copy_propagating_kwargs, and add_tag functions.
  • sphinxdocs/readthedocs.bzl
    • Updated load statement for _readthedocs_install to use a relative path within the sphinxdocs module.
  • sphinxdocs/sphinx.bzl
    • Updated load statement for _sphinx_build_binary, _sphinx_docs, and _sphinx_inventory to use a relative path within the sphinxdocs module.
  • sphinxdocs/sphinx_docs_library.bzl
    • Updated load statement for _sphinx_docs_library to use a relative path within the sphinxdocs module.
  • sphinxdocs/sphinx_stardoc.bzl
    • Updated load statement for _sphinx_stardoc and _sphinx_stardocs to use a relative path within the sphinxdocs module.
  • sphinxdocs/src/sphinx_bzl/BUILD.bazel
    • Updated load statement for py_library to reference @rules_python//python.
  • sphinxdocs/src/sphinx_bzl/bzl.py
    • Updated a comment to reflect the new //:quiet=false flag syntax.
  • sphinxdocs/tests/proto_to_markdown/BUILD.bazel
    • Updated load statement for py_test to reference @rules_python//python.
    • Modified deps for proto_to_markdown_test to use //private:proto_to_markdown_lib.
  • sphinxdocs/tests/proto_to_markdown/proto_to_markdown_test.py
    • Updated the import statement for proto_to_markdown to use a relative path.
  • sphinxdocs/tests/sphinx_docs/BUILD.bazel
    • Updated load statement for sphinx_build_binary and sphinx_docs to use a relative path within the sphinxdocs module.
  • sphinxdocs/tests/sphinx_stardoc/BUILD.bazel
    • Updated load statements for py_test, sphinx_build_binary, sphinx_docs, sphinx_stardoc, and sphinx_stardocs to reference @rules_python//python and use relative paths.
    • Modified renamed_srcs to use //inventories:bazel_inventory.
  • sphinxdocs/tests/sphinx_stardoc/index.md
    • Updated bazel run commands to use relative paths for the docs.serve and docs targets.
  • sphinxdocs/tests/sphinx_stardoc/sphinx_output_test.py
    • Updated the import statement for sphinx_stardoc to use a relative path.
  • sphinxdocs/tests/sphinx_stardoc/xrefs.md
    • Updated the cross-reference path for GenericInfo to use a relative path.
Activity
  • The pull request was initiated by rickeylev with the goal of modularizing sphinxdocs.
  • New Bazel module infrastructure for sphinxdocs was created, including MODULE.bazel, .bazelrc, .bazelversion, and BCR configuration files.
  • Extensive refactoring of BUILD.bazel files and Starlark code was performed across rules_python and the new sphinxdocs module to align with the new module boundaries.
  • Dependencies and load statements were updated to correctly reference targets either within the new sphinxdocs module or from rules_python as an external dependency.
  • A util.bzl file was added to sphinxdocs/private, likely consolidating common Starlark functions for the new module.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant refactoring that splits sphinxdocs into its own Bazel module to reduce dependencies. The changes are extensive and mostly look correct, with many path and dependency updates to support the new module structure.

I've identified a few issues that need attention:

  • A potential bug in a presubmit script for Windows due to incorrect shell command syntax.
  • An incorrect Python import in a test that will likely cause it to fail.
  • A typo in a code example within the documentation.
  • Some inconsistency regarding a duplicated utility file (util.bzl). While the duplication might be intentional to break dependencies, a related visibility change in rules_python is confusing and should be clarified or reverted.

Please see my detailed comments for suggestions on how to address these points.

from stardoc.proto import stardoc_output_pb2

from sphinxdocs.private import proto_to_markdown
from private import proto_to_markdown
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The proto_to_markdown_lib target in sphinxdocs/private/BUILD.bazel has imports = ["."], which adds the sphinxdocs/private directory to the PYTHONPATH. Therefore, you should import proto_to_markdown directly. The current import from private import proto_to_markdown will likely fail because private is not a package (it's missing an __init__.py and incompatible_default_to_explicit_init_py is enabled in .bazelrc).

Suggested change
from private import proto_to_markdown
import proto_to_markdown

visibility = [
"//:__subpackages__",
],
visibility = ["//visibility:public"],
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

You're making util_bzl public here, but the sphinxdocs module is introducing its own copy of util.bzl instead of using this one. This leads to code duplication and is confusing. If the intent is to decouple sphinxdocs from rules_python's private implementation details (like PyInfo), it would be better to not make this target public and stick with the copied version in sphinxdocs. If this visibility change is no longer needed, please revert it to avoid confusion.

# File: docs/BUILD

load("@rules_python//sphinxdocs:readthedocs.bzl.bzl", "readthedocs_install")
load("//:readthedocs.bzl.bzl", "readthedocs_install")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There seems to be a typo in the filename in this load statement. It should be readthedocs.bzl, not readthedocs.bzl.bzl.

Suggested change
load("//:readthedocs.bzl.bzl", "readthedocs_install")
load("//:readthedocs.bzl", "readthedocs_install")

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

Naming of new imports from rules_python LGTM.

The key purpose of the shell script it to set the
`--@rules_python//sphinxdocs:extra_env` and
`--@rules_python//sphinxdocs:extra_defines` flags. These are used to communicate
`--//:extra_env` and
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use @sphinxdocs// instead of //

# These are only exported because they're passed as files to the //
# macros, and thus must be visible to other packages. They should only be
# referenced by the //sphinxdocs macros.
# referenced by the // macros.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# referenced by the // macros.
# referenced by the @sphinxdocs macros.

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.

2 participants