Skip to content

Commit

Permalink
Merge pull request matplotlib#17258 from anntzer/texlog
Browse files Browse the repository at this point in the history
Improve info logged by tex subsystem.
  • Loading branch information
timhoffm authored Apr 29, 2020
2 parents 5455bab + de6d073 commit c7894e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
16 changes: 12 additions & 4 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2133,15 +2133,23 @@ def _check_and_log_subprocess(command, logger, **kwargs):
proc = subprocess.run(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
if proc.returncode:
stdout = proc.stdout
if isinstance(stdout, bytes):
stdout = stdout.decode()
stderr = proc.stderr
if isinstance(stderr, bytes):
stderr = stderr.decode()
raise RuntimeError(
f"The command\n"
f" {_pformat_subprocess(command)}\n"
f"failed and generated the following output:\n"
f"{proc.stdout.decode('utf-8')}\n"
f"{stdout}\n"
f"and the following error:\n"
f"{proc.stderr.decode('utf-8')}")
logger.debug("stdout:\n%s", proc.stdout)
logger.debug("stderr:\n%s", proc.stderr)
f"{stderr}")
if proc.stdout:
logger.debug("stdout:\n%s", proc.stdout)
if proc.stderr:
logger.debug("stderr:\n%s", proc.stderr)
return proc.stdout


Expand Down
14 changes: 7 additions & 7 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pathlib import Path
import re
import struct
import sys
import textwrap

import numpy as np
Expand Down Expand Up @@ -1067,9 +1068,11 @@ def find_tex_file(filename, format=None):
# 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 Matplotlib issue #11848.
kwargs = dict(env=dict(os.environ, command_line_encoding='utf-8'))
else:
kwargs = {}
kwargs = {'env': {**os.environ, 'command_line_encoding': 'utf-8'},
'encoding': 'utf-8'}
else: # On POSIX, run through the equivalent of os.fsdecode().
kwargs = {'encoding': sys.getfilesystemencoding(),
'errors': 'surrogatescape'}

cmd = ['kpsewhich']
if format is not None:
Expand All @@ -1079,10 +1082,7 @@ def find_tex_file(filename, format=None):
result = cbook._check_and_log_subprocess(cmd, _log, **kwargs)
except RuntimeError:
return ''
if os.name == 'nt':
return result.decode('utf-8').rstrip('\r\n')
else:
return os.fsdecode(result).rstrip('\n')
return result.rstrip('\n')


@lru_cache()
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def get_font_config(self):
font_family, font, self.font_info[font.lower()])
break
else:
_log.debug('%s font is not compatible with usetex.',
font_family)
_log.debug('%s font is not compatible with usetex.', font)
else:
_log.info('No LaTeX-compatible font found for the %s font '
'family in rcParams. Using default.', font_family)
Expand Down

0 comments on commit c7894e5

Please sign in to comment.