Skip to content

Overhaul external process calls #7572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 14, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove precmd from backend_ps and use subprocess
  • Loading branch information
tomspur committed Apr 9, 2017
commit 6d189b39a4ac91e12d5ce7d54dac62f8e264fe35
22 changes: 10 additions & 12 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,20 +1458,17 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
"rcParam.", 'helpful')
raise

# the split drive part of the command is necessary for windows users with
# multiple
if sys.platform == 'win32': precmd = '%s &&'% os.path.splitdrive(tmpdir)[0]
else: precmd = ''
#Replace \\ for / so latex does not think there is a function call
latexfile = latexfile.replace("\\", "/")
# Replace ~ so Latex does not think it is line break
latexfile = latexfile.replace("~", "\\string~")
command = '%s cd "%s" && latex -interaction=nonstopmode "%s" > "%s"'\
%(precmd, tmpdir, latexfile, outfile)
command = [str("latex"), "-interaction=nonstopmode",
'"%s"' % latexfile]
verbose.report(command, 'debug')
try:
output = subprocess.check_output(command, shell=True,
stderr=subprocess.STDOUT)
with open(outfile, "w") as fout:
subprocess.check_call(command, cwd=tmpdir,
stdout=fout, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
with io.open(outfile, 'rb') as fh:
raise RuntimeError('LaTeX was not able to process your file: '
Expand All @@ -1482,12 +1479,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
verbose.report(fh.read(), 'debug')
os.remove(outfile)

command = '%s cd "%s" && dvips -q -R0 -o "%s" "%s" > "%s"'%(precmd, tmpdir,
os.path.split(psfile)[-1], os.path.split(dvifile)[-1], outfile)
command = [str('dvips'), '-q', '-R0', '-o', os.path.basename(psfile),
os.path.basename(dvifile)]
verbose.report(command, 'debug')
try:
output = subprocess.check_output(command, shell=True,
stderr=subprocess.STDOUT)
with open(outfile, "w") as fout:
subprocess.check_call(command, cwd=tmpdir,
stdout=fout, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
with io.open(outfile, 'rb') as fh:
raise RuntimeError('dvips was not able to process the following '
Expand Down