diff options
author | Stephen Finucane <stephen@that.guru> | 2017-02-27 14:57:34 +0000 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2017-02-28 17:30:28 +0000 |
commit | 2afa0b6627f7e5afb188d5a60c8c4767f6250774 (patch) | |
tree | 36187057c569ce7f9db7baab62ad0e4474bda24b /sphinx/setup_command.py | |
parent | 493c65a9ee75589e3d77f0b97a4a4d7a764f0aeb (diff) | |
download | sphinx-git-2afa0b6627f7e5afb188d5a60c8c4767f6250774.tar.gz |
setuptools: Support multiple builders
At present, the 'builder' option for the setuptools integration only
supports a single output format, typically HTML, like so:
[build_sphinx]
builder = man
There is value in being able to specify multiple format, like so:
[build_sphinx]
builder = html man
Make this possible.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'sphinx/setup_command.py')
-rw-r--r-- | sphinx/setup_command.py | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py index ca0cdd88a..6d0aecb8f 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -28,7 +28,7 @@ from sphinx.util.osutil import abspath if False: # For type annotation - from typing import Any # NOQA + from typing import Any, Tuple # NOQA class BuildDoc(Command): @@ -76,7 +76,8 @@ class BuildDoc(Command): ('source-dir=', 's', 'Source directory'), ('build-dir=', None, 'Build directory'), ('config-dir=', 'c', 'Location of the configuration directory'), - ('builder=', 'b', 'The builder to use. Defaults to "html"'), + ('builder=', 'b', 'The builder (or builders) to use. Can be a comma- ' + 'or space-separated list. Defaults to "html"'), ('warning-is-error', 'W', 'Turn warning into errors'), ('project=', None, 'The documented project\'s name'), ('version=', None, 'The short X.Y version'), @@ -144,6 +145,7 @@ class BuildDoc(Command): self.config_dir = self.source_dir self.config_dir = abspath(self.config_dir) + self.ensure_string_list('builder') # type: ignore if self.build_dir is None: build = self.get_finalized_command('build') # type: ignore self.build_dir = os.path.join(abspath(build.build_base), 'sphinx') @@ -151,8 +153,11 @@ class BuildDoc(Command): self.build_dir = abspath(self.build_dir) self.doctree_dir = os.path.join(self.build_dir, 'doctrees') self.mkpath(self.doctree_dir) # type: ignore - self.builder_target_dir = os.path.join(self.build_dir, self.builder) - self.mkpath(self.builder_target_dir) # type: ignore + self.builder_target_dirs = [ + (builder, os.path.join(self.build_dir, builder)) + for builder in self.builder] # type: List[Tuple[str, unicode]] + for _, builder_target_dir in self.builder_target_dirs: + self.mkpath(builder_target_dir) # type: ignore def run(self): # type: () -> None @@ -174,24 +179,28 @@ class BuildDoc(Command): if self.copyright: confoverrides['copyright'] = self.copyright - app = None - try: - with docutils_namespace(): - app = Sphinx(self.source_dir, self.config_dir, - self.builder_target_dir, self.doctree_dir, - self.builder, confoverrides, status_stream, - freshenv=self.fresh_env, - warningiserror=self.warning_is_error) - app.build(force_all=self.all_files) - if app.statuscode: - raise DistutilsExecError( - 'caused by %s builder.' % app.builder.name) - except Exception as exc: - handle_exception(app, self, exc, sys.stderr) - if not self.pdb: - raise SystemExit(1) - - if self.link_index: + for builder, builder_target_dir in self.builder_target_dirs: + app = None + + try: + with docutils_namespace(): + app = Sphinx(self.source_dir, self.config_dir, + builder_target_dir, self.doctree_dir, + builder, confoverrides, status_stream, + freshenv=self.fresh_env, + warningiserror=self.warning_is_error) + app.build(force_all=self.all_files) + if app.statuscode: + raise DistutilsExecError( + 'caused by %s builder.' % app.builder.name) + except Exception as exc: + handle_exception(app, self, exc, sys.stderr) + if not self.pdb: + raise SystemExit(1) + + if not self.link_index: + continue + src = app.config.master_doc + app.builder.out_suffix # type: ignore dst = app.builder.get_outfilename('index') # type: ignore os.symlink(src, dst) |