| 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 | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 21 | "sphinx.ext.autodoc", |
| 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.autosummary", |
| 24 | "sphinx.ext.doctest", |
| 25 | "sphinx.ext.duration", |
| 26 | "sphinx.ext.extlinks", |
| 27 | "sphinx.ext.intersphinx", |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 28 | "myst_parser", |
| 29 | "sphinx_rtd_theme", # Necessary to get jquery to make flyout work |
| Richard Levasseur | 975edfe | 2024-05-24 21:52:43 -0700 | [diff] [blame] | 30 | "sphinx_bzl.bzl", |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 31 | ] |
| 32 | |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 33 | # Adapted from the template code: |
| 34 | # https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl |
| 35 | if os.environ.get("READTHEDOCS") == "True": |
| Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 36 | # 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 Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 39 | |
| Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 40 | 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 Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 59 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 60 | exclude_patterns = ["_includes/*"] |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 61 | templates_path = ["_templates"] |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 62 | primary_domain = None # The default is 'py', which we don't make much use of |
| 63 | nitpicky = True |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 64 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 65 | # --- Intersphinx configuration |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 66 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 67 | intersphinx_mapping = { |
| 68 | "bazel": ("https://bazel.build/", "bazel_inventory.inv"), |
| 69 | } |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 70 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 71 | # --- Extlinks configuration |
| 72 | extlinks = { |
| 73 | "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"), |
| 74 | } |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 75 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 76 | # --- MyST configuration |
| 77 | # See https://myst-parser.readthedocs.io/en/latest/configuration.html |
| 78 | # for more settings |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 79 | |
| 80 | # See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html |
| 81 | # for additional extensions. |
| 82 | myst_enable_extensions = [ |
| 83 | "fieldlist", |
| 84 | "attrs_block", |
| 85 | "attrs_inline", |
| 86 | "colon_fence", |
| 87 | "deflist", |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 88 | "substitution", |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 89 | ] |
| 90 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 91 | myst_substitutions = {} |
| 92 | |
| Richard Levasseur | 6ca2f58 | 2024-05-23 20:44:47 -0700 | [diff] [blame] | 93 | # --- sphinx_stardoc configuration |
| 94 | |
| 95 | bzl_default_repository_name = "@rules_python" |
| 96 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 97 | # -- 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 |
| 103 | html_theme = "sphinx_rtd_theme" |
| 104 | html_theme_options = {} |
| 105 | |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 106 | # The html_context settings are part of the jinja context used by the themes. |
| 107 | html_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 Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 115 | "PRODUCTION_DOMAIN": "readthedocs.org", |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 116 | # 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^] | 117 | "conf_py_path": "/docs/", |
| Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 118 | "github_user": "bazelbuild", |
| 119 | "github_repo": "rules_python", |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 120 | # 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] | 121 | "github_version": os.environ.get("READTHEDOCS_GIT_IDENTIFIER", ""), |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 122 | # 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 Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 125 | "display_github": os.environ.get("READTHEDOCS") == "True", |
| 126 | "commit": os.environ.get("READTHEDOCS_GIT_COMMIT_HASH", "unknown commit"), |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 127 | # Used by readthedocs_ext.external_version_warning extension |
| 128 | # This is the PR number being built |
| Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 129 | "current_version": os.environ.get("READTHEDOCS_VERSION", ""), |
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 132 | # Keep this in sync with the stardoc templates |
| 133 | html_permalinks_icon = "ΒΆ" |
| 134 | |
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 135 | # These folders are copied to the documentation's HTML output |
| 136 | html_static_path = ["_static"] |
| 137 | |
| 138 | # These paths are either relative to html_static_path |
| 139 | # or fully qualified paths (eg. https://...) |
| 140 | html_css_files = [ |
| 141 | "css/custom.css", |
| 142 | ] |
| 143 | |
| 144 | # -- Options for EPUB output |
| 145 | epub_show_urls = "footnote" |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 146 | |
| Richard Levasseur | 13ce192 | 2024-08-19 11:08:38 -0700 | [diff] [blame] | 147 | suppress_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 Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 153 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 154 | |
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 155 | def setup(app): |
| Richard Levasseur | 900d801 | 2023-11-30 02:05:05 -0800 | [diff] [blame] | 156 | # 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"]) |