Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d664879

Browse files
committed
Merge pull request #541 from mdboom/issue520
Issue520
2 parents 93e4d19 + fc30d92 commit d664879

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

doc/sphinxext/gen_rst.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ def generate_example_rst(app):
113113

114114
fhsubdirIndex.write(' %s <%s>\n'%(os.path.basename(basename),rstfile))
115115

116+
do_plot = (subdir in ('api',
117+
'pylab_examples',
118+
'units',
119+
'mplot3d',
120+
'axes_grid',
121+
) and
122+
not noplot_regex.search(contents))
123+
if not do_plot:
124+
fhstatic = file(outputfile, 'w')
125+
fhstatic.write(contents)
126+
fhstatic.close()
127+
116128
if not out_of_date(fullpath, outrstfile):
117129
continue
118130

@@ -121,25 +133,13 @@ def generate_example_rst(app):
121133
title = '%s example code: %s'%(subdir, fname)
122134
#title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname)
123135

124-
125136
fh.write(title + '\n')
126137
fh.write('='*len(title) + '\n\n')
127138

128-
do_plot = (subdir in ('api',
129-
'pylab_examples',
130-
'units',
131-
'mplot3d',
132-
'axes_grid',
133-
) and
134-
not noplot_regex.search(contents))
135-
136139
if do_plot:
137140
fh.write("\n\n.. plot:: %s\n\n::\n\n" % fullpath)
138141
else:
139142
fh.write("[`source code <%s>`_]\n\n::\n\n" % fname)
140-
fhstatic = file(outputfile, 'w')
141-
fhstatic.write(contents)
142-
fhstatic.close()
143143

144144
# indent the contents
145145
contents = '\n'.join([' %s'%row.rstrip() for row in contents.split('\n')])

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,13 @@ def run(arguments, content, options, state_machine, state, lineno):
764764
shutil.copyfile(fn, destimg)
765765

766766
# copy script (if necessary)
767+
target_name = os.path.join(dest_dir, output_base + source_ext)
768+
f = open(target_name, 'w')
767769
if source_file_name == rst_file:
768-
target_name = os.path.join(dest_dir, output_base + source_ext)
769-
f = open(target_name, 'w')
770-
f.write(unescape_doctest(code))
771-
f.close()
770+
code_escaped = unescape_doctest(code)
771+
else:
772+
code_escaped = code
773+
f.write(code_escaped)
774+
f.close()
772775

773776
return errors

0 commit comments

Comments
 (0)