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