Add Extensions#

The docs-as-code module defines its own Python environment in MODULE.bazel and as a user you cannot extend that. If you want to add Sphinx extensions, you must duplicate the Python environment first.

Once you have your own Python environment, supply all necessary packages to docs via the deps attribute.

Listing 1 In your BUILD file#
 load("@your_python_env//:requirements.bzl", "all_requirements")

 docs(
     # ...other attributes...
     deps = all_requirements
 )

Inside docs(), the docs-as-code module will check if you have supplied all necessary dependencies.

How to Create a Python Environment?#

The general documentation is in the rules_python documentation.

You can also peek into this docs-as-code repo’s MODULE.bazel file how docs_as_code_hub_env is defined and use it as a template for your_python_env.

Recommendation: Use compile_pip_requirements because it is a solid practice anyways. Next, get @score_docs_as_code//src:requirements.in as one of the inputs to ensure you have all the necessary dependencies for docs-as-code.

Listing 2 Example BUILD file snippet#
 load("@rules_python//python:pip.bzl", "compile_pip_requirements")

 compile_pip_requirements(
     name = "requirements",
     srcs = [
         "@score_docs_as_code//src:requirements.in",
         "requirements.in",
     ],
     requirements_txt = "requirements_lock.txt",
     visibility = ["//visibility:public"],
 )