1*60517a1eSAndroid Build Coastguard Worker# Configuration file for the Sphinx documentation builder. 2*60517a1eSAndroid Build Coastguard Worker 3*60517a1eSAndroid Build Coastguard Workerimport os 4*60517a1eSAndroid Build Coastguard Worker 5*60517a1eSAndroid Build Coastguard Worker# -- Project information 6*60517a1eSAndroid Build Coastguard Workerproject = "rules_python" 7*60517a1eSAndroid Build Coastguard Workercopyright = "2023, The Bazel Authors" 8*60517a1eSAndroid Build Coastguard Workerauthor = "Bazel" 9*60517a1eSAndroid Build Coastguard Worker 10*60517a1eSAndroid Build Coastguard Worker# NOTE: These are overriden by -D flags via --//sphinxdocs:extra_defines 11*60517a1eSAndroid Build Coastguard Workerversion = "0.0.0" 12*60517a1eSAndroid Build Coastguard Workerrelease = version 13*60517a1eSAndroid Build Coastguard Worker 14*60517a1eSAndroid Build Coastguard Worker# -- General configuration 15*60517a1eSAndroid Build Coastguard Worker# See https://www.sphinx-doc.org/en/master/usage/configuration.html 16*60517a1eSAndroid Build Coastguard Worker# for more settings 17*60517a1eSAndroid Build Coastguard Worker 18*60517a1eSAndroid Build Coastguard Worker# Any extensions here not built into Sphinx must also be added to 19*60517a1eSAndroid Build Coastguard Worker# the dependencies of //docs:sphinx-builder 20*60517a1eSAndroid Build Coastguard Workerextensions = [ 21*60517a1eSAndroid Build Coastguard Worker "autodoc2", 22*60517a1eSAndroid Build Coastguard Worker "sphinx.ext.autosectionlabel", 23*60517a1eSAndroid Build Coastguard Worker "sphinx.ext.doctest", 24*60517a1eSAndroid Build Coastguard Worker "sphinx.ext.duration", 25*60517a1eSAndroid Build Coastguard Worker "sphinx.ext.extlinks", 26*60517a1eSAndroid Build Coastguard Worker "sphinx.ext.intersphinx", 27*60517a1eSAndroid Build Coastguard Worker "myst_parser", 28*60517a1eSAndroid Build Coastguard Worker "sphinx_rtd_theme", # Necessary to get jquery to make flyout work 29*60517a1eSAndroid Build Coastguard Worker "sphinx_bzl.bzl", 30*60517a1eSAndroid Build Coastguard Worker "sphinx_reredirects", 31*60517a1eSAndroid Build Coastguard Worker] 32*60517a1eSAndroid Build Coastguard Worker 33*60517a1eSAndroid Build Coastguard Workerautodoc2_packages = [ 34*60517a1eSAndroid Build Coastguard Worker "sphinx_bzl", 35*60517a1eSAndroid Build Coastguard Worker "runfiles", 36*60517a1eSAndroid Build Coastguard Worker] 37*60517a1eSAndroid Build Coastguard Worker 38*60517a1eSAndroid Build Coastguard Workerautodoc2_output_dir = "api/py" 39*60517a1eSAndroid Build Coastguard Workerautodoc2_sort_names = True 40*60517a1eSAndroid Build Coastguard Workerautodoc2_class_docstring = "both" 41*60517a1eSAndroid Build Coastguard Workerautodoc2_index_template = """ 42*60517a1eSAndroid Build Coastguard WorkerPython APIs 43*60517a1eSAndroid Build Coastguard Worker==================== 44*60517a1eSAndroid Build Coastguard Worker 45*60517a1eSAndroid Build Coastguard WorkerThis page contains auto-generated API reference documentation [#f1]_. 46*60517a1eSAndroid Build Coastguard Worker 47*60517a1eSAndroid Build Coastguard Worker.. toctree:: 48*60517a1eSAndroid Build Coastguard Worker :titlesonly: 49*60517a1eSAndroid Build Coastguard Worker 50*60517a1eSAndroid Build Coastguard Worker{% for package in top_level %} 51*60517a1eSAndroid Build Coastguard Worker {{ package }} 52*60517a1eSAndroid Build Coastguard Worker{%- endfor %} 53*60517a1eSAndroid Build Coastguard Worker 54*60517a1eSAndroid Build Coastguard Worker.. [#f1] Created with `sphinx-autodoc2 <https://github.com/chrisjsewell/sphinx-autodoc2>`_ 55*60517a1eSAndroid Build Coastguard Worker 56*60517a1eSAndroid Build Coastguard Worker""" 57*60517a1eSAndroid Build Coastguard Worker 58*60517a1eSAndroid Build Coastguard Worker 59*60517a1eSAndroid Build Coastguard Workerautodoc2_docstring_parser_regexes = [ 60*60517a1eSAndroid Build Coastguard Worker (".*", "myst"), 61*60517a1eSAndroid Build Coastguard Worker] 62*60517a1eSAndroid Build Coastguard Worker 63*60517a1eSAndroid Build Coastguard Worker# NOTE: The redirects generation will clobber existing files. 64*60517a1eSAndroid Build Coastguard Workerredirects = { 65*60517a1eSAndroid Build Coastguard Worker "api/tools/precompiler/index": "/api/rules_python/tools/precompiler/index.html", 66*60517a1eSAndroid Build Coastguard Worker "api/python/py_library": "/api/rules_python/python/py_library.html", 67*60517a1eSAndroid Build Coastguard Worker "api/python/py_binary": "/api/rules_python/python/py_binary.html", 68*60517a1eSAndroid Build Coastguard Worker "api/python/py_test": "/api/rules_python/python/py_test.html", 69*60517a1eSAndroid Build Coastguard Worker "api/python/defs": "/api/rules_python/python/defs.html", 70*60517a1eSAndroid Build Coastguard Worker "api/python/index": "/api/rules_python/python/index.html", 71*60517a1eSAndroid Build Coastguard Worker "api/python/py_runtime_info": "/api/rules_python/python/py_runtime_info.html", 72*60517a1eSAndroid Build Coastguard Worker "api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/common/py_library_rule_bazel.html", 73*60517a1eSAndroid Build Coastguard Worker "api/python/private/common/py_test_rule_bazel": "/api/rules_python/python/private/common/py_test_rule_bazel.html", 74*60517a1eSAndroid Build Coastguard Worker "api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/common/py_binary_rule_bazel.html", 75*60517a1eSAndroid Build Coastguard Worker "api/python/private/common/py_runtime_rule": "/api/rules_python/python/private/common/py_runtime_rule.html", 76*60517a1eSAndroid Build Coastguard Worker "api/python/extensions/pip": "/api/rules_python/python/extensions/pip.html", 77*60517a1eSAndroid Build Coastguard Worker "api/python/extensions/python": "/api/rules_python/python/extensions/python.html", 78*60517a1eSAndroid Build Coastguard Worker "api/python/entry_points/py_console_script_binary": "/api/rules_python/python/entry_points/py_console_script_binary.html", 79*60517a1eSAndroid Build Coastguard Worker "api/python/cc/py_cc_toolchain_info": "/api/rules_python/python/cc/py_cc_toolchain_info.html", 80*60517a1eSAndroid Build Coastguard Worker "api/python/cc/index": "/api/rules_python/python/cc/index.html", 81*60517a1eSAndroid Build Coastguard Worker "api/python/py_cc_link_params_info": "/api/rules_python/python/py_cc_link_params_info.html", 82*60517a1eSAndroid Build Coastguard Worker "api/python/runtime_env_toolchains/index": "/api/rules_python/python/runtime_env_toolchains/index.html", 83*60517a1eSAndroid Build Coastguard Worker "api/python/pip": "/api/rules_python/python/pip.html", 84*60517a1eSAndroid Build Coastguard Worker "api/python/config_settings/index": "/api/rules_python/python/config_settings/index.html", 85*60517a1eSAndroid Build Coastguard Worker "api/python/packaging": "/api/rules_python/python/packaging.html", 86*60517a1eSAndroid Build Coastguard Worker "api/python/py_runtime": "/api/rules_python/python/py_runtime.html", 87*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/sphinx": "/api/sphinxdocs/sphinxdocs/sphinx.html", 88*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/sphinx_stardoc": "/api/sphinxdocs/sphinxdocs/sphinx_stardoc.html", 89*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/readthedocs": "/api/sphinxdocs/sphinxdocs/readthedocs.html", 90*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/index": "/api/sphinxdocs/sphinxdocs/index.html", 91*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/private/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/private/sphinx_docs_library.html", 92*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/sphinx_docs_library": "/api/sphinxdocs/sphinxdocs/sphinx_docs_library.html", 93*60517a1eSAndroid Build Coastguard Worker "api/sphinxdocs/inventories/index": "/api/sphinxdocs/sphinxdocs/inventories/index.html", 94*60517a1eSAndroid Build Coastguard Worker} 95*60517a1eSAndroid Build Coastguard Worker 96*60517a1eSAndroid Build Coastguard Worker# Adapted from the template code: 97*60517a1eSAndroid Build Coastguard Worker# https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl 98*60517a1eSAndroid Build Coastguard Workerif os.environ.get("READTHEDOCS") == "True": 99*60517a1eSAndroid Build Coastguard Worker # Must come first because it can interfere with other extensions, according 100*60517a1eSAndroid Build Coastguard Worker # to the original conf.py template comments 101*60517a1eSAndroid Build Coastguard Worker extensions.insert(0, "readthedocs_ext.readthedocs") 102*60517a1eSAndroid Build Coastguard Worker 103*60517a1eSAndroid Build Coastguard Worker if os.environ.get("READTHEDOCS_VERSION_TYPE") == "external": 104*60517a1eSAndroid Build Coastguard Worker # Insert after the main extension 105*60517a1eSAndroid Build Coastguard Worker extensions.insert(1, "readthedocs_ext.external_version_warning") 106*60517a1eSAndroid Build Coastguard Worker readthedocs_vcs_url = ( 107*60517a1eSAndroid Build Coastguard Worker "http://github.com/bazelbuild/rules_python/pull/{}".format( 108*60517a1eSAndroid Build Coastguard Worker os.environ.get("READTHEDOCS_VERSION", "") 109*60517a1eSAndroid Build Coastguard Worker ) 110*60517a1eSAndroid Build Coastguard Worker ) 111*60517a1eSAndroid Build Coastguard Worker # The build id isn't directly available, but it appears to be encoded 112*60517a1eSAndroid Build Coastguard Worker # into the host name, so we can parse it from that. The format appears 113*60517a1eSAndroid Build Coastguard Worker # to be `build-X-project-Y-Z`, where: 114*60517a1eSAndroid Build Coastguard Worker # * X is an integer build id 115*60517a1eSAndroid Build Coastguard Worker # * Y is an integer project id 116*60517a1eSAndroid Build Coastguard Worker # * Z is the project name 117*60517a1eSAndroid Build Coastguard Worker _build_id = os.environ.get("HOSTNAME", "build-0-project-0-rules-python") 118*60517a1eSAndroid Build Coastguard Worker _build_id = _build_id.split("-")[1] 119*60517a1eSAndroid Build Coastguard Worker readthedocs_build_url = ( 120*60517a1eSAndroid Build Coastguard Worker f"https://readthedocs.org/projects/rules-python/builds/{_build_id}" 121*60517a1eSAndroid Build Coastguard Worker ) 122*60517a1eSAndroid Build Coastguard Worker 123*60517a1eSAndroid Build Coastguard Workerexclude_patterns = ["_includes/*"] 124*60517a1eSAndroid Build Coastguard Workertemplates_path = ["_templates"] 125*60517a1eSAndroid Build Coastguard Workerprimary_domain = None # The default is 'py', which we don't make much use of 126*60517a1eSAndroid Build Coastguard Workernitpicky = True 127*60517a1eSAndroid Build Coastguard Worker 128*60517a1eSAndroid Build Coastguard Worker# --- Intersphinx configuration 129*60517a1eSAndroid Build Coastguard Worker 130*60517a1eSAndroid Build Coastguard Workerintersphinx_mapping = { 131*60517a1eSAndroid Build Coastguard Worker "bazel": ("https://bazel.build/", "bazel_inventory.inv"), 132*60517a1eSAndroid Build Coastguard Worker} 133*60517a1eSAndroid Build Coastguard Worker 134*60517a1eSAndroid Build Coastguard Worker# --- Extlinks configuration 135*60517a1eSAndroid Build Coastguard Workerextlinks = { 136*60517a1eSAndroid Build Coastguard Worker "gh-path": (f"https://github.com/bazelbuild/rules_python/tree/main/%s", "%s"), 137*60517a1eSAndroid Build Coastguard Worker} 138*60517a1eSAndroid Build Coastguard Worker 139*60517a1eSAndroid Build Coastguard Worker# --- MyST configuration 140*60517a1eSAndroid Build Coastguard Worker# See https://myst-parser.readthedocs.io/en/latest/configuration.html 141*60517a1eSAndroid Build Coastguard Worker# for more settings 142*60517a1eSAndroid Build Coastguard Worker 143*60517a1eSAndroid Build Coastguard Worker# See https://myst-parser.readthedocs.io/en/latest/syntax/optional.html 144*60517a1eSAndroid Build Coastguard Worker# for additional extensions. 145*60517a1eSAndroid Build Coastguard Workermyst_enable_extensions = [ 146*60517a1eSAndroid Build Coastguard Worker "fieldlist", 147*60517a1eSAndroid Build Coastguard Worker "attrs_block", 148*60517a1eSAndroid Build Coastguard Worker "attrs_inline", 149*60517a1eSAndroid Build Coastguard Worker "colon_fence", 150*60517a1eSAndroid Build Coastguard Worker "deflist", 151*60517a1eSAndroid Build Coastguard Worker "substitution", 152*60517a1eSAndroid Build Coastguard Worker] 153*60517a1eSAndroid Build Coastguard Worker 154*60517a1eSAndroid Build Coastguard Workermyst_substitutions = {} 155*60517a1eSAndroid Build Coastguard Worker 156*60517a1eSAndroid Build Coastguard Worker# --- sphinx_stardoc configuration 157*60517a1eSAndroid Build Coastguard Worker 158*60517a1eSAndroid Build Coastguard Workerbzl_default_repository_name = "@rules_python" 159*60517a1eSAndroid Build Coastguard Worker 160*60517a1eSAndroid Build Coastguard Worker# -- Options for HTML output 161*60517a1eSAndroid Build Coastguard Worker# See https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 162*60517a1eSAndroid Build Coastguard Worker# For additional html settings 163*60517a1eSAndroid Build Coastguard Worker 164*60517a1eSAndroid Build Coastguard Worker# See https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html for 165*60517a1eSAndroid Build Coastguard Worker# them-specific options 166*60517a1eSAndroid Build Coastguard Workerhtml_theme = "sphinx_rtd_theme" 167*60517a1eSAndroid Build Coastguard Workerhtml_theme_options = {} 168*60517a1eSAndroid Build Coastguard Worker 169*60517a1eSAndroid Build Coastguard Worker# The html_context settings are part of the jinja context used by the themes. 170*60517a1eSAndroid Build Coastguard Workerhtml_context = { 171*60517a1eSAndroid Build Coastguard Worker # This controls whether the flyout menu is shown. It is always false 172*60517a1eSAndroid Build Coastguard Worker # because: 173*60517a1eSAndroid Build Coastguard Worker # * For local builds, the flyout menu is empty and doesn't show in the 174*60517a1eSAndroid Build Coastguard Worker # same place as for RTD builds. No point in showing it locally. 175*60517a1eSAndroid Build Coastguard Worker # * For RTD builds, the flyout menu is always automatically injected, 176*60517a1eSAndroid Build Coastguard Worker # so having it be True makes the flyout show up twice. 177*60517a1eSAndroid Build Coastguard Worker "READTHEDOCS": False, 178*60517a1eSAndroid Build Coastguard Worker "PRODUCTION_DOMAIN": "readthedocs.org", 179*60517a1eSAndroid Build Coastguard Worker # This is the path to a page's source (after the github user/repo/commit) 180*60517a1eSAndroid Build Coastguard Worker "conf_py_path": "/docs/", 181*60517a1eSAndroid Build Coastguard Worker "github_user": "bazelbuild", 182*60517a1eSAndroid Build Coastguard Worker "github_repo": "rules_python", 183*60517a1eSAndroid Build Coastguard Worker # The git version that was checked out, e.g. the tag or branch name 184*60517a1eSAndroid Build Coastguard Worker "github_version": os.environ.get("READTHEDOCS_GIT_IDENTIFIER", ""), 185*60517a1eSAndroid Build Coastguard Worker # For local builds, the github link won't work. Disabling it replaces 186*60517a1eSAndroid Build Coastguard Worker # it with a "view source" link to view the source Sphinx saw, which 187*60517a1eSAndroid Build Coastguard Worker # is useful for local development. 188*60517a1eSAndroid Build Coastguard Worker "display_github": os.environ.get("READTHEDOCS") == "True", 189*60517a1eSAndroid Build Coastguard Worker "commit": os.environ.get("READTHEDOCS_GIT_COMMIT_HASH", "unknown commit"), 190*60517a1eSAndroid Build Coastguard Worker # Used by readthedocs_ext.external_version_warning extension 191*60517a1eSAndroid Build Coastguard Worker # This is the PR number being built 192*60517a1eSAndroid Build Coastguard Worker "current_version": os.environ.get("READTHEDOCS_VERSION", ""), 193*60517a1eSAndroid Build Coastguard Worker} 194*60517a1eSAndroid Build Coastguard Worker 195*60517a1eSAndroid Build Coastguard Worker# Keep this in sync with the stardoc templates 196*60517a1eSAndroid Build Coastguard Workerhtml_permalinks_icon = "¶" 197*60517a1eSAndroid Build Coastguard Worker 198*60517a1eSAndroid Build Coastguard Worker# These folders are copied to the documentation's HTML output 199*60517a1eSAndroid Build Coastguard Workerhtml_static_path = ["_static"] 200*60517a1eSAndroid Build Coastguard Worker 201*60517a1eSAndroid Build Coastguard Worker# These paths are either relative to html_static_path 202*60517a1eSAndroid Build Coastguard Worker# or fully qualified paths (eg. https://...) 203*60517a1eSAndroid Build Coastguard Workerhtml_css_files = [ 204*60517a1eSAndroid Build Coastguard Worker "css/custom.css", 205*60517a1eSAndroid Build Coastguard Worker] 206*60517a1eSAndroid Build Coastguard Worker 207*60517a1eSAndroid Build Coastguard Worker# -- Options for EPUB output 208*60517a1eSAndroid Build Coastguard Workerepub_show_urls = "footnote" 209*60517a1eSAndroid Build Coastguard Worker 210*60517a1eSAndroid Build Coastguard Workersuppress_warnings = [ 211*60517a1eSAndroid Build Coastguard Worker # The autosectionlabel extension turns header titles into referencable 212*60517a1eSAndroid Build Coastguard Worker # names. Unfortunately, CHANGELOG.md has many duplicate header titles, 213*60517a1eSAndroid Build Coastguard Worker # which creates lots of warning spam. Just ignore them. 214*60517a1eSAndroid Build Coastguard Worker "autosectionlabel.*" 215*60517a1eSAndroid Build Coastguard Worker] 216*60517a1eSAndroid Build Coastguard Worker 217*60517a1eSAndroid Build Coastguard Worker 218*60517a1eSAndroid Build Coastguard Workerdef setup(app): 219*60517a1eSAndroid Build Coastguard Worker # Pygments says it supports starlark, but it doesn't seem to actually 220*60517a1eSAndroid Build Coastguard Worker # recognize `starlark` as a name. So just manually map it to python. 221*60517a1eSAndroid Build Coastguard Worker from sphinx.highlighting import lexer_classes 222*60517a1eSAndroid Build Coastguard Worker 223*60517a1eSAndroid Build Coastguard Worker app.add_lexer("starlark", lexer_classes["python"]) 224