8000 Merge pull request #12351 from Kojoley/kpswitch-force-utf8-on-windows · matplotlib/matplotlib@8d646e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d646e4

Browse files
authored
Merge pull request #12351 from Kojoley/kpswitch-force-utf8-on-windows
dviread: find_tex_file: Ensure the encoding on windows
2 parents e4608c1 + 0229348 commit 8d646e4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/matplotlib/dviread.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,20 +1013,26 @@ def find_tex_file(filename, format=None):
10131013
if isinstance(format, bytes):
10141014
format = format.decode('utf-8', errors='replace')
10151015

1016+
if os.name == 'nt':
1017+
# On Windows only, kpathsea can use utf-8 for cmd args and output.
1018+
# The `command_line_encoding` environment variable is set to force it
1019+
# to always use utf-8 encoding. See mpl issue #11848 for more info.
1020+
kwargs = dict(env=dict(os.environ, command_line_encoding='utf-8'))
1021+
else:
1022+
kwargs = {}
1023+
10161024
cmd = ['kpsewhich']
10171025
if format is not None:
10181026
cmd += ['--format=' + format]
10191027
cmd += [filename]
1020-
try: # Below: strip final newline.
1021-
result = cbook._check_and_log_subprocess(cmd, _log)[:-1]
1028+
try:
1029+
result = cbook._check_and_log_subprocess(cmd, _log, **kwargs)
10221030
except RuntimeError:
10231031
return ''
10241032
if os.name == 'nt':
1025-
# On Windows only, kpathsea appears to use utf-8 output(?); see
1026-
# __win32_fputs in the kpathsea sources and mpl issue #11848.
1027-
return result.decode('utf-8')
1033+
return result.decode('utf-8').rstrip('\r\n')
10281034
else:
1029-
return os.fsdecode(result)
1035+
return os.fsdecode(result).rstrip('\n')
10301036

10311037

10321038
@lru_cache()

0 commit comments

Comments
 (0)
0