Skip to content

dviread: find_tex_file: Ensure the encoding on windows #12351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,20 +1013,26 @@ 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]
try:
result = cbook._check_and_log_subprocess(cmd, _log, **kwargs)
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')
return result.decode('utf-8').rstrip('\r\n')
else:
return os.fsdecode(result)
return os.fsdecode(result).rstrip('\n')


@lru_cache()
Expand Down