Skip to content

Commit 5d85ba7

Browse files
Add smv_prebuild_command config option
Can be used to run a command in the checked out director before building with sphinx.
1 parent dd282b1 commit 5d85ba7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/configuration.rst

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ Here are some examples:
8181
8282
git for-each-ref --format "%(refname)" | sed 's/^refs\///g'
8383
84+
Prebuild command
85+
================
86+
87+
In some cases it may be necessary to run a command in the checked out directory before building with sphinx. For example if you are using ``sphinx-apidoc`` to generate the autodoc api source files.
88+
89+
For example:
90+
91+
smv_prebuild_command = "sphinx-apidoc -o docs/api mymodule"
8492

8593
Output Directory Format
8694
=======================

sphinx_multiversion/main.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def load_sphinx_config_worker(q, confpath, confoverrides, add_defaults):
6767
str,
6868
)
6969
current_config.add("smv_prefer_remote_refs", False, "html", bool)
70+
current_config.add("smv_prebuild_command", "", "html", str)
7071
current_config.pre_init_values()
7172
current_config.init_values()
7273
except Exception as err:
@@ -329,6 +330,15 @@ def main(argv=None):
329330
*args.filenames,
330331
]
331332
)
333+
current_cwd = os.path.join(data["basedir"], cwd_relative)
334+
if config.smv_prebuild_command != "":
335+
logger.debug(
336+
"Running prebuild command: %r", config.smv_prebuild_command
337+
)
338+
subprocess.check_call(
339+
config.smv_prebuild_command, cwd=current_cwd, shell=True
340+
)
341+
332342
logger.debug("Running sphinx-build with args: %r", current_argv)
333343
cmd = (
334344
sys.executable,
@@ -337,7 +347,7 @@ def main(argv=None):
337347
"sphinx",
338348
*current_argv,
339349
)
340-
current_cwd = os.path.join(data["basedir"], cwd_relative)
350+
341351
env = os.environ.copy()
342352
env.update(
343353
{

0 commit comments

Comments
 (0)