Skip to content

Commit 54bd24f

Browse files
committed
The contentes of this PR
sphinx-contrib/multiversion#62 has not been merged yet and is not available from pypi. This picks-up that change to that `smv_prebuild_command` can be used by Zuar documentation.
1 parent dd282b1 commit 54bd24f

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# sphinx-multiversion [![Build Status](https://travis-ci.org/Holzhaus/sphinx-multiversion.svg?branch=master)](https://travis-ci.org/Holzhaus/sphinx-multiversion)
2-
31
Sphinx extension for building self-hosted versioned docs.
42

5-
This extension aims to provide a clean implementation that tries to avoid
6-
messing with Sphinx internals as much as possible.
3+
This is a Zuar fork of the original `sphinx-multiversion`, which
4+
lives here: https://holzhaus.github.io/sphinx-multiversion/
75

8-
Documentation can be found at: https://holzhaus.github.io/sphinx-multiversion/
6+
The fork is necessary to add support for `smv_prebuild_command` which
7+
is not yet available in the original repo. This fork can be
8+
removed once the prebuild feature is available via pypi.

docs/configuration.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ Here are some examples:
8282
git for-each-ref --format "%(refname)" | sed 's/^refs\///g'
8383
8484
85+
Prebuild command
86+
================
87+
88+
In some cases it may be necessary to run a command in the checked out
89+
directory before building with sphinx. For example if you are using
90+
``sphinx-apidoc`` to generate the autodoc api source files.
91+
92+
For example:
93+
94+
smv_prebuild_command = "sphinx-apidoc -o docs/api mymodule"
95+
96+
8597
Output Directory Format
8698
=======================
8799

sphinx_multiversion/main.py

Lines changed: 26 additions & 3 deletions
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:
@@ -289,6 +290,7 @@ def main(argv=None):
289290
),
290291
"confdir": confpath,
291292
"docnames": list(project.discover()),
293+
"commit": gitref.commit,
292294
}
293295

294296
if args.dump_metadata:
@@ -329,16 +331,37 @@ def main(argv=None):
329331
*args.filenames,
330332
]
331333
)
332-
logger.debug("Running sphinx-build with args: %r", current_argv)
334+
335+
current_cwd = os.path.join(data["basedir"], cwd_relative)
336+
337+
env = os.environ.copy()
338+
339+
if config.smv_prebuild_command != "":
340+
logger.info("Running prebuild command: %r", config.smv_prebuild_command)
341+
342+
cpi = subprocess.run(
343+
config.smv_prebuild_command,
344+
cwd=current_cwd,
345+
shell=True,
346+
stdout=subprocess.PIPE,
347+
stderr=subprocess.STDOUT,
348+
env=env,
349+
executable="/bin/bash",
350+
)
351+
352+
if cpi.returncode != 0:
353+
print(cpi.stdout.decode("UTF-8"), file=sys.stderr, flush=True)
354+
raise subprocess.CalledProcessError
355+
356+
logger.info("Running sphinx-build with args: %r", current_argv)
333357
cmd = (
334358
sys.executable,
335359
*get_python_flags(),
336360
"-m",
337361
"sphinx",
338362
*current_argv,
339363
)
340-
current_cwd = os.path.join(data["basedir"], cwd_relative)
341-
env = os.environ.copy()
364+
342365
env.update(
343366
{
344367
"SPHINX_MULTIVERSION_NAME": data["name"],

sphinx_multiversion/sphinx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"version",
2828
"release",
2929
"is_released",
30+
"commit",
3031
],
3132
)
3233

@@ -45,6 +46,7 @@ def _dict_to_versionobj(self, v):
4546
version=v["version"],
4647
release=v["release"],
4748
is_released=v["is_released"],
49+
commit=v["commit"],
4850
)
4951

5052
@property

0 commit comments

Comments
 (0)