blob: 4c8e4a2a6bb55fa2966f417a7b92230638a5a111 [file] [log] [blame]
Richard Levasseurede4fd42023-10-17 13:17:34 -07001# Configuration file for the Sphinx documentation builder.
2
Richard Levasseura326b682023-10-30 16:50:57 -07003import os
4
Richard Levasseurede4fd42023-10-17 13:17:34 -07005# -- Project information
6project = "rules_python"
7copyright = "2023, The Bazel Authors"
8author = "Bazel"
9
Richard Levasseur327b4e32023-10-19 11:03:01 -070010# NOTE: These are overriden by -D flags via --//sphinxdocs:extra_defines
11version = "0.0.0"
12release = version
Richard Levasseurede4fd42023-10-17 13:17:34 -070013
14# -- General configuration
Richard Levasseur327b4e32023-10-19 11:03:01 -070015# See https://www.sphinx-doc.org/en/master/usage/configuration.html
16# for more settings
Richard Levasseurede4fd42023-10-17 13:17:34 -070017
18# Any extensions here not built into Sphinx must also be added to
Richard Levasseurd7d2ce72024-08-20 17:07:22 -070019# the dependencies of //docs:sphinx-builder
Richard Levasseurede4fd42023-10-17 13:17:34 -070020extensions = [
Richard Levasseur2f468732024-08-25 19:10:30 -070021 "autodoc2",
Richard Levasseurede4fd42023-10-17 13:17:34 -070022 "sphinx.ext.autosectionlabel",
Richard Levasseur327b4e32023-10-19 11:03:01 -070023 "sphinx.ext.doctest",
24 "sphinx.ext.duration",
25 "sphinx.ext.extlinks",
26 "sphinx.ext.intersphinx",
Richard Levasseurede4fd42023-10-17 13:17:34 -070027 "myst_parser",
28 "sphinx_rtd_theme", # Necessary to get jquery to make flyout work
Richard Levasseur975edfe2024-05-24 21:52:43 -070029 "sphinx_bzl.bzl",
Richard Levasseur2f468732024-08-25 19:10:30 -070030 "sphinx_reredirects",
Richard Levasseurede4fd42023-10-17 13:17:34 -070031]
32
Richard Levasseur2f468732024-08-25 19:10:30 -070033autodoc2_packages = [
34 "sphinx_bzl",
35 "runfiles",
36]
37
38autodoc2_output_dir = "api/py"
39autodoc2_sort_names = True
40autodoc2_class_docstring = "both"
41autodoc2_index_template = """
42Python APIs
43====================
44
45This page contains auto-generated API reference documentation [#f1]_.
46
47.. toctree::
48 :titlesonly:
49
50{% for package in top_level %}
51 {{ package }}
52{%- endfor %}
53
54.. [#f1] Created with `sphinx-autodoc2 <https://github.com/chrisjsewell/sphinx-autodoc2>`_
55
56"""
57
58
59autodoc2_docstring_parser_regexes = [
60 (".*", "myst"),
61]
Richard Levasseurdd5db652024-10-15 16:33:37 -070062
Richard Levasseur2f468732024-08-25 19:10:30 -070063# NOTE: The redirects generation will clobber existing files.
64redirects = {
65 "api/tools/precompiler/index": "/api/rules_python/tools/precompiler/index.html",
66 "api/python/py_library": "/api/rules_python/python/py_library.html",
67 "api/python/py_binary": "/api/rules_python/python/py_binary.html",
68 "api/python/py_test": "/api/rules_python/python/py_test.html",
69 "api/python/defs": "/api/rules_python/python/defs.html",
70 "api/python/index": "/api/rules_python/python/index.html",
71 "api/python/py_runtime_info": "/api/rules_python/python/py_runtime_info.html",
Richard Levasseur7c5e7cf2024-10-29 20:32:35 -070072 "api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/py_library_rule.html",
Richard Levasseurdd5db652024-10-15 16:33:37 -070073 "api/python/private/common/py_test_rule_bazel": "/api/rules_python/python/private/py_test_rule_bazel.html",
Richard Levasseur7c5e7cf2024-10-29 20:32:35 -070074 "api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/py_binary_rule.html",
Richard Levasseurdd5db652024-10-15 16:33:37 -070075 "api/python/private/common/py_runtime_rule": "/api/rules_python/python/private/py_runtime_rule.html",
Richard Levasseur2f468732024-08-25 19:10:30 -070076 "api/python/extensions/pip": "/api/rules_python/python/extensions/pip.html",
77 "api/python/extensions/python": "/api/rules_python/python/extensions/python.html",
78 "api/python/entry_points/py_console_script_binary": "/api/rules_python/python/entry_points/py_console_script_binary.html",
79 "api/python/cc/py_cc_toolchain_info": "/api/rules_python/python/cc/py_cc_toolchain_info.html",
80 "api/python/cc/index": "/api/rules_python/python/cc/index.html",
81 "api/python/py_cc_link_params_info": "/api/rules_python/python/py_cc_link_params_info.html",
82 "api/python/runtime_env_toolchains/index": "/api/rules_python/python/runtime_env_toolchains/index.html",
83 "api/python/pip": "/api/rules_python/python/pip.html",
84 "api/python/config_settings/index": "/api/rules_python/python/config_settings/index.html",
85 "api/python/packaging": "/api/rules_python/python/packaging.html",
86 "api/python/py_runtime": "/api/rules_python/python/py_runtime.html",
87 "api/sphinxdocs/sphinx": "/api/sphinxdocs/sphinxdocs/sphinx.html",
88 "api/sphinxdocs/sphinx_stardoc": "/api/sphinxdocs/sphinxdocs/sphinx_stardoc.html",
89 "api/sphinxdocs/readthedocs": "/api/sphinxdocs/sphinxdocs/readthedocs.html",
90 "api/sphinxdocs/index": "/api/sphinxdocs/sphinxdocs/index.html",
91 "api/sphinxdocs/private/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/private/sphinx_docs_library.html",
92 "api/sphinxdocs/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/sphinx_docs_library.html",
93 "api/sphinxdocs/inventories/index": "/api/sphinxdocs/sphinxdocs/inventories/index.html",
94}
95
Richard Levasseura326b682023-10-30 16:50:57 -070096# Adapted from the template code:
97# https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
98if os.environ.get("READTHEDOCS") == "True":
Richard Levasseur900d8012023-11-30 02:05:05 -080099 # Must come first because it can interfere with other extensions, according
100 # to the original conf.py template comments
101 extensions.insert(0, "readthedocs_ext.readthedocs")
Richard Levasseura326b682023-10-30 16:50:57 -0700102
Richard Levasseur900d8012023-11-30 02:05:05 -0800103 if os.environ.get("READTHEDOCS_VERSION_TYPE") == "external":
104 # Insert after the main extension
105 extensions.insert(1, "readthedocs_ext.external_version_warning")
106 readthedocs_vcs_url = (
107 "http://github.com/bazelbuild/rules_python/pull/{}".format(
108 os.environ.get("READTHEDOCS_VERSION", "")
109 )
110 )
111 # The build id isn't directly available, but it appears to be encoded
112 # into the host name, so we can parse it from that. The format appears
113 # to be `build-X-project-Y-Z`, where:
114 # * X is an integer build id
115 # * Y is an integer project id
116 # * Z is the project name
117 _build_id = os.environ.get("HOSTNAME", "build-0-project-0-rules-python")
118 _build_id = _build_id.split("-")[1]
119 readthedocs_build_url = (
120 f"https://readthedocs.org/projects/rules-python/builds/{_build_id}"
121 )
Richard Levasseura326b682023-10-30 16:50:57 -0700122
Richard Levasseur327b4e32023-10-19 11:03:01 -0700123exclude_patterns = ["_includes/*"]
Richard Levasseurede4fd42023-10-17 13:17:34 -0700124templates_path = ["_templates"]
Richard Levasseur327b4e32023-10-19 11:03:01 -0700125primary_domain = None # The default is 'py', which we don't make much use of
126nitpicky = True
Richard Levasseurede4fd42023-10-17 13:17:34 -0700127
Richard Levasseur327b4e32023-10-19 11:03:01 -0700128# --- Intersphinx configuration
Richard Levasseurede4fd42023-10-17 13:17:34 -0700129
Richard Levasseur327b4e32023-10-19 11:03:01 -0700130intersphinx_mapping = {
131 "bazel": ("https://bazel.build/", "bazel_inventory.inv"),
132}
Richard Levasseurede4fd42023-10-17 13:17:34 -0700133
Richard Levasseur327b4e32023-10-19 11:03:01 -0700134# --- Extlinks configuration
135extlinks = {
136 "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"),
137}
Richard Levasseurede4fd42023-10-17 13:17:34 -0700138
Richard Levasseur327b4e32023-10-19 11:03:01 -0700139# --- MyST configuration
140# See https://myst-parser.readthedocs.io/en/latest/configuration.html
141# for more settings
Richard Levasseurede4fd42023-10-17 13:17:34 -0700142
143# See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html
144# for additional extensions.
145myst_enable_extensions = [
146 "fieldlist",
147 "attrs_block",
148 "attrs_inline",
149 "colon_fence",
150 "deflist",
Richard Levasseur327b4e32023-10-19 11:03:01 -0700151 "substitution",
Richard Levasseurede4fd42023-10-17 13:17:34 -0700152]
153
Richard Levasseur327b4e32023-10-19 11:03:01 -0700154myst_substitutions = {}
155
Richard Levasseur6ca2f582024-05-23 20:44:47 -0700156# --- sphinx_stardoc configuration
157
158bzl_default_repository_name = "@rules_python"
159
Richard Levasseur327b4e32023-10-19 11:03:01 -0700160# -- Options for HTML output
161# See https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
162# For additional html settings
163
164# See https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html for
165# them-specific options
166html_theme = "sphinx_rtd_theme"
167html_theme_options = {}
168
Richard Levasseura326b682023-10-30 16:50:57 -0700169# The html_context settings are part of the jinja context used by the themes.
170html_context = {
171 # This controls whether the flyout menu is shown. It is always false
172 # because:
173 # * For local builds, the flyout menu is empty and doesn't show in the
174 # same place as for RTD builds. No point in showing it locally.
175 # * For RTD builds, the flyout menu is always automatically injected,
176 # so having it be True makes the flyout show up twice.
177 "READTHEDOCS": False,
Richard Levasseur900d8012023-11-30 02:05:05 -0800178 "PRODUCTION_DOMAIN": "readthedocs.org",
Richard Levasseura326b682023-10-30 16:50:57 -0700179 # This is the path to a page's source (after the github user/repo/commit)
Richard Levasseurd7d2ce72024-08-20 17:07:22 -0700180 "conf_py_path": "/docs/",
Richard Levasseur900d8012023-11-30 02:05:05 -0800181 "github_user": "bazelbuild",
182 "github_repo": "rules_python",
Richard Levasseura326b682023-10-30 16:50:57 -0700183 # The git version that was checked out, e.g. the tag or branch name
Richard Levasseur900d8012023-11-30 02:05:05 -0800184 "github_version": os.environ.get("READTHEDOCS_GIT_IDENTIFIER", ""),
Richard Levasseura326b682023-10-30 16:50:57 -0700185 # For local builds, the github link won't work. Disabling it replaces
186 # it with a "view source" link to view the source Sphinx saw, which
187 # is useful for local development.
Richard Levasseur900d8012023-11-30 02:05:05 -0800188 "display_github": os.environ.get("READTHEDOCS") == "True",
189 "commit": os.environ.get("READTHEDOCS_GIT_COMMIT_HASH", "unknown commit"),
Richard Levasseura326b682023-10-30 16:50:57 -0700190 # Used by readthedocs_ext.external_version_warning extension
191 # This is the PR number being built
Richard Levasseur900d8012023-11-30 02:05:05 -0800192 "current_version": os.environ.get("READTHEDOCS_VERSION", ""),
Richard Levasseura326b682023-10-30 16:50:57 -0700193}
194
Richard Levasseur327b4e32023-10-19 11:03:01 -0700195# Keep this in sync with the stardoc templates
196html_permalinks_icon = "ΒΆ"
197
Richard Levasseurede4fd42023-10-17 13:17:34 -0700198# These folders are copied to the documentation's HTML output
199html_static_path = ["_static"]
200
201# These paths are either relative to html_static_path
202# or fully qualified paths (eg. https://...)
203html_css_files = [
204 "css/custom.css",
205]
206
207# -- Options for EPUB output
208epub_show_urls = "footnote"
Richard Levasseur327b4e32023-10-19 11:03:01 -0700209
Richard Levasseur13ce1922024-08-19 11:08:38 -0700210suppress_warnings = [
211 # The autosectionlabel extension turns header titles into referencable
212 # names. Unfortunately, CHANGELOG.md has many duplicate header titles,
213 # which creates lots of warning spam. Just ignore them.
214 "autosectionlabel.*"
215]
Richard Levasseur900d8012023-11-30 02:05:05 -0800216
Richard Levasseur327b4e32023-10-19 11:03:01 -0700217
Richard Levasseur327b4e32023-10-19 11:03:01 -0700218def setup(app):
Richard Levasseur900d8012023-11-30 02:05:05 -0800219 # Pygments says it supports starlark, but it doesn't seem to actually
220 # recognize `starlark` as a name. So just manually map it to python.
221 from sphinx.highlighting import lexer_classes
222
223 app.add_lexer("starlark", lexer_classes["python"])