From c88ba504f357ecaf47337eff92fd13b2c54e13bc Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 13 Jan 2013 14:15:45 +0100 Subject: [PATCH] Introduce a "-j" flag for parallel build. --- sphinx/application.py | 5 ++++- sphinx/cmdline.py | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 02f0ff82e..3f1837373 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -61,7 +61,8 @@ class Sphinx(object): def __init__(self, srcdir, confdir, outdir, doctreedir, buildername, confoverrides=None, status=sys.stdout, warning=sys.stderr, - freshenv=False, warningiserror=False, tags=None, verbosity=0): + freshenv=False, warningiserror=False, tags=None, verbosity=0, + parallel=0): self.verbosity = verbosity self.next_listener_id = 0 self._extensions = {} @@ -76,6 +77,8 @@ class Sphinx(object): self.outdir = outdir self.doctreedir = doctreedir + self.parallel = parallel + if status is None: self._status = StringIO() self.quiet = True diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 13bd2e9f4..aee75418c 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -48,6 +48,7 @@ General options -E don't use a saved environment, always read all files -d path for the cached environment and doctree files (default: outdir/.doctrees) +-j build in parallel with N processes where possible Build configuration options ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +90,7 @@ def main(argv): nocolor() try: - opts, args = getopt.getopt(argv[1:], 'ab:t:d:c:CD:A:nNEqQWw:PThv', + opts, args = getopt.getopt(argv[1:], 'ab:t:d:c:CD:A:nNEqQWw:PThvj:', ['help', 'version']) allopts = set(opt[0] for opt in opts) if '-h' in allopts or '--help' in allopts: @@ -139,6 +140,7 @@ def main(argv): force_all = freshenv = warningiserror = use_pdb = False show_traceback = False verbosity = 0 + parallel = 0 status = sys.stdout warning = sys.stderr error = sys.stderr @@ -220,6 +222,13 @@ def main(argv): elif opt == '-v': verbosity += 1 show_traceback = True + elif opt == '-j': + try: + parallel = int(val) + except ValueError: + print >>sys.stderr, ('Error: -j option argument must be an ' + 'integer.') + return 1 if warning and warnfile: warnfp = open(warnfile, 'w') @@ -234,7 +243,7 @@ def main(argv): try: app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername, confoverrides, status, warning, freshenv, - warningiserror, tags, verbosity) + warningiserror, tags, verbosity, parallel) app.build(force_all, filenames) return app.statuscode except (Exception, KeyboardInterrupt), err: