1# Copyright 2023 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 16load("@dev_pip//:requirements.bzl", "requirement") 17load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility 18load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility 19load("//python/uv/private:lock.bzl", "lock") # buildifier: disable=bzl-visibility 20load("//sphinxdocs:readthedocs.bzl", "readthedocs_install") 21load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs") 22load("//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 23load("//sphinxdocs:sphinx_stardoc.bzl", "sphinx_stardoc", "sphinx_stardocs") 24 25package(default_visibility = ["//:__subpackages__"]) 26 27licenses(["notice"]) # Apache 2.0 28 29# We only build for Linux and Mac because: 30# 1. The actual doc process only runs on Linux 31# 2. Mac is a common development platform, and is close enough to Linux 32# it's feasible to make work. 33# Making CI happy under Windows is too much of a headache, though, so we don't 34# bother with that. 35_TARGET_COMPATIBLE_WITH = select({ 36 "@platforms//os:linux": [], 37 "@platforms//os:macos": [], 38 "//conditions:default": ["@platforms//:incompatible"], 39}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"] 40 41# See README.md for instructions. Short version: 42# * `bazel run //docs:docs.serve` in a separate terminal 43# * `ibazel build //docs:docs` to automatically rebuild docs 44sphinx_docs( 45 name = "docs", 46 srcs = glob( 47 include = [ 48 "*.md", 49 "**/*.md", 50 "_static/**", 51 "_includes/**", 52 ], 53 exclude = [ 54 "README.md", 55 "_*", 56 "*.inv*", 57 ], 58 ), 59 config = "conf.py", 60 formats = [ 61 "html", 62 ], 63 renamed_srcs = { 64 "//:CHANGELOG.md": "changelog.md", 65 "//:CONTRIBUTING.md": "contributing.md", 66 "//sphinxdocs/inventories:bazel_inventory": "bazel_inventory.inv", 67 }, 68 sphinx = ":sphinx-build", 69 strip_prefix = package_name() + "/", 70 tags = ["docs"], 71 target_compatible_with = _TARGET_COMPATIBLE_WITH, 72 deps = [ 73 ":bzl_api_docs", 74 ":py_api_srcs", 75 ":py_runtime_pair", 76 "//sphinxdocs/docs:docs_lib", 77 ], 78) 79 80sphinx_stardocs( 81 name = "bzl_api_docs", 82 srcs = [ 83 "//python:defs_bzl", 84 "//python:packaging_bzl", 85 "//python:pip_bzl", 86 "//python:py_binary_bzl", 87 "//python:py_cc_link_params_info_bzl", 88 "//python:py_exec_tools_info_bzl", 89 "//python:py_exec_tools_toolchain_bzl", 90 "//python:py_executable_info_bzl", 91 "//python:py_library_bzl", 92 "//python:py_runtime_bzl", 93 "//python:py_runtime_info_bzl", 94 "//python:py_test_bzl", 95 "//python:repositories_bzl", 96 "//python/cc:py_cc_toolchain_bzl", 97 "//python/cc:py_cc_toolchain_info_bzl", 98 "//python/entry_points:py_console_script_binary_bzl", 99 "//python/private:py_cc_toolchain_rule_bzl", 100 "//python/private/common:py_binary_rule_bazel_bzl", 101 "//python/private/common:py_library_rule_bazel_bzl", 102 "//python/private/common:py_runtime_rule_bzl", 103 "//python/private/common:py_test_rule_bazel_bzl", 104 ] + ([ 105 # Bazel 6 + Stardoc isn't able to parse something about the python bzlmod extension 106 "//python/extensions:python_bzl", 107 ] if IS_BAZEL_7_OR_HIGHER else []) + ([ 108 # This depends on @pythons_hub, which is only created under bzlmod, 109 "//python/extensions:pip_bzl", 110 ] if IS_BAZEL_7_OR_HIGHER and BZLMOD_ENABLED else []), 111 prefix = "api/rules_python/", 112 tags = ["docs"], 113 target_compatible_with = _TARGET_COMPATIBLE_WITH, 114) 115 116sphinx_stardoc( 117 name = "py_runtime_pair", 118 src = "//python/private:py_runtime_pair_rule_bzl", 119 prefix = "api/rules_python/", 120 tags = ["docs"], 121 target_compatible_with = _TARGET_COMPATIBLE_WITH, 122) 123 124sphinx_docs_library( 125 name = "py_api_srcs", 126 srcs = [ 127 "//python/runfiles", 128 ], 129 strip_prefix = "python/", 130) 131 132readthedocs_install( 133 name = "readthedocs_install", 134 docs = [":docs"], 135 target_compatible_with = _TARGET_COMPATIBLE_WITH, 136) 137 138sphinx_build_binary( 139 name = "sphinx-build", 140 target_compatible_with = _TARGET_COMPATIBLE_WITH, 141 deps = [ 142 requirement("sphinx"), 143 requirement("sphinx_rtd_theme"), 144 requirement("myst_parser"), 145 requirement("readthedocs_sphinx_ext"), 146 requirement("typing_extensions"), 147 requirement("sphinx_autodoc2"), 148 requirement("sphinx_reredirects"), 149 "//sphinxdocs/src/sphinx_bzl", 150 ], 151) 152 153# Run bazel run //docs:requirements.update 154lock( 155 name = "requirements", 156 srcs = ["pyproject.toml"], 157 out = "requirements.txt", 158 upgrade = True, 159) 160 161# Temporary compatibility aliases for some other projects depending on the old 162# bzl_library targets. 163alias( 164 name = "defs", 165 actual = "//python:defs_bzl", 166 deprecation = "Use //python:defs_bzl instead; targets under //docs are internal.", 167 visibility = ["//visibility:public"], 168) 169 170alias( 171 name = "bazel_repo_tools", 172 actual = "//python/private:bazel_tools_bzl", 173 deprecation = "Use @bazel_tools//tools:bzl_srcs instead; targets under //docs are internal.", 174 visibility = ["//visibility:public"], 175) 176 177bzl_library( 178 name = "pip_install_bzl", 179 deprecation = "Use //python:pip_bzl or //python/pip_install:pip_repository_bzl instead; " + 180 "targets under //docs are internal.", 181 visibility = ["//visibility:public"], 182 deps = [ 183 "//python:pip_bzl", 184 "//python/pip_install:pip_repository_bzl", 185 ], 186) 187 188alias( 189 name = "requirements_parser_bzl", 190 actual = "//python/pip_install:pip_repository_bzl", 191 deprecation = "Use //python/pip_install:pip_repository_bzl instead; Both the requirements " + 192 "parser and targets under //docs are internal", 193 visibility = ["//visibility:public"], 194) 195