Skip to content

Commit e61ff44

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 71856e6 commit e61ff44

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/configuration.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ Here are some examples:
8181
8282
git for-each-ref --format "%(refname)"
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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def load_sphinx_config_worker(q, confpath, confoverrides, add_defaults):
9393
str,
9494
)
9595
current_config.add("smv_prefer_remote_refs", False, "html", bool)
96+
current_config.add("smv_prebuild_command", "", "html", str)
9697
current_config.pre_init_values()
9798
current_config.init_values()
9899
except Exception as err:
@@ -355,6 +356,15 @@ def main(argv=None):
355356
*args.filenames,
356357
]
357358
)
359+
current_cwd = os.path.join(data["basedir"], cwd_relative)
360+
if config.smv_prebuild_command != "":
361+
logger.debug(
362+
"Running prebuild command: %r", config.smv_prebuild_command
363+
)
364+
subprocess.check_call(
365+
config.smv_prebuild_command, cwd=current_cwd, shell=True
366+
)
367+
358368
logger.debug("Running sphinx-build with args: %r", current_argv)
359369
cmd = (
360370
sys.executable,
@@ -363,7 +373,7 @@ def main(argv=None):
363373
"sphinx",
364374
*current_argv,
365375
)
366-
current_cwd = os.path.join(data["basedir"], cwd_relative)
376+
367377
env = os.environ.copy()
368378
env.update(
369379
{

0 commit comments

Comments
 (0)