From acd84c81233c10c25ba5602753e11e1554e241f3 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 24 Sep 2018 20:40:17 +0200 Subject: [PATCH] Handle utf-8 output by kpathsea on Windows. --- lib/matplotlib/dviread.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index b1bd6392e637..f064113adae5 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -29,7 +29,7 @@ import numpy as np -from matplotlib import rcParams +from matplotlib import cbook, rcParams _log = logging.getLogger(__name__) @@ -990,6 +990,8 @@ def find_tex_file(filename, format=None): kpathsea. It is also available as part of MikTeX, a popular distribution on Windows. + *If the file is not found, an empty string is returned*. + Parameters ---------- filename : string or bytestring @@ -1015,11 +1017,16 @@ def find_tex_file(filename, format=None): if format is not None: cmd += ['--format=' + format] cmd += [filename] - _log.debug('find_tex_file(%s): %s', filename, cmd) - pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE) - result = pipe.communicate()[0].rstrip() - _log.debug('find_tex_file result: %s', result) - return result.decode('ascii') + try: # Below: strip final newline. + result = cbook._check_and_log_subprocess(cmd, _log)[:-1] + except RuntimeError: + return '' + if os.name == 'nt': + # On Windows only, kpathsea appears to use utf-8 output(?); see + # __win32_fputs in the kpathsea sources and mpl issue #11848. + return result.decode('utf-8') + else: + return os.fsdecode(result) @lru_cache()