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"""Starlark rules for integrating Sphinx and Readthedocs.""" 15 16load("//python:py_binary.bzl", "py_binary") 17load("//python/private:util.bzl", "add_tag") # buildifier: disable=bzl-visibility 18 19_INSTALL_MAIN_SRC = Label("//sphinxdocs/private:readthedocs_install.py") 20 21def readthedocs_install(name, docs, **kwargs): 22 """Run a program to copy Sphinx doc files into readthedocs output directories. 23 24 This is intended to be run using `bazel run` during the readthedocs 25 build process when the build process is overridden. See 26 https://docs.readthedocs.io/en/stable/build-customization.html#override-the-build-process 27 for more information. 28 29 Args: 30 name: {type}`Name` name of the installer 31 docs: {type}`list[label]` list of targets that generate directories to copy 32 into the directories readthedocs expects final output in. This 33 is typically a single {obj}`sphinx_stardocs` target. 34 **kwargs: {type}`dict` additional kwargs to pass onto the installer 35 """ 36 add_tag(kwargs, "@rules_python//sphinxdocs:readthedocs_install") 37 py_binary( 38 name = name, 39 srcs = [_INSTALL_MAIN_SRC], 40 main = _INSTALL_MAIN_SRC, 41 data = docs, 42 args = [ 43 "$(rlocationpaths {})".format(d) 44 for d in docs 45 ], 46 deps = [Label("//python/runfiles")], 47 **kwargs 48 ) 49