blob: cfc819f61064ad3ae1932d165178be26e0273210 [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 Levasseur327b4e32023-10-19 11:03:01 -070019# the dependencies of //docs/sphinx: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
30]
31
Richard Levasseura326b682023-10-30 16:50:57 -070032# Adapted from the template code:
33# https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
34if os.environ.get("READTHEDOCS") == "True":
35 # Must come first because it can interfere with other extensions, according
36 # to the original conf.py template comments
37 extensions.insert(0, "readthedocs_ext.readthedocs")
38
39 if os.environ.get("READTHEDOCS_VERSION_TYPE") == "external":
40 # Insert after the main extension
41 extensions.insert(1, "readthedocs_ext.external_version_warning")
42 readthedocs_vcs_url = "http://github.com/bazelbuild/rules_python/pull/{}".format(
43 os.environ.get("READTHEDOCS_VERSION", "")
44 )
45 # The build id isn't directly available, but it appears to be encoded
46 # into the host name, so we can parse it from that. The format appears
47 # to be `build-X-project-Y-Z`, where:
48 # * X is an integer build id
49 # * Y is an integer project id
50 # * Z is the project name
51 _build_id = os.environ.get("HOSTNAME", "build-0-project-0-rules-python")
52 _build_id = _build_id.split("-")[1]
53 readthedocs_build_url = f"https://readthedocs.org/projects/rules-python/builds/{_build_id}"
54
Richard Levasseur327b4e32023-10-19 11:03:01 -070055exclude_patterns = ["_includes/*"]
Richard Levasseurede4fd42023-10-17 13:17:34 -070056templates_path = ["_templates"]
Richard Levasseur327b4e32023-10-19 11:03:01 -070057primary_domain = None # The default is 'py', which we don't make much use of
58nitpicky = True
Richard Levasseurede4fd42023-10-17 13:17:34 -070059
Richard Levasseur327b4e32023-10-19 11:03:01 -070060# --- Intersphinx configuration
Richard Levasseurede4fd42023-10-17 13:17:34 -070061
Richard Levasseur327b4e32023-10-19 11:03:01 -070062intersphinx_mapping = {
63 "bazel": ("https://bazel.build/", "bazel_inventory.inv"),
64}
Richard Levasseurede4fd42023-10-17 13:17:34 -070065
Richard Levasseur327b4e32023-10-19 11:03:01 -070066# --- Extlinks configuration
67extlinks = {
68 "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"),
69}
Richard Levasseurede4fd42023-10-17 13:17:34 -070070
Richard Levasseur327b4e32023-10-19 11:03:01 -070071# --- MyST configuration
72# See https://myst-parser.readthedocs.io/en/latest/configuration.html
73# for more settings
Richard Levasseurede4fd42023-10-17 13:17:34 -070074
75# See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html
76# for additional extensions.
77myst_enable_extensions = [
78 "fieldlist",
79 "attrs_block",
80 "attrs_inline",
81 "colon_fence",
82 "deflist",
Richard Levasseur327b4e32023-10-19 11:03:01 -070083 "substitution",
Richard Levasseurede4fd42023-10-17 13:17:34 -070084]
85
Richard Levasseur327b4e32023-10-19 11:03:01 -070086myst_substitutions = {}
87
88# -- Options for HTML output
89# See https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
90# For additional html settings
91
92# See https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html for
93# them-specific options
94html_theme = "sphinx_rtd_theme"
95html_theme_options = {}
96
Richard Levasseura326b682023-10-30 16:50:57 -070097# The html_context settings are part of the jinja context used by the themes.
98html_context = {
99 # This controls whether the flyout menu is shown. It is always false
100 # because:
101 # * For local builds, the flyout menu is empty and doesn't show in the
102 # same place as for RTD builds. No point in showing it locally.
103 # * For RTD builds, the flyout menu is always automatically injected,
104 # so having it be True makes the flyout show up twice.
105 "READTHEDOCS": False,
106 'PRODUCTION_DOMAIN': "readthedocs.org",
107 # This is the path to a page's source (after the github user/repo/commit)
108 "conf_py_path": "/docs/sphinx/",
109 'github_user': 'bazelbuild',
110 'github_repo': 'rules_python',
111 # The git version that was checked out, e.g. the tag or branch name
112 'github_version': os.environ.get("READTHEDOCS_GIT_IDENTIFIER", ""),
113 # For local builds, the github link won't work. Disabling it replaces
114 # it with a "view source" link to view the source Sphinx saw, which
115 # is useful for local development.
116 'display_github': os.environ.get("READTHEDOCS") == "True",
117 'commit': os.environ.get("READTHEDOCS_GIT_COMMIT_HASH", "unknown commit"),
118
119 # Used by readthedocs_ext.external_version_warning extension
120 # This is the PR number being built
121 'current_version': os.environ.get("READTHEDOCS_VERSION", ""),
122}
123
Richard Levasseur327b4e32023-10-19 11:03:01 -0700124# Keep this in sync with the stardoc templates
125html_permalinks_icon = "ΒΆ"
126
Richard Levasseurede4fd42023-10-17 13:17:34 -0700127# These folders are copied to the documentation's HTML output
128html_static_path = ["_static"]
129
130# These paths are either relative to html_static_path
131# or fully qualified paths (eg. https://...)
132html_css_files = [
133 "css/custom.css",
134]
135
136# -- Options for EPUB output
137epub_show_urls = "footnote"
Richard Levasseur327b4e32023-10-19 11:03:01 -0700138
139suppress_warnings = ["myst.header", "myst.xref_missing"]
140
Richard Levasseur327b4e32023-10-19 11:03:01 -0700141def setup(app):
142 # Pygments says it supports starlark, but it doesn't seem to actually
143 # recognize `starlark` as a name. So just manually map it to python.
144 from sphinx.highlighting import lexer_classes
145 app.add_lexer('starlark', lexer_classes['python'])