blob: be428a6eb8bfd31e32016d7332e2c2691f03c269 [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 Levasseurede4fd42023-10-17 13:17:34 -070021 "sphinx.ext.autodoc",
Richard Levasseurede4fd42023-10-17 13:17:34 -070022 "sphinx.ext.autosectionlabel",
Richard Levasseur327b4e32023-10-19 11:03:01 -070023 "sphinx.ext.autosummary",
24 "sphinx.ext.doctest",
25 "sphinx.ext.duration",
26 "sphinx.ext.extlinks",
27 "sphinx.ext.intersphinx",
Richard Levasseurede4fd42023-10-17 13:17:34 -070028 "myst_parser",
29 "sphinx_rtd_theme", # Necessary to get jquery to make flyout work
Richard Levasseur975edfe2024-05-24 21:52:43 -070030 "sphinx_bzl.bzl",
Richard Levasseurede4fd42023-10-17 13:17:34 -070031]
32
Richard Levasseura326b682023-10-30 16:50:57 -070033# Adapted from the template code:
34# https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
35if os.environ.get("READTHEDOCS") == "True":
Richard Levasseur900d8012023-11-30 02:05:05 -080036 # Must come first because it can interfere with other extensions, according
37 # to the original conf.py template comments
38 extensions.insert(0, "readthedocs_ext.readthedocs")
Richard Levasseura326b682023-10-30 16:50:57 -070039
Richard Levasseur900d8012023-11-30 02:05:05 -080040 if os.environ.get("READTHEDOCS_VERSION_TYPE") == "external":
41 # Insert after the main extension
42 extensions.insert(1, "readthedocs_ext.external_version_warning")
43 readthedocs_vcs_url = (
44 "http://github.com/bazelbuild/rules_python/pull/{}".format(
45 os.environ.get("READTHEDOCS_VERSION", "")
46 )
47 )
48 # The build id isn't directly available, but it appears to be encoded
49 # into the host name, so we can parse it from that. The format appears
50 # to be `build-X-project-Y-Z`, where:
51 # * X is an integer build id
52 # * Y is an integer project id
53 # * Z is the project name
54 _build_id = os.environ.get("HOSTNAME", "build-0-project-0-rules-python")
55 _build_id = _build_id.split("-")[1]
56 readthedocs_build_url = (
57 f"https://readthedocs.org/projects/rules-python/builds/{_build_id}"
58 )
Richard Levasseura326b682023-10-30 16:50:57 -070059
Richard Levasseur327b4e32023-10-19 11:03:01 -070060exclude_patterns = ["_includes/*"]
Richard Levasseurede4fd42023-10-17 13:17:34 -070061templates_path = ["_templates"]
Richard Levasseur327b4e32023-10-19 11:03:01 -070062primary_domain = None # The default is 'py', which we don't make much use of
63nitpicky = True
Richard Levasseurede4fd42023-10-17 13:17:34 -070064
Richard Levasseur327b4e32023-10-19 11:03:01 -070065# --- Intersphinx configuration
Richard Levasseurede4fd42023-10-17 13:17:34 -070066
Richard Levasseur327b4e32023-10-19 11:03:01 -070067intersphinx_mapping = {
68 "bazel": ("https://bazel.build/", "bazel_inventory.inv"),
69}
Richard Levasseurede4fd42023-10-17 13:17:34 -070070
Richard Levasseur327b4e32023-10-19 11:03:01 -070071# --- Extlinks configuration
72extlinks = {
73 "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"),
74}
Richard Levasseurede4fd42023-10-17 13:17:34 -070075
Richard Levasseur327b4e32023-10-19 11:03:01 -070076# --- MyST configuration
77# See https://myst-parser.readthedocs.io/en/latest/configuration.html
78# for more settings
Richard Levasseurede4fd42023-10-17 13:17:34 -070079
80# See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html
81# for additional extensions.
82myst_enable_extensions = [
83 "fieldlist",
84 "attrs_block",
85 "attrs_inline",
86 "colon_fence",
87 "deflist",
Richard Levasseur327b4e32023-10-19 11:03:01 -070088 "substitution",
Richard Levasseurede4fd42023-10-17 13:17:34 -070089]
90
Richard Levasseur327b4e32023-10-19 11:03:01 -070091myst_substitutions = {}
92
Richard Levasseur6ca2f582024-05-23 20:44:47 -070093# --- sphinx_stardoc configuration
94
95bzl_default_repository_name = "@rules_python"
96
Richard Levasseur327b4e32023-10-19 11:03:01 -070097# -- Options for HTML output
98# See https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
99# For additional html settings
100
101# See https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html for
102# them-specific options
103html_theme = "sphinx_rtd_theme"
104html_theme_options = {}
105
Richard Levasseura326b682023-10-30 16:50:57 -0700106# The html_context settings are part of the jinja context used by the themes.
107html_context = {
108 # This controls whether the flyout menu is shown. It is always false
109 # because:
110 # * For local builds, the flyout menu is empty and doesn't show in the
111 # same place as for RTD builds. No point in showing it locally.
112 # * For RTD builds, the flyout menu is always automatically injected,
113 # so having it be True makes the flyout show up twice.
114 "READTHEDOCS": False,
Richard Levasseur900d8012023-11-30 02:05:05 -0800115 "PRODUCTION_DOMAIN": "readthedocs.org",
Richard Levasseura326b682023-10-30 16:50:57 -0700116 # This is the path to a page's source (after the github user/repo/commit)
Richard Levasseurd7d2ce72024-08-20 17:07:22 -0700117 "conf_py_path": "/docs/",
Richard Levasseur900d8012023-11-30 02:05:05 -0800118 "github_user": "bazelbuild",
119 "github_repo": "rules_python",
Richard Levasseura326b682023-10-30 16:50:57 -0700120 # The git version that was checked out, e.g. the tag or branch name
Richard Levasseur900d8012023-11-30 02:05:05 -0800121 "github_version": os.environ.get("READTHEDOCS_GIT_IDENTIFIER", ""),
Richard Levasseura326b682023-10-30 16:50:57 -0700122 # For local builds, the github link won't work. Disabling it replaces
123 # it with a "view source" link to view the source Sphinx saw, which
124 # is useful for local development.
Richard Levasseur900d8012023-11-30 02:05:05 -0800125 "display_github": os.environ.get("READTHEDOCS") == "True",
126 "commit": os.environ.get("READTHEDOCS_GIT_COMMIT_HASH", "unknown commit"),
Richard Levasseura326b682023-10-30 16:50:57 -0700127 # Used by readthedocs_ext.external_version_warning extension
128 # This is the PR number being built
Richard Levasseur900d8012023-11-30 02:05:05 -0800129 "current_version": os.environ.get("READTHEDOCS_VERSION", ""),
Richard Levasseura326b682023-10-30 16:50:57 -0700130}
131
Richard Levasseur327b4e32023-10-19 11:03:01 -0700132# Keep this in sync with the stardoc templates
133html_permalinks_icon = "ΒΆ"
134
Richard Levasseurede4fd42023-10-17 13:17:34 -0700135# These folders are copied to the documentation's HTML output
136html_static_path = ["_static"]
137
138# These paths are either relative to html_static_path
139# or fully qualified paths (eg. https://...)
140html_css_files = [
141 "css/custom.css",
142]
143
144# -- Options for EPUB output
145epub_show_urls = "footnote"
Richard Levasseur327b4e32023-10-19 11:03:01 -0700146
Richard Levasseur13ce1922024-08-19 11:08:38 -0700147suppress_warnings = [
148 # The autosectionlabel extension turns header titles into referencable
149 # names. Unfortunately, CHANGELOG.md has many duplicate header titles,
150 # which creates lots of warning spam. Just ignore them.
151 "autosectionlabel.*"
152]
Richard Levasseur900d8012023-11-30 02:05:05 -0800153
Richard Levasseur327b4e32023-10-19 11:03:01 -0700154
Richard Levasseur327b4e32023-10-19 11:03:01 -0700155def setup(app):
Richard Levasseur900d8012023-11-30 02:05:05 -0800156 # Pygments says it supports starlark, but it doesn't seem to actually
157 # recognize `starlark` as a name. So just manually map it to python.
158 from sphinx.highlighting import lexer_classes
159
160 app.add_lexer("starlark", lexer_classes["python"])