Skip to content

Commit 847c03f

Browse files
authored
docs: include changelog and contributing page in generated docs. (bazel-contrib#1617)
This better unifies where docs can be viewed. Also deletes some mentions of having to generate the docs manually.
1 parent 2b5b896 commit 847c03f

5 files changed

Lines changed: 49 additions & 16 deletions

File tree

BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ exports_files([
2424
"version.bzl",
2525
])
2626

27+
exports_files(
28+
glob(["*.md"]),
29+
visibility = ["//docs:__subpackages__"],
30+
)
31+
2732
filegroup(
2833
name = "distribution",
2934
srcs = [

CONTRIBUTING.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ and setup. Subsequent runs will be faster, but there are many tests, and some of
6565
them are slow. If you're working on a particular area of code, you can run just
6666
the tests in those directories instead, which can speed up your edit-run cycle.
6767

68-
Note that there are tests to verify generated documentation is correct -- if
69-
you're modifying the signature of a public function, these tests will likely
70-
fail and you'll need to [regenerate the api docs](#documentation).
71-
7268
## Formatting
7369

7470
Starlark files should be formatted by
@@ -150,17 +146,6 @@ For the full details of types, see
150146
Some checked-in files are generated and need to be updated when a new PR is
151147
merged.
152148

153-
### Documentation
154-
155-
To regenerate the content under the `docs/` directory, run this command:
156-
157-
```shell
158-
bazel run //docs:update
159-
```
160-
161-
This needs to be done whenever the docstrings in the corresponding .bzl files
162-
are changed; a test failure will remind you to run this command when needed.
163-
164149
## Core rules
165150

166151
The bulk of this repo is owned and maintained by the Bazel Python community.

docs/sphinx/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ sphinx_docs(
5555
formats = [
5656
"html",
5757
],
58+
renamed_srcs = {
59+
"//:CHANGELOG.md": "changelog.md",
60+
"//:CONTRIBUTING.md": "contributing.md",
61+
},
5862
sphinx = ":sphinx-build",
5963
strip_prefix = package_name() + "/",
6064
tags = ["docs"],

docs/sphinx/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pypi-dependencies
6060
pip
6161
coverage
6262
gazelle
63+
Contributing <contributing>
64+
Changelog <changelog>
6365
api/index
6466
glossary
6567
genindex

sphinxdocs/private/sphinx.bzl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ def sphinx_build_binary(name, py_binary_rule = py_binary, **kwargs):
4545
**kwargs
4646
)
4747

48-
def sphinx_docs(name, *, srcs = [], sphinx, config, formats, strip_prefix = "", extra_opts = [], **kwargs):
48+
def sphinx_docs(
49+
name,
50+
*,
51+
srcs = [],
52+
renamed_srcs = {},
53+
sphinx,
54+
config,
55+
formats,
56+
strip_prefix = "",
57+
extra_opts = [],
58+
**kwargs):
4959
"""Generate docs using Sphinx.
5060
5161
This generates three public targets:
@@ -62,6 +72,9 @@ def sphinx_docs(name, *, srcs = [], sphinx, config, formats, strip_prefix = "",
6272
Args:
6373
name: (str) name of the docs rule.
6474
srcs: (label list) The source files for Sphinx to process.
75+
renamed_srcs: (label_keyed_string_dict) Doc source files for Sphinx that
76+
are renamed. This is typically used for files elsewhere, such as top
77+
level files in the repo.
6578
sphinx: (label) the Sphinx tool to use for building
6679
documentation. Because Sphinx supports various plugins, you must
6780
construct your own binary with the necessary dependencies. The
@@ -83,6 +96,7 @@ def sphinx_docs(name, *, srcs = [], sphinx, config, formats, strip_prefix = "",
8396
_sphinx_docs(
8497
name = name,
8598
srcs = srcs,
99+
renamed_srcs = renamed_srcs,
86100
sphinx = sphinx,
87101
config = config,
88102
formats = formats,
@@ -143,6 +157,12 @@ _sphinx_docs = rule(
143157
"other options, but before the source/output args.",
144158
),
145159
"formats": attr.string_list(doc = "Output formats for Sphinx to create."),
160+
"renamed_srcs": attr.label_keyed_string_dict(
161+
allow_files = True,
162+
doc = "Doc source files for Sphinx that are renamed. This is " +
163+
"typically used for files elsewhere, such as top level " +
164+
"files in the repo.",
165+
),
146166
"sphinx": attr.label(
147167
executable = True,
148168
cfg = "exec",
@@ -189,6 +209,23 @@ def _create_sphinx_source_tree(ctx):
189209
for orig_file in ctx.files.srcs:
190210
_symlink_source(orig_file)
191211

212+
for src_target, dest in ctx.attr.renamed_srcs.items():
213+
src_files = src_target.files.to_list()
214+
if len(src_files) != 1:
215+
fail("A single file must be specified to be renamed. Target {} " +
216+
"generate {} files: {}".format(
217+
src_target,
218+
len(src_files),
219+
src_files,
220+
))
221+
sphinx_src = ctx.actions.declare_file(paths.join(source_prefix, dest))
222+
ctx.actions.symlink(
223+
output = sphinx_src,
224+
target_file = src_files[0],
225+
progress_message = "Symlinking (renamed) Sphinx source %{input} to %{output}",
226+
)
227+
sphinx_source_files.append(sphinx_src)
228+
192229
return sphinx_source_dir_path, source_conf_file, sphinx_source_files
193230

194231
def _run_sphinx(ctx, format, source_path, inputs, output_prefix):

0 commit comments

Comments
 (0)