diff --git a/docs/configuration.rst b/docs/configuration.rst index 6b7d6aa2..0eb22db9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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 ======================= diff --git a/sphinx_multiversion/main.py b/sphinx_multiversion/main.py index 9870b314..da42216b 100644 --- a/sphinx_multiversion/main.py +++ b/sphinx_multiversion/main.py @@ -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: @@ -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, @@ -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( {