Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 1 | # Configuration file for the Sphinx documentation builder. |
| 2 | |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 3 | import os |
| 4 | |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 5 | # -- Project information |
| 6 | project = "rules_python" |
| 7 | copyright = "2023, The Bazel Authors" |
| 8 | author = "Bazel" |
| 9 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 10 | # NOTE: These are overriden by -D flags via --//sphinxdocs:extra_defines |
| 11 | version = "0.0.0" |
| 12 | release = version |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 13 | |
| 14 | # -- General configuration |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 15 | # See https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 16 | # for more settings |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 17 | |
| 18 | # Any extensions here not built into Sphinx must also be added to |
Richard Levasseur | d7d2ce7 | 2024-08-20 17:07:22 -0700 | [diff] [blame] | 19 | # the dependencies of //docs:sphinx-builder |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 20 | extensions = [ |
Richard Levasseur | 2f46873 | 2024-08-25 19:10:30 -0700 | [diff] [blame] | 21 | "autodoc2", |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 22 | "sphinx.ext.autosectionlabel", |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 23 | "sphinx.ext.doctest", |
| 24 | "sphinx.ext.duration", |
| 25 | "sphinx.ext.extlinks", |
| 26 | "sphinx.ext.intersphinx", |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 27 | "myst_parser", |
| 28 | "sphinx_rtd_theme", # Necessary to get jquery to make flyout work |
Richard Levasseur | 975edfe | 2024-05-24 21:52:43 -0700 | [diff] [blame] | 29 | "sphinx_bzl.bzl", |
Richard Levasseur | 2f46873 | 2024-08-25 19:10:30 -0700 | [diff] [blame] | 30 | "sphinx_reredirects", |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 31 | ] |
| 32 | |
Richard Levasseur | 2f46873 | 2024-08-25 19:10:30 -0700 | [diff] [blame] | 33 | autodoc2_packages = [ |
| 34 | "sphinx_bzl", |
| 35 | "runfiles", |
| 36 | ] |
| 37 | |
| 38 | autodoc2_output_dir = "api/py" |
| 39 | autodoc2_sort_names = True |
| 40 | autodoc2_class_docstring = "both" |
| 41 | autodoc2_index_template = """ |
| 42 | Python APIs |
| 43 | ==================== |
| 44 | |
| 45 | This 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 | |
| 59 | autodoc2_docstring_parser_regexes = [ |
| 60 | (".*", "myst"), |
| 61 | ] |
Richard Levasseur | dd5db65 | 2024-10-15 16:33:37 -0700 | [diff] [blame] | 62 | |
Richard Levasseur | 2f46873 | 2024-08-25 19:10:30 -0700 | [diff] [blame] | 63 | # NOTE: The redirects generation will clobber existing files. |
| 64 | redirects = { |
| 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 Levasseur | 7c5e7cf | 2024-10-29 20:32:35 -0700 | [diff] [blame] | 72 | "api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/py_library_rule.html", |
Richard Levasseur | dd5db65 | 2024-10-15 16:33:37 -0700 | [diff] [blame] | 73 | "api/python/private/common/py_test_rule_bazel": "/api/rules_python/python/private/py_test_rule_bazel.html", |
Richard Levasseur | 7c5e7cf | 2024-10-29 20:32:35 -0700 | [diff] [blame] | 74 | "api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/py_binary_rule.html", |
Richard Levasseur | dd5db65 | 2024-10-15 16:33:37 -0700 | [diff] [blame] | 75 | "api/python/private/common/py_runtime_rule": "/api/rules_python/python/private/py_runtime_rule.html", |
Richard Levasseur | 2f46873 | 2024-08-25 19:10:30 -0700 | [diff] [blame] | 76 | "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 Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 96 | # Adapted from the template code: |
| 97 | # https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl |
| 98 | if os.environ.get("READTHEDOCS") == "True": |
Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 99 | # 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 Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 102 | |
Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 103 | 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 Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 122 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 123 | exclude_patterns = ["_includes/*"] |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 124 | templates_path = ["_templates"] |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 125 | primary_domain = None # The default is 'py', which we don't make much use of |
| 126 | nitpicky = True |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 127 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 128 | # --- Intersphinx configuration |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 129 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 130 | intersphinx_mapping = { |
| 131 | "bazel": ("https://bazel.build/", "bazel_inventory.inv"), |
| 132 | } |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 133 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 134 | # --- Extlinks configuration |
| 135 | extlinks = { |
| 136 | "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"), |
| 137 | } |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 138 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 139 | # --- MyST configuration |
| 140 | # See https://myst-parser.readthedocs.io/en/latest/configuration.html |
| 141 | # for more settings |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 142 | |
| 143 | # See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html |
| 144 | # for additional extensions. |
| 145 | myst_enable_extensions = [ |
| 146 | "fieldlist", |
| 147 | "attrs_block", |
| 148 | "attrs_inline", |
| 149 | "colon_fence", |
| 150 | "deflist", |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 151 | "substitution", |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 152 | ] |
| 153 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 154 | myst_substitutions = {} |
| 155 | |
Richard Levasseur | 6ca2f58 | 2024-05-23 20:44:47 -0700 | [diff] [blame] | 156 | # --- sphinx_stardoc configuration |
| 157 | |
| 158 | bzl_default_repository_name = "@rules_python" |
| 159 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 160 | # -- 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 |
| 166 | html_theme = "sphinx_rtd_theme" |
| 167 | html_theme_options = {} |
| 168 | |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 169 | # The html_context settings are part of the jinja context used by the themes. |
| 170 | html_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 Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 178 | "PRODUCTION_DOMAIN": "readthedocs.org", |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 179 | # This is the path to a page's source (after the github user/repo/commit) |
Richard Levasseur | d7d2ce7 | 2024-08-20 17:07:22 -0700 | [diff] [blame] | 180 | "conf_py_path": "/docs/", |
Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 181 | "github_user": "bazelbuild", |
| 182 | "github_repo": "rules_python", |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 183 | # The git version that was checked out, e.g. the tag or branch name |
Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 184 | "github_version": os.environ.get("READTHEDOCS_GIT_IDENTIFIER", ""), |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 185 | # 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 Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 188 | "display_github": os.environ.get("READTHEDOCS") == "True", |
| 189 | "commit": os.environ.get("READTHEDOCS_GIT_COMMIT_HASH", "unknown commit"), |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 190 | # Used by readthedocs_ext.external_version_warning extension |
| 191 | # This is the PR number being built |
Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 192 | "current_version": os.environ.get("READTHEDOCS_VERSION", ""), |
Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 195 | # Keep this in sync with the stardoc templates |
| 196 | html_permalinks_icon = "ΒΆ" |
| 197 | |
Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 198 | # These folders are copied to the documentation's HTML output |
| 199 | html_static_path = ["_static"] |
| 200 | |
| 201 | # These paths are either relative to html_static_path |
| 202 | # or fully qualified paths (eg. https://...) |
| 203 | html_css_files = [ |
| 204 | "css/custom.css", |
| 205 | ] |
| 206 | |
| 207 | # -- Options for EPUB output |
| 208 | epub_show_urls = "footnote" |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 209 | |
Richard Levasseur | 13ce192 | 2024-08-19 11:08:38 -0700 | [diff] [blame] | 210 | suppress_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 Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 216 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 217 | |
Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 218 | def setup(app): |
Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 219 | # 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"]) |