summaryrefslogtreecommitdiff
path: root/sphinx/cmdline.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-01-21 16:07:14 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-01-21 16:07:14 +0900
commit9a3f401c469ec6c16be32ce1bda11d266ba88d76 (patch)
treed16d1b647f40eb2610e3ecb382878a4a1f7f8395 /sphinx/cmdline.py
parent6e420e517ed20aaa6922250d4324582d83f7ee10 (diff)
parent91873f09b896762297dbb8aba6b67ede5d22ac88 (diff)
downloadsphinx-git-9a3f401c469ec6c16be32ce1bda11d266ba88d76.tar.gz
Merge branch '1.7-release'
Diffstat (limited to 'sphinx/cmdline.py')
-rw-r--r--sphinx/cmdline.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py
index e13261dfe..264ee30fe 100644
--- a/sphinx/cmdline.py
+++ b/sphinx/cmdline.py
@@ -12,6 +12,7 @@ from __future__ import print_function
import argparse
import os
+import multiprocessing
import sys
import traceback
@@ -82,6 +83,23 @@ def handle_exception(app, args, exception, stderr=sys.stderr):
file=stderr)
+def jobs_argument(value):
+ # type: (str) -> int
+ """
+ Special type to handle 'auto' flags passed to 'sphinx-build' via -j flag. Can
+ be expanded to handle other special scaling requests, such as setting job count
+ to cpu_count.
+ """
+ if value == 'auto':
+ return multiprocessing.cpu_count()
+ else:
+ jobs = int(value)
+ if jobs <= 0:
+ raise argparse.ArgumentTypeError('job number should be a positive number')
+ else:
+ return jobs
+
+
def get_parser():
# type: () -> argparse.ArgumentParser
parser = argparse.ArgumentParser(
@@ -128,10 +146,9 @@ files can be built by specifying individual filenames.
group.add_argument('-d', metavar='PATH', dest='doctreedir',
help='path for the cached environment and doctree '
'files (default: OUTPUTDIR/.doctrees)')
- group.add_argument('-j', metavar='N', default=1, type=int, dest='jobs',
+ group.add_argument('-j', metavar='N', default=1, type=jobs_argument, dest='jobs',
help='build in parallel with N processes where '
- 'possible')
-
+ 'possible (special value "auto" will set N to cpu-count)')
group = parser.add_argument_group('build configuration options')
group.add_argument('-c', metavar='PATH', dest='confdir',
help='path where configuration file (conf.py) is '