|
6 | 6 | import shutil
|
7 | 7 | import sys
|
8 | 8 | import re
|
9 |
| - |
| 9 | +import argparse |
10 | 10 |
|
11 | 11 | def copy_if_out_of_date(original, derived):
|
12 | 12 | if (not os.path.exists(derived) or
|
@@ -43,6 +43,8 @@ def html(buildername='html'):
|
43 | 43 | options = "-D plot_formats=\"[('png', 80)]\""
|
44 | 44 | else:
|
45 | 45 | options = ''
|
| 46 | + if warnings_as_errors: |
| 47 | + options = options + ' -W' |
46 | 48 | if os.system('sphinx-build %s -b %s -d build/doctrees . build/%s' % (options, buildername, buildername)):
|
47 | 49 | raise SystemExit("Building HTML failed.")
|
48 | 50 |
|
@@ -136,6 +138,7 @@ def all():
|
136 | 138 |
|
137 | 139 |
|
138 | 140 | small_docs = False
|
| 141 | +warnings_as_errors = False |
139 | 142 |
|
140 | 143 | # Change directory to the one containing this file
|
141 | 144 | current_dir = os.getcwd()
|
@@ -174,17 +177,28 @@ def all():
|
174 | 177 | 'as spurious changes in your \'git status\':\n\t{}'
|
175 | 178 | .format('\n\t'.join(symlink_warnings)))
|
176 | 179 |
|
177 |
| -if len(sys.argv)>1: |
178 |
| - if '--small' in sys.argv[1:]: |
179 |
| - small_docs = True |
180 |
| - sys.argv.remove('--small') |
181 |
| - for arg in sys.argv[1:]: |
182 |
| - func = funcd.get(arg) |
| 180 | +parser = argparse.ArgumentParser(description='Build matplotlib docs') |
| 181 | +parser.add_argument("cmd", help=("Command to execute. Can be multiple. " |
| 182 | + "Valid options are: %s" % (funcd.keys())), nargs='*') |
| 183 | +parser.add_argument("--small", |
| 184 | + help="Smaller docs with only low res png figures", |
| 185 | + action="store_true") |
| 186 | +parser.add_argument("--warningsaserrors", |
| 187 | + help="Turn Sphinx warnings into errors", |
| 188 | + action="store_true") |
| 189 | +args = parser.parse_args() |
| 190 | +if args.small: |
| 191 | + small_docs = True |
| 192 | +if args.warningsaserrors: |
| 193 | + warnings_as_errors = True |
| 194 | + |
| 195 | +if args.cmd: |
| 196 | + for command in args.cmd: |
| 197 | + func = funcd.get(command) |
183 | 198 | if func is None:
|
184 |
| - raise SystemExit('Do not know how to handle %s; valid args are %s'%( |
185 |
| - arg, funcd.keys())) |
| 199 | + raise SystemExit(('Do not know how to handle %s; valid commands' |
| 200 | + ' are %s' % (command, funcd.keys()))) |
186 | 201 | func()
|
187 | 202 | else:
|
188 |
| - small_docs = False |
189 | 203 | all()
|
190 | 204 | os.chdir(current_dir)
|
0 commit comments