43
43
import glob
44
44
import os
45
45
import shutil
46
+ from matplotlib .compat .subprocess import subprocess
46
47
import sys
47
48
import warnings
48
49
@@ -404,25 +405,41 @@ def make_dvi(self, tex, fontsize):
404
405
(os .path .split (texfile )[- 1 ], outfile ))
405
406
mpl .verbose .report (command , 'debug' )
406
407
with Locked (self .texcache ):
407
- exit_status = os .system (command )
408
- try :
409
- with open (outfile ) as fh :
410
- report = fh .read ()
411
- except IOError :
412
- report = 'No latex error report available.'
413
- try :
414
- os .stat (dvifile )
415
- exists = True
416
- except OSError :
417
- exists = False
418
- if exit_status or not exists :
419
- raise RuntimeError (
420
- ('LaTeX was not able to process the following '
421
- 'string:\n %s\n Here is the full report generated by '
422
- 'LaTeX: \n \n ' % repr (tex .encode ('unicode_escape' )) +
423
- report ))
424
- else :
425
- mpl .verbose .report (report , 'debug' )
408
+ try :
409
+ output = subprocess .check_output (command , shell = True ,
410
+ stderr = subprocess .STDOUT )
411
+ except subprocess .CalledProcessError as exc :
412
+ try :
413
+ with open (outfile ) as fh :
414
+ report = fh .read ()
415
+ except IOError :
416
+ report = 'No latex error report available.'
417
+ raise RuntimeError (
418
+ ('LaTeX was not able to process the following '
419
+ 'string:\n %s\n LaTeX failed with: %s\n '
420
+ 'Here is the full report generated by LaTeX: '
421
+ '\n \n ' % (exc .output ,
422
+ repr (tex .encode ('unicode_escape' ))) +
423
+ report ))
424
+ try :
425
+ with open (outfile ) as fh :
426
+ report = fh .read ()
427
+ except IOError :
428
+ report = 'No latex error report available.'
429
+ try :
430
+ os .stat (dvifile )
431
+ exists = True
432
+ except OSError :
433
+ exists = False
434
+ if not exists :
435
+ raise RuntimeError (
436
+ ('LaTeX was not able to process the following '
437
+ 'string:\n %s\n '
438
+ 'Here is the full report generated by LaTeX: '
439
+ '\n \n ' % repr (tex .encode ('unicode_escape' )) +
440
+ report ))
441
+ else :
442
+ mpl .verbose .report (report , 'debug' )
426
443
for fname in glob .glob (basefile + '*' ):
427
444
if fname .endswith ('dvi' ):
428
445
pass
@@ -457,20 +474,28 @@ def make_dvi_preview(self, tex, fontsize):
457
474
'latex -interaction=nonstopmode %s > "%s"' %
458
475
(os .path .split (texfile )[- 1 ], outfile ))
459
476
mpl .verbose .report (command , 'debug' )
460
- exit_status = os .system (command )
477
+ try :
478
+ output = subprocess .check_output (command , shell = True ,
479
+ stderr = subprocess .STDOUT )
480
+ except subprocess .CalledProcessError as exc :
481
+ try :
482
+ with open (outfile ) as fh :
483
+ report = fh .read ()
484
+ except IOError :
485
+ report = 'No latex error report available.'
486
+ raise RuntimeError (
487
+ ('LaTeX was not able to process the following '
488
+ 'string:\n %s\n LaTeX failed with: %s\n '
489
+ 'Here is the full report generated by LaTeX: '
490
+ '\n \n ' % (exc .output ,
491
+ repr (tex .encode ('unicode_escape' ))) +
492
+ report ))
461
493
try :
462
494
with open (outfile ) as fh :
463
495
report = fh .read ()
464
-
465
496
except IOError :
466
497
report = 'No latex error report available.'
467
- if exit_status :
468
- raise RuntimeError (
469
- ('LaTeX was not able to process the following '
470
- 'string:\n %s\n Here is the full report generated by '
471
- 'LaTeX: \n \n ' % repr (tex )) + report )
472
- else :
473
- mpl .verbose .report (report , 'debug' )
498
+ mpl .verbose .report (report , 'debug' )
474
499
475
500
# find the box extent information in the latex output
476
501
# file and store them in ".baseline" file
@@ -512,19 +537,28 @@ def make_png(self, tex, fontsize, dpi):
512
537
(dpi , os .path .split (pngfile )[- 1 ],
513
538
os .path .split (dvifile )[- 1 ], outfile ))
514
539
mpl .verbose .report (command , 'debug' )
515
- exit_status = os .system (command )
540
+ try :
541
+ output = subprocess .check_output (command , shell = True ,
542
+ stderr = subprocess .STDOUT )
543
+ except subprocess .CalledProcessError as exc :
544
+ try :
545
+ with open (outfile ) as fh :
546
+ report = fh .read ()
547
+ except IOError :
548
+ report = 'No dvipng error report available.'
549
+ raise RuntimeError (
550
+ ('dvipng was not able to process the following '
551
+ 'string:\n %s\n dvipng failed with: %s\n '
552
+ 'Here is the full report generated by dvipng: '
553
+ '\n \n ' % (exc .output ,
554
+ repr (tex .encode ('unicode_escape' ))) +
555
+ report ))
516
556
try :
517
557
with open (outfile ) as fh :
518
558
report = fh .read ()
519
559
except IOError :
520
560
report = 'No dvipng error report available.'
521
- if exit_status :
522
- raise RuntimeError (
523
- 'dvipng was not able to process the following '
524
- 'file:\n %s\n Here is the full report generated by '
525
- 'dvipng: \n \n ' % dvifile + report )
526
- else :
527
- mpl .verbose .report (report , 'debug' )
561
+ mpl .verbose .report (report , 'debug' )
528
562
try :
529
563
os .remove (outfile )
530
564
except OSError :
@@ -550,15 +584,19 @@ def make_ps(self, tex, fontsize):
550
584
(os .path .split (psfile )[- 1 ],
551
585
os .path .split (dvifile )[- 1 ], outfile ))
552
586
mpl .verbose .report (command , 'debug' )
553
- exit_status = os .system (command )
554
- with open (outfile ) as fh :
555
- if exit_status :
587
+ try :
588
+ output = subprocess .check_output (command , shell = True ,
589
+ stderr = subprocess .STDOUT )
590
+ except subprocess .CalledProcessError as exc :
591
+ with open (outfile ) as fh :
556
592
raise RuntimeError (
557
- 'dvipng was not able to process the flowing '
558
- 'file:\n %s\n Here is the full report generated by '
559
- 'dvipng: \n \n ' % dvifile + fh .read ())
560
- else :
561
- mpl .verbose .report (fh .read (), 'debug' )
593
+ ('dvipng was not able to process the following '
594
+ 'file:\n %s\n dvipng failed with: %s\n '
595
+ 'Here is the full report generated by dvipng: '
596
+ '\n \n ' % (dvifile , exc .output ) +
597
+ fh .read ()))
598
+ with open (outfile ) as fh :
599
+ mpl .verbose .report (fh .read (), 'debug' )
562
600
os .remove (outfile )
563
601
564
602
return psfile
0 commit comments