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

Skip to content

Commit ca8413a

Browse files
committed
don't use subprocess module for now, problems with
windows/python-2.3 svn path=/trunk/matplotlib/; revision=2155
1 parent 29593b6 commit ca8413a

File tree

3 files changed

+109
-85
lines changed

3 files changed

+109
-85
lines changed

lib/matplotlib/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ def validate_ps_distiller(s):
628628
warnings.warn('matplotlibrc ps.usedistiller can not be set to \
629629
xpdf unless xpdf-%s or later is installed on your system' % xpdf_req)
630630

631-
ps2eps_v = checkdep_ps2eps()
632-
if compare_versions(ps2eps_v, ps2eps_req): pass
633-
else:
634-
flag = False
635-
warnings.warn('matplotlibrc ps.usedistiller can not be set to xpdf \
636-
unless ps2eps-%s or later is installed on your system' % ps2eps_req)
631+
## ps2eps_v = checkdep_ps2eps()
632+
## if compare_versions(ps2eps_v, ps2eps_req): pass
633+
## else:
634+
## flag = False
635+
## warnings.warn('matplotlibrc ps.usedistiller can not be set to xpdf \
636+
##unless ps2eps-%s or later is installed on your system' % ps2eps_req)
637637

638638
if flag: return s
639639
else: return None

lib/matplotlib/backends/backend_ps.py

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import glob, math, md5, os, shutil, sys, time
88
def _fn_name(): return sys._getframe(1).f_code.co_name
99

10-
from subprocess import Popen, STDOUT, PIPE
10+
##from subprocess import Popen, STDOUT, PIPE
1111
from tempfile import gettempdir
1212
from cStringIO import StringIO
1313
from matplotlib import verbose, __version__, rcParams, get_data_path
@@ -1196,20 +1196,21 @@ def _print_figure_tex(self, outfile, dpi, facecolor, edgecolor, orientation,
11961196
isLandscape = True
11971197
width, height = height, width
11981198
bbox = (lly, llx, ury, urx)
1199-
temp_papertype = _get_papertype(width+1, height+1)
1199+
temp_papertype = _get_papertype(width, height)
12001200
if papertype=='auto':
12011201
papertype = temp_papertype
12021202
paperWidth, paperHeight = papersize[papertype]
12031203
convert_psfrags(tmpfile, renderer.psfrag,
1204-
renderer.texmanager.get_font_preamble(), width+1, height+1,
1204+
renderer.texmanager.get_font_preamble(), width+2, height+2,
12051205
orientation)
12061206

12071207
if rcParams['ps.usedistiller'] == 'ghostscript':
12081208
gs_distill(tmpfile, ext=='.eps', ptype=papertype, bbox=bbox)
12091209
elif rcParams['ps.usedistiller'] == 'xpdf':
12101210
xpdf_distill(tmpfile, ext=='.eps', ptype=papertype, bbox=bbox)
12111211
elif rcParams['text.usetex']:
1212-
gs_distill(tmpfile, ext=='.eps', ptype=papertype, bbox=bbox)
1212+
if False: pass # for debugging
1213+
else: gs_distill(tmpfile, ext=='.eps', ptype=papertype, bbox=bbox)
12131214

12141215
if isinstance(outfile, file):
12151216
fh = file(tmpfile)
@@ -1235,7 +1236,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, paperWidth, paperHeight,
12351236
else: angle = 0
12361237
print >>latexh, r"""\documentclass{article}
12371238
%s
1238-
\usepackage[dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0.5in,0.5in}]{geometry}
1239+
\usepackage[dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0in,0in}]{geometry}
12391240
\usepackage{psfrag}
12401241
\usepackage[dvips]{graphicx}
12411242
\usepackage{color}
@@ -1247,7 +1248,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, paperWidth, paperHeight,
12471248
\includegraphics[angle=%s]{%s}
12481249
\end{figure}
12491250
\end{document}
1250-
"""% (font_preamble, paperWidth, paperHeight, paperWidth-1, paperHeight-1, '\n'.join(psfrags), angle,
1251+
"""% (font_preamble, paperWidth, paperHeight, paperWidth, paperHeight, '\n'.join(psfrags), angle,
12511252
os.path.split(epsfile)[-1])
12521253
latexh.close()
12531254

@@ -1256,23 +1257,27 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, paperWidth, paperHeight,
12561257

12571258
command = 'latex -interaction=nonstopmode "%s"' % latexfile
12581259
verbose.report(command, 'debug-annoying')
1259-
process = Popen(command, shell=True, stderr=STDOUT,
1260-
stdout=PIPE, close_fds=True)
1261-
exit_status = process.wait()
1262-
if exit_status: raise RuntimeError('LaTeX was not able to process \
1263-
your image.\nHere is the full report generated by LaTeX: \
1264-
\n\n' + process.stdout.read())
1265-
else: verbose.report(process.stdout.read(), 'debug-annoying')
1260+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1261+
## exit_status = process.wait()
1262+
## if exit_status: raise RuntimeError('LaTeX was not able to process \
1263+
##your image.\nHere is the full report generated by LaTeX: \
1264+
##\n\n' + process.stdout.read())
1265+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
1266+
stdin, stdout, stderr = os.popen3(command)
1267+
verbose.report(stdout.read(), 'debug-annoying')
1268+
verbose.report(stderr.read(), 'helpful')
12661269

12671270
command = 'dvips -o "%s" "%s"' % (psfile, dvifile)
12681271
verbose.report(command, 'debug-annoying')
1269-
process = Popen(command, shell=True, stderr=STDOUT,
1270-
stdout=PIPE, close_fds=True)
1271-
exit_status = process.wait()
1272-
if exit_status: raise RuntimeError('dvips was not able to process \
1273-
your image.\nHere is the full report generated by dvips: \
1274-
\n\n' + process.stdout.read())
1275-
else: verbose.report(process.stdout.read(), 'debug-annoying')
1272+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1273+
## exit_status = process.wait()
1274+
## if exit_status: raise RuntimeError('dvips was not able to process \
1275+
##your image.\nHere is the full report generated by dvips: \
1276+
##\n\n' + process.stdout.read())
1277+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
1278+
stdin, stdout, stderr = os.popen3(command)
1279+
verbose.report(stdout.read(), 'debug-annoying')
1280+
verbose.report(stderr.read(), 'helpful')
12761281

12771282
shutil.move(psfile, tmpfile)
12781283
for fname in glob.glob(tmpfile+'.*'):
@@ -1295,13 +1300,15 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None):
12951300
command = '%s -dBATCH -dNOPAUSE -r%d -sDEVICE=pswrite %s -sOutputFile="%s" \
12961301
"%s"'% (gs_exe, dpi, paper, outputfile, tmpfile)
12971302
verbose.report(command, 'debug-annoying')
1298-
process = Popen(command, shell=True, stderr=STDOUT,
1299-
stdout=PIPE, close_fds=True)
1300-
exit_status = process.wait()
1301-
if exit_status: raise RuntimeError('ghostscript was not able to process \
1302-
your image.\nHere is the full report generated by ghostscript: \
1303-
\n\n' + process.stdout.read())
1304-
else: verbose.report(process.stdout.read(), 'debug-annoying')
1303+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1304+
## exit_status = process.wait()
1305+
## if exit_status: raise RuntimeError('ghostscript was not able to process \
1306+
##your image.\nHere is the full report generated by ghostscript: \
1307+
##\n\n' + process.stdout.read())
1308+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
1309+
stdin, stdout, stderr = os.popen3(command)
1310+
verbose.report(stdout.read(), 'debug-annoying')
1311+
verbose.report(stderr.read(), 'helpful')
13051312
os.remove(tmpfile)
13061313
shutil.move(outputfile, tmpfile)
13071314
if eps:
@@ -1319,22 +1326,24 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None):
13191326
psfile = tmpfile + '.ps'
13201327
command = 'ps2pdf -sPAPERSIZE=%s "%s" "%s"'% (ptype, tmpfile, pdffile)
13211328
verbose.report(command, 'debug-annoying')
1322-
process = Popen(command, shell=True, stderr=STDOUT,
1323-
stdout=PIPE, close_fds=True)
1324-
exit_status = process.wait()
1325-
if exit_status:
1326-
raise RuntimeError('ps2pdf was not able to process your image.\n\
1327-
Here is the report generated by ghostscript:\n\n' + process.stdout.read())
1328-
else: verbose.report(process.stdout.read(), 'debug-annoying')
1329+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1330+
## exit_status = process.wait()
1331+
## if exit_status:
1332+
## raise RuntimeError('ps2pdf was not able to process your image.\n\
1333+
##Here is the report generated by ghostscript:\n\n' + process.stdout.read())
1334+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
1335+
stdin, stderr = os.popen4(command)
1336+
verbose.report(stderr.read(), 'helpful')
13291337
command = 'pdftops -paper match -level2 "%s" "%s"'% (pdffile, psfile)
13301338
verbose.report(command, 'debug-annoying')
1331-
process = Popen(command, shell=True, stderr=STDOUT,
1332-
stdout=PIPE, close_fds=True)
1333-
exit_status = process.wait()
1334-
if exit_status: raise RuntimeError('pdftops was not able to process \
1335-
your image.\nHere is the full report generated by pdftops: \
1336-
\n\n' + process.stdout.read())
1337-
else: verbose.report(process.stdout.read(), 'debug-annoying')
1339+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1340+
## exit_status = process.wait()
1341+
## if exit_status: raise RuntimeError('pdftops was not able to process \
1342+
##your image.\nHere is the full report generated by pdftops: \
1343+
##\n\n' + process.stdout.read())
1344+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
1345+
stdin, stderr = os.popen4(command)
1346+
verbose.report(stderr.read(), 'helpful')
13381347
os.remove(tmpfile)
13391348
shutil.move(psfile, tmpfile)
13401349
if eps:
@@ -1352,15 +1361,18 @@ def get_bbox(tmpfile, bbox):
13521361
else: gs_exe = 'gs'
13531362
command = '%s -dBATCH -dNOPAUSE -sDEVICE=bbox "%s"' % (gs_exe, tmpfile)
13541363
verbose.report(command, 'debug-annoying')
1355-
process = Popen(command, shell=True, stderr=STDOUT,
1356-
stdout=PIPE, close_fds=True)
1357-
exit_status = process.wait()
1358-
if exit_status: raise RuntimeError('ghostscript was not able to determine \
1359-
the bounding box for your image.\nHere is the full report generated by \
1360-
ghostscript: \n\n' + process.stdout.read())
1361-
else:
1362-
bbox_info = process.stdout.read()
1363-
verbose.report(bbox_info, 'debug')
1364+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
1365+
## exit_status = process.wait()
1366+
## if exit_status: raise RuntimeError('ghostscript was not able to determine \
1367+
##the bounding box for your image.\nHere is the full report generated by \
1368+
##ghostscript: \n\n' + process.stdout.read())
1369+
## else:
1370+
## bbox_info = process.stdout.read()
1371+
## verbose.report(bbox_info, 'debug')
1372+
stdin, stdout, stderr = os.popen3(command)
1373+
verbose.report(stdout.read(), 'debug-annoying')
1374+
bbox_info = stderr.read()
1375+
verbose.report(bbox_info, 'helpful')
13641376
l, b, r, t = [float(i) for i in bbox_info.split()[-4:]]
13651377

13661378
# this is a hack to deal with the fact that ghostscript does not return the

lib/matplotlib/texmanager.py

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"""
3535

3636
import glob, md5, os, shutil, sys, warnings
37-
from subprocess import Popen, STDOUT, PIPE
37+
##from subprocess import Popen, STDOUT, PIPE
3838
from matplotlib import get_configdir, get_home, get_data_path, \
3939
rcParams, verbose
4040
from matplotlib._image import readpng
@@ -185,14 +185,18 @@ def make_dvi(self, tex, fontsize, force=0):
185185

186186
if force or not os.path.exists(dvifile):
187187
command = self.get_tex_command(tex, fname, fontsize)
188+
## verbose.report(command, 'debug-annoying')
189+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
190+
## exit_status = process.wait()
191+
## if exit_status: raise RuntimeError('LaTeX was not able to process \
192+
##the flowing string:\n%s\nHere is the full report generated by LaTeX: \
193+
##\n\n'% tex + process.stdout.read())
194+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
188195
verbose.report(command, 'debug-annoying')
189-
process = Popen(command, shell=True, stderr=STDOUT,
190-
stdout=PIPE, close_fds=True)
191-
exit_status = process.wait()
192-
if exit_status: raise RuntimeError('LaTeX was not able to process \
193-
the flowing string:\n%s\nHere is the full report generated by LaTeX: \
194-
\n\n'% tex + process.stdout.read())
195-
else: verbose.report(process.stdout.read(), 'debug-annoying')
196+
stdin, stdout, stderr = os.popen3(command)
197+
verbose.report(stdout.read(), 'debug-annoying')
198+
err = stderr.read()
199+
if err: verbose.report(err, 'helpful')
196200

197201
# tex will put it's output in the current dir if possible, and
198202
# if not in TEXMFOUTPUT. So check for existence in current
@@ -223,13 +227,16 @@ def make_png(self, tex, fontsize, dpi, force=0):
223227
# see get_rgba for a discussion of the background
224228
if force or not os.path.exists(pngfile):
225229
verbose.report(command, 'debug-annoying')
226-
process = Popen(command, shell=True, stderr=STDOUT,
227-
stdout=PIPE, close_fds=True)
228-
exit_status = process.wait()
229-
if exit_status: raise RuntimeError('dvipng was not able to \
230-
process the flowing file:\n%s\nHere is the full report generated by dvipng: \
231-
\n\n'% dvifile + process.stdout.read())
232-
else: verbose.report(process.stdout.read(), 'debug-annoying')
230+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
231+
## exit_status = process.wait()
232+
## if exit_status: raise RuntimeError('dvipng was not able to \
233+
##process the flowing file:\n%s\nHere is the full report generated by dvipng: \
234+
##\n\n'% dvifile + process.stdout.read())
235+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
236+
stdin, stdout, stderr = os.popen3(command)
237+
verbose.report(stdout.read(), 'debug-annoying')
238+
err = stderr.read()
239+
if err: verbose.report(err, 'helpful')
233240
return pngfile
234241

235242
def make_ps(self, tex, fontsize, force=0):
@@ -241,13 +248,17 @@ def make_ps(self, tex, fontsize, force=0):
241248

242249
if not os.path.exists(psfile):
243250
command = 'dvips -q -E -o "%s" "%s"'% (psfile, dvifile)
244-
process = Popen(command, shell=True, stderr=STDOUT,
245-
stdout=PIPE, close_fds=True)
246-
exit_status = process.wait()
247-
if exit_status: raise RuntimeError('dvips was not able to process \
248-
the flowing file:\n%s\nHere is the full report generated by dvips: \
249-
\n\n'% dvifile + process.stdout.read())
250-
else: verbose.report(process.stdout.read(), 'debug-annoying')
251+
## process = Popen([command], shell=True, stdout=PIPE, stderr=STDOUT)
252+
## exit_status = process.wait()
253+
## if exit_status: raise RuntimeError('dvips was not able to process \
254+
##the flowing file:\n%s\nHere is the full report generated by dvips: \
255+
##\n\n'% dvifile + process.stdout.read())
256+
## else: verbose.report(process.stdout.read(), 'debug-annoying')
257+
verbose.report(command, 'debug-annoying')
258+
stdin, stdout, stderr = os.popen3(command)
259+
verbose.report(stdout.read(), 'debug-annoying')
260+
err = stderr.read()
261+
if err: verbose.report(err, 'helpful')
251262

252263
return psfile
253264

@@ -400,13 +411,14 @@ def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0,0,0)):
400411

401412
def get_dvipng_version(self):
402413
if self.dvipngVersion is not None: return self.dvipngVersion
403-
process = Popen('dvipng --version', shell=True, stderr=PIPE,
404-
stdout=PIPE, close_fds=True, universal_newlines=True)
405-
exit_status = process.wait()
406-
if exit_status: raise RuntimeError('Could not obtain dvipng version\n\
407-
\n\n' + process.stdout.read())
408-
else: sout = process.stdout.read()
409-
for line in sout.split('\n'):
414+
## process = Popen('dvipng --version', shell=True, stderr=PIPE,stdout=PIPE)
415+
## exit_status = process.wait()
416+
## if exit_status: raise RuntimeError('Could not obtain dvipng version\n\
417+
##\n\n' + process.stdout.read())
418+
## else: sout = process.stdout.read()
419+
## for line in sout.split('\n'):
420+
sin, sout = os.popen2('dvipng --version')
421+
for line in sout.readlines():
410422
if line.startswith('dvipng '):
411423
self.dvipngVersion = line.split()[-1]
412424
verbose.report('Found dvipng version %s'% self.dvipngVersion,

0 commit comments

Comments
 (0)