Skip to content

Commit 269dabc

Browse files
authored
Merge pull request #7572 from tomspur/subprocesses
MNT: Overhaul external process calls
2 parents b2ee7a3 + d579266 commit 269dabc

File tree

8 files changed

+182
-228
lines changed

8 files changed

+182
-228
lines changed

doc/make.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,9 @@ def latex():
172172
raise SystemExit("Building LaTeX failed.")
173173

174174
# Produce pdf.
175-
os.chdir('build/latex')
176-
177175
# Call the makefile produced by sphinx...
178-
if os.system('make'):
179-
raise SystemExit("Rendering LaTeX failed.")
180-
181-
os.chdir('../..')
176+
if subprocess.call("make", cwd="build/latex"):
177+
raise SystemExit("Rendering LaTeX failed with.")
182178
else:
183179
print('latex build has not been tested on windows')
184180

@@ -195,13 +191,9 @@ def texinfo():
195191
raise SystemExit("Building Texinfo failed.")
196192

197193
# Produce info file.
198-
os.chdir('build/texinfo')
199-
200194
# Call the makefile produced by sphinx...
201-
if os.system('make'):
202-
raise SystemExit("Rendering Texinfo failed.")
203-
204-
os.chdir('../..')
195+
if subprocess.call("make", cwd="build/texinfo"):
196+
raise SystemExit("Rendering Texinfo failed with.")
205197
else:
206198
print('texinfo build has not been tested on windows')
207199

examples/pylab_examples/mathtext_examples.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
from __future__ import print_function
55
import matplotlib.pyplot as plt
6-
import os
6+
import subprocess
77
import sys
88
import re
99
import gc
@@ -120,6 +120,6 @@ def doall():
120120
fd.write("\\end{document}\n")
121121
fd.close()
122122

123-
os.system("pdflatex mathtext_examples.ltx")
123+
subprocess.call(["pdflatex", "mathtext_examples.ltx"])
124124
else:
125125
doall()

examples/pylab_examples/movie_demo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import print_function
44

5-
import os
5+
import subprocess
66
import matplotlib.pyplot as plt
77
import numpy as np
88

@@ -22,8 +22,8 @@
2222
files.append(fname)
2323

2424
print('Making movie animation.mpg - this may take a while')
25-
os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o animation.mpg")
26-
#os.system("convert _tmp*.png animation.mng")
25+
subprocess.call("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 -ovc lavc "
26+
"-lavcopts vcodec=wmv2 -oac copy -o animation.mpg", shell=True)
2727

2828
# cleanup
2929
for fname in files:

examples/pylab_examples/stix_fonts_demo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
import os
3+
import subprocess
44
import sys
55
import re
66
import gc
@@ -53,6 +53,6 @@ def doall():
5353
fd.write("\\end{document}\n")
5454
fd.close()
5555

56-
os.system("pdflatex stix_fonts_examples.ltx")
56+
subprocess.call(["pdflatex", "stix_fonts_examples.ltx"])
5757
else:
5858
doall()

examples/tests/backend_driver.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,16 @@ def report_all_missing(directories):
337337
)
338338

339339

340-
try:
341-
import subprocess
342-
343-
def run(arglist):
344-
try:
345-
ret = subprocess.call(arglist)
346-
except KeyboardInterrupt:
347-
sys.exit()
348-
else:
349-
return ret
350-
except ImportError:
351-
def run(arglist):
352-
os.system(' '.join(arglist))
340+
from matplotlib.compat import subprocess
341+
342+
343+
def run(arglist):
344+
try:
345+
ret = subprocess.call(arglist)
346+
except KeyboardInterrupt:
347+
sys.exit()
348+
else:
349+
return ret
353350

354351

355352
def drive(backend, directories, python=['python'], switches=[]):
@@ -420,7 +417,7 @@ def drive(backend, directories, python=['python'], switches=[]):
420417
ret = run(program + [tmpfile_name] + switches)
421418
end_time = time.time()
422419
print("%s %s" % ((end_time - start_time), ret))
423-
#os.system('%s %s %s' % (python, tmpfile_name, ' '.join(switches)))
420+
# subprocess.call([python, tmpfile_name] + switches)
424421
os.remove(tmpfile_name)
425422
if ret:
426423
failures.append(fullpath)

0 commit comments

Comments
 (0)