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,36 @@ 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
+ os .stat (dvifile )
426
+ exists = True
427
+ except OSError :
428
+ exists = False
429
+ if not exists :
430
+ raise RuntimeError (
431
+ ('LaTeX was not able to process the following '
432
+ 'string:\n %s\n '
433
+ 'Here is the full report generated by LaTeX: '
434
+ '\n \n ' % repr (tex .encode ('unicode_escape' )) +
435
+ report ))
436
+ else :
437
+ mpl .verbose .report (report , 'debug' )
426
438
for fname in glob .glob (basefile + '*' ):
427
439
if fname .endswith ('dvi' ):
428
440
pass
@@ -457,20 +469,23 @@ def make_dvi_preview(self, tex, fontsize):
457
469
'latex -interaction=nonstopmode %s > "%s"' %
458
470
(os .path .split (texfile )[- 1 ], outfile ))
459
471
mpl .verbose .report (command , 'debug' )
460
- exit_status = os .system (command )
461
472
try :
462
- with open (outfile ) as fh :
463
- report = fh .read ()
464
-
465
- except IOError :
466
- report = 'No latex error report available.'
467
- if exit_status :
473
+ output = subprocess .check_output (command , shell = True ,
474
+ stderr = subprocess .STDOUT )
475
+ except subprocess .CalledProcessError as exc :
476
+ try :
477
+ with open (outfile ) as fh :
478
+ report = fh .read ()
479
+ except IOError :
480
+ report = 'No latex error report available.'
468
481
raise RuntimeError (
469
482
('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' )
483
+ 'string:\n %s\n LaTeX failed with: %s\n '
484
+ 'Here is the full report generated by LaTeX: '
485
+ '\n \n ' % (exc .output ,
486
+ repr (tex .encode ('unicode_escape' ))) +
487
+ report ))
488
+ mpl .verbose .report (report , 'debug' )
474
489
475
490
# find the box extent information in the latex output
476
491
# file and store them in ".baseline" file
@@ -512,19 +527,23 @@ def make_png(self, tex, fontsize, dpi):
512
527
(dpi , os .path .split (pngfile )[- 1 ],
513
528
os .path .split (dvifile )[- 1 ], outfile ))
514
529
mpl .verbose .report (command , 'debug' )
515
- exit_status = os .system (command )
516
530
try :
517
- with open (outfile ) as fh :
518
- report = fh .read ()
519
- except IOError :
520
- report = 'No dvipng error report available.'
521
- if exit_status :
531
+ output = subprocess .check_output (command , shell = True ,
532
+ stderr = subprocess .STDOUT )
533
+ except subprocess .CalledProcessError as exc :
534
+ try :
535
+ with open (outfile ) as fh :
536
+ report = fh .read ()
537
+ except IOError :
538
+ report = 'No dvipng error report available.'
522
539
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' )
540
+ ('dvipng was not able to process the following '
541
+ 'string:\n %s\n dvipng failed with: %s\n '
542
+ 'Here is the full report generated by dvipng: '
543
+ '\n \n ' % (exc .output ,
544
+ repr (tex .encode ('unicode_escape' ))) +
545
+ report ))
546
+ mpl .verbose .report (report , 'debug' )
528
547
try :
529
548
os .remove (outfile )
530
549
except OSError :
@@ -550,15 +569,19 @@ def make_ps(self, tex, fontsize):
550
569
(os .path .split (psfile )[- 1 ],
551
570
os .path .split (dvifile )[- 1 ], outfile ))
552
571
mpl .verbose .report (command , 'debug' )
553
- exit_status = os .system (command )
554
- with open (outfile ) as fh :
555
- if exit_status :
572
+ try :
573
+ output = subprocess .check_output (command , shell = True ,
574
+ stderr = subprocess .STDOUT )
575
+ except subprocess .CalledProcessError as exc :
576
+ with open (outfile ) as fh :
556
577
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' )
578
+ ('dvipng was not able to process the following '
579
+ 'file:\n %s\n dvipng failed with: %s\n '
580
+ 'Here is the full report generated by dvipng: '
581
+ '\n \n ' % (dvifile , exc .output ) +
582
+ fh .read ()))
583
+ with open (outfile ) as fh :
584
+ mpl .verbose .report (fh .read (), 'debug' )
562
585
os .remove (outfile )
563
586
564
587
return psfile
0 commit comments