Skip to content

Commit c7894e5

Browse files
authored
Merge pull request #17258 from anntzer/texlog
Improve info logged by tex subsystem.
2 parents 5455bab + de6d073 commit c7894e5

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,15 +2133,23 @@ def _check_and_log_subprocess(command, logger, **kwargs):
21332133
proc = subprocess.run(
21342134
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
21352135
if proc.returncode:
2136+
stdout = proc.stdout
2137+
if isinstance(stdout, bytes):
2138+
stdout = stdout.decode()
2139+
stderr = proc.stderr
2140+
if isinstance(stderr, bytes):
2141+
stderr = stderr.decode()
21362142
raise RuntimeError(
21372143
f"The command\n"
21382144
f" {_pformat_subprocess(command)}\n"
21392145
f"failed and generated the following output:\n"
2140-
f"{proc.stdout.decode('utf-8')}\n"
2146+
f"{stdout}\n"
21412147
f"and the following error:\n"
2142-
f"{proc.stderr.decode('utf-8')}")
2143-
logger.debug("stdout:\n%s", proc.stdout)
2144-
logger.debug("stderr:\n%s", proc.stderr)
2148+
f"{stderr}")
2149+
if proc.stdout:
2150+
logger.debug("stdout:\n%s", proc.stdout)
2151+
if proc.stderr:
2152+
logger.debug("stderr:\n%s", proc.stderr)
21452153
return proc.stdout
21462154

21472155

lib/matplotlib/dviread.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pathlib import Path
2626
import re
2727
import struct
28+
import sys
2829
import textwrap
2930

3031
import numpy as np
@@ -1067,9 +1068,11 @@ def find_tex_file(filename, format=None):
10671068
# On Windows only, kpathsea can use utf-8 for cmd args and output.
10681069
# The `command_line_encoding` environment variable is set to force it
10691070
# to always use utf-8 encoding. See Matplotlib issue #11848.
1070-
kwargs = dict(env=dict(os.environ, command_line_encoding='utf-8'))
1071-
else:
1072-
kwargs = {}
1071+
kwargs = {'env': {**os.environ, 'command_line_encoding': 'utf-8'},
1072+
'encoding': 'utf-8'}
1073+
else: # On POSIX, run through the equivalent of os.fsdecode().
1074+
kwargs = {'encoding': sys.getfilesystemencoding(),
1075+
'errors': 'surrogatescape'}
10731076

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

10871087

10881088
@lru_cache()

lib/matplotlib/texmanager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ def get_font_config(self):
131131
font_family, font, self.font_info[font.lower()])
132132
break
133133
else:
134-
_log.debug('%s font is not compatible with usetex.',
135-
font_family)
134+
_log.debug('%s font is not compatible with usetex.', font)
136135
else:
137136
_log.info('No LaTeX-compatible font found for the %s font '
138137
'family in rcParams. Using default.', font_family)

0 commit comments

Comments
 (0)