From 6fd8b5b7d2fb892f3f9f7474385801827ae71d92 Mon Sep 17 00:00:00 2001 From: Nikita Kniazev Date: Sun, 30 Sep 2018 15:49:07 +0300 Subject: [PATCH 1/2] dviread: find_tex_file: Ensure the encoding on windows --- lib/matplotlib/dviread.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index f064113adae5..6a642c5d25fc 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -1013,17 +1013,23 @@ def find_tex_file(filename, format=None): if isinstance(format, bytes): format = format.decode('utf-8', errors='replace') + if os.name == 'nt': + # On Windows only, kpathsea can use utf-8 for cmd args and output. + # The `command_line_encoding` environment variable is set to force it + # to always use utf-8 encoding. See mpl issue #11848 for more info. + kwargs = dict(env=dict(os.environ, command_line_encoding='utf-8')) + else: + kwargs = {} + cmd = ['kpsewhich'] if format is not None: cmd += ['--format=' + format] cmd += [filename] try: # Below: strip final newline. - result = cbook._check_and_log_subprocess(cmd, _log)[:-1] + result = cbook._check_and_log_subprocess(cmd, _log, **kwargs)[:-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) From 022934882b8ec806dc41e94db4567bbb2b27b322 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 1 Oct 2018 13:46:25 +0200 Subject: [PATCH 2/2] Fix stripping of CRLF on Windows. --- lib/matplotlib/dviread.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 6a642c5d25fc..5f6054079016 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -1025,14 +1025,14 @@ def find_tex_file(filename, format=None): if format is not None: cmd += ['--format=' + format] cmd += [filename] - try: # Below: strip final newline. - result = cbook._check_and_log_subprocess(cmd, _log, **kwargs)[:-1] + try: + result = cbook._check_and_log_subprocess(cmd, _log, **kwargs) except RuntimeError: return '' if os.name == 'nt': - return result.decode('utf-8') + return result.decode('utf-8').rstrip('\r\n') else: - return os.fsdecode(result) + return os.fsdecode(result).rstrip('\n') @lru_cache()