Skip to content

Commit 3b2a36d

Browse files
committed
BUG: fix checkout_output with non-ascii paths in PATH
Closes #7715 This ensures that on python2 the values passed into `check_output` are bytes. If they are passed in as unicode (due to unicode_literals at the top of most of our files) they will cause an exception when there is a path in PATH that has non-ascii values. The reason is that when locating possible executable our input (as unicode) is concatenated with the non-ascii path (as bytes) which then fails to encode as ascii and raises. The other two places we currently use `check_output` (setupext.py and tools/github_stats.py) we do not need this handling as we do not import unicode_iterals in those files.
1 parent 592e509 commit 3b2a36d

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ before_install:
6969
- pip install --upgrade virtualenv
7070
- virtualenv --python=python venv
7171
- source venv/bin/activate
72+
# test with non-ascii in path
73+
- mkdir /tmp/λ
74+
- export PATH=$PATH:/tmp/λ
7275
- export PATH=/usr/lib/ccache:$PATH
7376

7477
install:

lib/matplotlib/backends/backend_pgf.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
# assuming fontconfig is installed and the command 'fc-list' exists
4646
try:
4747
# list scalable (non-bitmap) fonts
48-
fc_list = check_output(['fc-list', ':outline,scalable', 'family'])
48+
fc_list = check_output(str(' '.join(['fc-list',
49+
':outline,scalable', 'family'])))
4950
fc_list = fc_list.decode('utf8')
5051
system_fonts = [f.split(',')[0] for f in fc_list.splitlines()]
5152
system_fonts = list(set(system_fonts))
@@ -179,7 +180,7 @@ def make_pdf_to_png_converter():
179180
tools_available = []
180181
# check for pdftocairo
181182
try:
182-
check_output(["pdftocairo", "-v"], stderr=subprocess.STDOUT)
183+
check_output([str("pdftocairo"), str("-v")], stderr=subprocess.STDOUT)
183184
tools_available.append("pdftocairo")
184185
except:
185186
pass
@@ -194,15 +195,16 @@ def cairo_convert(pdffile, pngfile, dpi):
194195
cmd = ["pdftocairo", "-singlefile", "-png",
195196
"-r %d" % dpi, pdffile, os.path.splitext(pngfile)[0]]
196197
# for some reason this doesn't work without shell
197-
check_output(" ".join(cmd), shell=True, stderr=subprocess.STDOUT)
198+
check_output(str(" ".join(cmd)), shell=True,
199+
stderr=subprocess.STDOUT)
198200
return cairo_convert
199201
elif "gs" in tools_available:
200202
def gs_convert(pdffile, pngfile, dpi):
201-
cmd = [gs, '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
203+
cmd = [str(gs), '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
202204
'-sDEVICE=png16m', '-dUseCIEColor', '-dTextAlphaBits=4',
203205
'-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', '-sOutputFile=%s' % pngfile,
204206
'-r%d' % dpi, pdffile]
205-
check_output(cmd, stderr=subprocess.STDOUT)
207+
check_output(str(" ".join(cmd)), stderr=subprocess.STDOUT)
206208
return gs_convert
207209
else:
208210
raise RuntimeError("No suitable pdf to png renderer found.")
@@ -898,7 +900,7 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
898900
cmdargs = [texcommand, "-interaction=nonstopmode",
899901
"-halt-on-error", "figure.tex"]
900902
try:
901-
check_output(cmdargs, stderr=subprocess.STDOUT, cwd=tmpdir)
903+
check_output(str(' '.join(cmdargs)), stderr=subprocess.STDOUT, cwd=tmpdir)
902904
except subprocess.CalledProcessError as e:
903905
raise RuntimeError("%s was not able to process your file.\n\nFull log:\n%s" % (texcommand, e.output))
904906

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _call_fc_list():
281281
'This may take a moment.'))
282282
timer.start()
283283
try:
284-
out = subprocess.check_output(['fc-list', '--format=%{file}'])
284+
out = subprocess.check_output([str('fc-list'), '--format=%{file}'])
285285
except (OSError, subprocess.CalledProcessError):
286286
return []
287287
finally:

0 commit comments

Comments
 (0)