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

Skip to content

Commit c5c511e

Browse files
committed
improve error reporting in texmanager
svn path=/branches/v0_91_maint/; revision=5771
1 parent bf8b763 commit c5c511e

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-07-16 Improve error handling in texmanager, thanks to Ian Henry
2+
for reporting - DSD
3+
14
2008-07-09 Improve mathtext radical rendering - MGD
25

36
2008-07-08 Improve mathtext superscript placement - MGD

lib/matplotlib/texmanager.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,22 @@ def make_dvi(self, tex, fontsize):
255255
%(os.path.split(texfile)[-1], outfile))
256256
mpl.verbose.report(command, 'debug')
257257
exit_status = os.system(command)
258-
fh = file(outfile)
258+
try:
259+
fh = file(outfile)
260+
report = fh.read()
261+
fh.close()
262+
except IOError:
263+
report = 'No latex error report available.'
259264
if exit_status:
260265
raise RuntimeError(('LaTeX was not able to process the following \
261-
string:\n%s\nHere is the full report generated by LaTeX: \n\n'% repr(tex)) + fh.read())
262-
else: mpl.verbose.report(fh.read(), 'debug')
263-
fh.close()
266+
string:\n%s\nHere is the full report generated by LaTeX: \n\n'% repr(tex)) + report)
267+
else: mpl.verbose.report(report, 'debug')
264268
for fname in glob.glob(basefile+'*'):
265269
if fname.endswith('dvi'): pass
266270
elif fname.endswith('tex'): pass
267-
else: os.remove(fname)
271+
else:
272+
try: os.remove(fname)
273+
except OSError: pass
268274

269275
return dvifile
270276

@@ -282,14 +288,19 @@ def make_png(self, tex, fontsize, dpi):
282288
os.path.split(dvifile)[-1], outfile))
283289
mpl.verbose.report(command, 'debug')
284290
exit_status = os.system(command)
285-
fh = file(outfile)
291+
try:
292+
fh = file(outfile)
293+
report = fh.read()
294+
fh.close()
295+
except IOError:
296+
report = 'No dvipng error report available.'
286297
if exit_status:
287298
raise RuntimeError('dvipng was not able to \
288299
process the flowing file:\n%s\nHere is the full report generated by dvipng: \
289-
\n\n'% dvifile + fh.read())
290-
else: mpl.verbose.report(fh.read(), 'debug')
291-
fh.close()
292-
os.remove(outfile)
300+
\n\n'% dvifile + report)
301+
else: mpl.verbose.report(report, 'debug')
302+
try: os.remove(outfile)
303+
except OSError: pass
293304

294305
return pngfile
295306

@@ -363,7 +374,7 @@ def get_grey(self, tex, fontsize=None, dpi=None):
363374
# white (1) this reduces to red = 1-alpha or alpha = 1-red
364375
#alpha = npy.sqrt(1-X[:,:,0]) # should this be sqrt here?
365376
alpha = 1-X[:,:,0]
366-
377+
367378
else:
368379
alpha = X[:,:,-1]
369380

0 commit comments

Comments
 (0)