8000 Merge pull request #14663 from ivanov/manual-backport-pr-14636-on-v3.1.x · matplotlib/matplotlib@b341b4e · GitHub
[go: up one dir, main page]

Skip to content

Commit b341b4e

Browse files
authored
Merge pull request #14663 from ivanov/manual-backport-pr-14636-on-v3.1.x
Backport PR #14636 on branch v3.1.x: (Don't capture stderr in _check_and_log_subprocess.)
2 parents 52d3ae7 + 0a223fc commit b341b4e

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,24 +2114,28 @@ def _unmultiplied_rgba8888_to_premultiplied_argb32(rgba8888):
21142114

21152115
def _check_and_log_subprocess(command, logger, **kwargs):
21162116
"""
2117-
Run *command* using `subprocess.check_output`. If it succeeds, return the
2118-
output (stdout and stderr); if not, raise an exception whose text includes
2119-
the failed command and captured output. Both the command and the output
2120-
are logged at DEBUG level on *logger*.
2117+
Run *command*, returning its stdout output if it succeeds.
2118+
2119+
If it fails (exits with nonzero return code), raise an exception whose text
2120+
includes the failed command and captured stdout and stderr output.
2121+
2122+
Regardless of the return code, the command is logged at DEBUG level on
2123+
*logger*. In case of success, the output is likewise logged.
21212124
"""
2122-
logger.debug(command)
2123-
try:
2124-
report = subprocess.check_output(
2125-
command, stderr=subprocess.STDOUT, **kwargs)
2126-
except subprocess.CalledProcessError as exc:
2125+
logger.debug('%s', str(command))
2126+
proc = subprocess.run(
2127+
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
2128+
if proc.returncode:
21272129
raise RuntimeError(
2128-
'The command\n'
2129-
' {}\n'
2130-
'failed and generated the following output:\n'
2131-
'{}'
2132-
.format(command, exc.output.decode('utf-8')))
2133-
logger.debug(report)
2134-
return report
2130+
f"The command\n"
2131+
f" {str(command)}\n"
2132+
f"failed and generated the following output:\n"
2133+
f"{proc.stdout.decode('utf-8')}\n"
2134+
f"and the following error:\n"
2135+
f"{proc.stderr.decode('utf-8')}")
2136+
logger.debug("stdout:\n%s", proc.stdout)
2137+
logger.debug("stderr:\n%s", proc.stderr)
2138+
return proc.stdout
21352139

21362140

21372141
def _check_not_matrix(**kwargs):

0 commit comments

Comments
 (0)
0