Skip to content

Commit e33f456

Browse files
committed
Fix --small option for docs build with sphinx 1.3
Sphinx 1.3 adds support for passing lists from the commandline. This means that it splits on ',' which turns "[('png', 80)]" into ["[('png'", "80)]"]. Fix this py passing the formats on commandline as suffix0:dpi0,suffix1:dpi1...
1 parent e783caa commit e33f456

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

doc/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def html(buildername='html'):
4040
check_build()
4141
copy_if_out_of_date('../lib/matplotlib/mpl-data/matplotlibrc', '_static/matplotlibrc')
4242
if small_docs:
43-
options = "-D plot_formats=\"[('png', 80)]\""
43+
options = "-D plot_formats=png:80"
4444
else:
4545
options = ''
4646
if warnings_as_errors:

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@
103103
[(suffix, dpi), suffix, ...]
104104
105105
that determine the file format and the DPI. For entries whose
106-
DPI was omitted, sensible defaults are chosen.
106+
DPI was omitted, sensible defaults are chosen. When passing from
107+
the command line through sphinx_build the list should be passed as
108+
suffix:dpi,suffix:dpi, ....
107109
108110
plot_html_show_formats
109111
Whether to show links to the files in HTML.
@@ -539,10 +541,17 @@ def render_figures(code, code_path, output_dir, output_base, context,
539541
formats = []
540542
plot_formats = config.plot_formats
541543
if isinstance(plot_formats, six.string_types):
542-
plot_formats = eval(plot_formats)
544+
# String Sphinx < 1.3, Split on , to mimic
545+
# Sphinx 1.3 and later. Sphinx 1.3 always
546+
# returns a list.
547+
plot_formats = plot_formats.split(',')
543548
for fmt in plot_formats:
544549
if isinstance(fmt, six.string_types):
545-
formats.append((fmt, default_dpi.get(fmt, 80)))
550+
if ':' in fmt:
551+
suffix,dpi = fmt.split(':')
552+
formats.append((str(suffix), int(dpi)))
553+
else:
554+
formats.append((fmt, default_dpi.get(fmt, 80)))
546555
elif type(fmt) in (tuple, list) and len(fmt)==2:
547556
formats.append((str(fmt[0]), int(fmt[1])))
548557
else:

0 commit comments

Comments
 (0)