Skip to content

Commit

Permalink
Add smv_prebuild_command config option
Browse files Browse the repository at this point in the history
Can be used to run a command in the checked out director before building
with sphinx.
  • Loading branch information
samtygier-stfc committed May 26, 2021
1 parent dd282b1 commit 5d85ba7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ Here are some examples:
git for-each-ref --format "%(refname)" | sed 's/^refs\///g'
Prebuild command
================

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.

For example:

smv_prebuild_command = "sphinx-apidoc -o docs/api mymodule"

Output Directory Format
=======================
Expand Down
12 changes: 11 additions & 1 deletion sphinx_multiversion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def load_sphinx_config_worker(q, confpath, confoverrides, add_defaults):
str,
)
current_config.add("smv_prefer_remote_refs", False, "html", bool)
current_config.add("smv_prebuild_command", "", "html", str)
current_config.pre_init_values()
current_config.init_values()
except Exception as err:
Expand Down Expand Up @@ -329,6 +330,15 @@ def main(argv=None):
*args.filenames,
]
)
current_cwd = os.path.join(data["basedir"], cwd_relative)
if config.smv_prebuild_command != "":
logger.debug(
"Running prebuild command: %r", config.smv_prebuild_command
)
subprocess.check_call(
config.smv_prebuild_command, cwd=current_cwd, shell=True
)

logger.debug("Running sphinx-build with args: %r", current_argv)
cmd = (
sys.executable,
Expand All @@ -337,7 +347,7 @@ def main(argv=None):
"sphinx",
*current_argv,
)
current_cwd = os.path.join(data["basedir"], cwd_relative)

env = os.environ.copy()
env.update(
{
Expand Down

0 comments on commit 5d85ba7

Please sign in to comment.