Skip to content

Commit 283e565

Browse files
committed
enable worker by default so its used when available
1 parent 78651ea commit 283e565

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

docs/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ sphinx_docs(
7070
strip_prefix = package_name() + "/",
7171
tags = ["docs"],
7272
target_compatible_with = _TARGET_COMPATIBLE_WITH,
73-
use_persistent_workers = True,
7473
deps = [
7574
":bzl_api_docs",
7675
":py_api_srcs",

sphinxdocs/docs/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ documentation. It comes with:
1111
While it is primarily oriented towards docgen for Starlark code, the core of it
1212
is agnostic as to what is being documented.
1313

14+
### Optimization
15+
16+
Normally, Sphinx keeps various cache files to improve incremental building.
17+
Unfortunately, programs performing their own caching don't interact well
18+
with Bazel's model of precisely declaring and strictly enforcing what are
19+
inputs, what are outputs, and what files are available when running a program.
20+
The net effect is programs don't have a prior invocation's cache files
21+
available.
22+
23+
There are two mechanisms available to make some cache available to Sphinx under
24+
Bazel:
25+
26+
* Disable sandboxing, which allows some files from prior invocations to be
27+
visible to subsequent invocations. This can be done multiple ways:
28+
* Set `tags = ["no-sandbox"]` on the `sphinx_docs` target
29+
* `--modify_execution_info=SphinxBuildDocs=+no-sandbox` (Bazel flag)
30+
* `--strategy=SphinxBuildDocs=local` (Bazel flag)
31+
* Use persistent workers (enabled by default) by setting
32+
`allow_persistent_workers=True` on the `sphinx_docs` target. Note that other
33+
Bazel flags can disable using workers even if an action supports it. Setting
34+
`--strategy=SphinxBuildDocs=dynamic,worker,local,sandbox` should tell Bazel
35+
to use workers if possible, otherwise fallback to non-worker invocations.
36+
1437

1538
```{toctree}
1639
:hidden:

sphinxdocs/private/sphinx.bzl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def sphinx_docs(
103103
strip_prefix = "",
104104
extra_opts = [],
105105
tools = [],
106-
use_persistent_workers = False,
106+
allow_persistent_workers = True,
107107
**kwargs):
108108
"""Generate docs using Sphinx.
109109
@@ -143,8 +143,9 @@ def sphinx_docs(
143143
tools: {type}`list[label]` Additional tools that are used by Sphinx and its plugins.
144144
This just makes the tools available during Sphinx execution. To locate
145145
them, use {obj}`extra_opts` and `$(location)`.
146-
use_persistent_workers: {type}`bool` (experimental) If enable, use a persistent
147-
worker to run Sphinx for improved incremental, caching, and startup performance.
146+
allow_persistent_workers: {type}`bool` (experimental) If true, allow
147+
using persistent workers for running Sphinx, if Bazel decides to do so.
148+
This can improve incremental building of docs.
148149
**kwargs: {type}`dict` Common attributes to pass onto rules.
149150
"""
150151
add_tag(kwargs, "@rules_python//sphinxdocs:sphinx_docs")
@@ -168,7 +169,7 @@ def sphinx_docs(
168169
source_tree = internal_name + "/_sources",
169170
extra_opts = extra_opts,
170171
tools = tools,
171-
use_persistent_workers = use_persistent_workers,
172+
allow_persistent_workers = allow_persistent_workers,
172173
**kwargs
173174
)
174175

@@ -213,7 +214,7 @@ def _sphinx_docs_impl(ctx):
213214
source_path = source_dir_path,
214215
output_prefix = paths.join(ctx.label.name, "_build"),
215216
inputs = inputs,
216-
use_persistent_workers = ctx.attr.use_persistent_workers,
217+
allow_persistent_workers = ctx.attr.allow_persistent_workers,
217218
)
218219
outputs[format] = output_dir
219220
per_format_args[format] = args_env
@@ -253,7 +254,7 @@ _sphinx_docs = rule(
253254
cfg = "exec",
254255
doc = "Additional tools that are used by Sphinx and its plugins.",
255256
),
256-
"use_persistent_workers": attr.bool(
257+
"allow_persistent_workers": attr.bool(
257258
doc = "(experimental) Whether to invoke Sphinx as a persistent worker.",
258259
default = False,
259260
),
@@ -263,7 +264,7 @@ _sphinx_docs = rule(
263264
},
264265
)
265266

266-
def _run_sphinx(ctx, format, source_path, inputs, output_prefix, use_persistent_workers):
267+
def _run_sphinx(ctx, format, source_path, inputs, output_prefix, allow_persistent_workers):
267268
output_dir = ctx.actions.declare_directory(paths.join(output_prefix, format))
268269

269270
run_args = [] # Copy of the args to forward along to debug runner
@@ -326,7 +327,7 @@ def _run_sphinx(ctx, format, source_path, inputs, output_prefix, use_persistent_
326327
# requirements and disable workers. Thus, we can't assume that these
327328
# exec requirements will actually be respected.
328329
execution_requirements = {}
329-
if use_persistent_workers:
330+
if allow_persistent_workers:
330331
execution_requirements["supports-workers"] = "1"
331332
execution_requirements["requires-worker-protocol"] = "json"
332333

0 commit comments

Comments
 (0)