Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e38b65

Browse filesBrowse files
authored
feat: Allow additional tools for sphinx_docs (bazel-contrib#1831)
Some Sphinx plugins require that other (not necessarily Python) tools are available. One example is the plugin https://github.com/basejumpa/sphinxcontrib-umlet, which requires that UMLet is somehow within the sandbox. * Adds `tools` arg to `sphinx_docs` to allow passing in arbitrary tools that are made available at runtime * Performs location expansion on `extra_opts`, which allows passing the location of the tools onto sphinx.
1 parent 4a615be commit 9e38b65
Copy full SHA for 9e38b65

File tree

Expand file treeCollapse file tree

1 file changed

+18
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-1
lines changed

‎sphinxdocs/private/sphinx.bzl

Copy file name to clipboardExpand all lines: sphinxdocs/private/sphinx.bzl
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def sphinx_docs(
5555
formats,
5656
strip_prefix = "",
5757
extra_opts = [],
58+
tools = [],
5859
**kwargs):
5960
"""Generate docs using Sphinx.
6061
@@ -88,6 +89,11 @@ def sphinx_docs(
8889
source files. e.g., given `//docs:foo.md`, stripping `docs/`
8990
makes Sphinx see `foo.md` in its generated source directory.
9091
extra_opts: (list[str]) Additional options to pass onto Sphinx building.
92+
On each provided option, a location expansion is performed.
93+
See `ctx.expand_location()`.
94+
tools: (list[label]) Additional tools that are used by Sphinx and its plugins.
95+
This just makes the tools available during Sphinx execution. To locate
96+
them, use `extra_opts` and `$(location)`.
9197
**kwargs: (dict) Common attributes to pass onto rules.
9298
"""
9399
add_tag(kwargs, "@rules_python//sphinxdocs:sphinx_docs")
@@ -102,6 +108,7 @@ def sphinx_docs(
102108
formats = formats,
103109
strip_prefix = strip_prefix,
104110
extra_opts = extra_opts,
111+
tools = tools,
105112
**kwargs
106113
)
107114

@@ -174,6 +181,10 @@ _sphinx_docs = rule(
174181
doc = "Doc source files for Sphinx.",
175182
),
176183
"strip_prefix": attr.string(doc = "Prefix to remove from input file paths."),
184+
"tools": attr.label_list(
185+
cfg = "exec",
186+
doc = "Additional tools that are used by Sphinx and its plugins.",
187+
),
177188
"_extra_defines_flag": attr.label(default = "//sphinxdocs:extra_defines"),
178189
"_extra_env_flag": attr.label(default = "//sphinxdocs:extra_env"),
179190
},
@@ -238,7 +249,8 @@ def _run_sphinx(ctx, format, source_path, inputs, output_prefix):
238249
args.add("-j", "auto") # Build in parallel, if possible
239250
args.add("-E") # Don't try to use cache files. Bazel can't make use of them.
240251
args.add("-a") # Write all files; don't try to detect "changed" files
241-
args.add_all(ctx.attr.extra_opts)
252+
for opt in ctx.attr.extra_opts:
253+
args.add(ctx.expand_location(opt))
242254
args.add_all(ctx.attr._extra_defines_flag[_FlagInfo].value, before_each = "-D")
243255
args.add(source_path)
244256
args.add(output_dir.path)
@@ -248,11 +260,16 @@ def _run_sphinx(ctx, format, source_path, inputs, output_prefix):
248260
for v in ctx.attr._extra_env_flag[_FlagInfo].value
249261
])
250262

263+
tools = []
264+
for tool in ctx.attr.tools:
265+
tools.append(tool[DefaultInfo].files_to_run)
266+
251267
ctx.actions.run(
252268
executable = ctx.executable.sphinx,
253269
arguments = [args],
254270
inputs = inputs,
255271
outputs = [output_dir],
272+
tools = tools,
256273
mnemonic = "SphinxBuildDocs",
257274
progress_message = "Sphinx building {} for %{{label}}".format(format),
258275
env = env,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.