| 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 | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 19 | # the dependencies of //docs/sphinx: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 | 
 | 30 | ] | 
 | 31 |  | 
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 32 | # Adapted from the template code: | 
 | 33 | # https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl | 
 | 34 | if 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 Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 55 | exclude_patterns = ["_includes/*"] | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 56 | templates_path = ["_templates"] | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 57 | primary_domain = None  # The default is 'py', which we don't make much use of | 
 | 58 | nitpicky = True | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 59 |  | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 60 | # --- Intersphinx configuration | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 61 |  | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 62 | intersphinx_mapping = { | 
 | 63 |     "bazel": ("https://bazel.build/", "bazel_inventory.inv"), | 
 | 64 | } | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 65 |  | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 66 | # --- Extlinks configuration | 
 | 67 | extlinks = { | 
 | 68 |     "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"), | 
 | 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 | # --- MyST configuration | 
 | 72 | # See https://myst-parser.readthedocs.io/en/latest/configuration.html | 
 | 73 | # for more settings | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 74 |  | 
 | 75 | # See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html | 
 | 76 | # for additional extensions. | 
 | 77 | myst_enable_extensions = [ | 
 | 78 |     "fieldlist", | 
 | 79 |     "attrs_block", | 
 | 80 |     "attrs_inline", | 
 | 81 |     "colon_fence", | 
 | 82 |     "deflist", | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 83 |     "substitution", | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 84 | ] | 
 | 85 |  | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 86 | myst_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 | 
 | 94 | html_theme = "sphinx_rtd_theme" | 
 | 95 | html_theme_options = {} | 
 | 96 |  | 
| Richard Levasseur | a326b68 | 2023-10-30 16:50:57 -0700 | [diff] [blame] | 97 | # The html_context settings are part of the jinja context used by the themes. | 
 | 98 | html_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 Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 124 | # Keep this in sync with the stardoc templates | 
 | 125 | html_permalinks_icon = "ΒΆ" | 
 | 126 |  | 
| Richard Levasseur | ede4fd4 | 2023-10-17 13:17:34 -0700 | [diff] [blame] | 127 | # These folders are copied to the documentation's HTML output | 
 | 128 | html_static_path = ["_static"] | 
 | 129 |  | 
 | 130 | # These paths are either relative to html_static_path | 
 | 131 | # or fully qualified paths (eg. https://...) | 
 | 132 | html_css_files = [ | 
 | 133 |     "css/custom.css", | 
 | 134 | ] | 
 | 135 |  | 
 | 136 | # -- Options for EPUB output | 
 | 137 | epub_show_urls = "footnote" | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 138 |  | 
 | 139 | suppress_warnings = ["myst.header", "myst.xref_missing"] | 
 | 140 |  | 
| Richard Levasseur | 327b4e3 | 2023-10-19 11:03:01 -0700 | [diff] [blame] | 141 | def 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']) |