Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6fd8b5b

Browse files
committed
dviread: find_tex_file: Ensure the encoding on windows
1 parent 7bcf618 commit 6fd8b5b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/matplotlib/dviread.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,17 +1013,23 @@ 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]
10201028
try: # Below: strip final newline.
1021-
result = cbook._check_and_log_subprocess(cmd, _log)[:-1]
1029+
result = cbook._check_and_log_subprocess(cmd, _log, **kwargs)[:-1]
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.
10271033
return result.decode('utf-8')
10281034
else:
10291035
return os.fsdecode(result)

0 commit comments

Comments
 (0)