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

Skip to content

Commit 9f7e624

Browse files
authored
Merge pull request #14041 from anntzer/log-subprocess
ENH: Pretty-format subprocess logs.
2 parents 63ef1a1 + 06a9106 commit 9f7e624

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/matplotlib/animation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def _run(self):
354354
# movie file. *args* returns the sequence of command line arguments
355355
# from a few configuration options.
356356
command = self._args()
357-
_log.info('MovieWriter.run: running command: %s', command)
357+
_log.info('MovieWriter._run: running command: %s',
358+
cbook._pformat_subprocess(command))
358359
PIPE = subprocess.PIPE
359360
self._proc = subprocess.Popen(
360361
command, stdin=PIPE, stdout=PIPE, stderr=PIPE,

lib/matplotlib/cbook/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os
2020
from pathlib import Path
2121
import re
22+
import shlex
2223
import subprocess
2324
import sys
2425
import time
@@ -2119,14 +2120,20 @@ def _unmultiplied_rgba8888_to_premultiplied_argb32(rgba8888):
21192120
return argb32
21202121

21212122

2123+
def _pformat_subprocess(command):
2124+
"""Pretty-format a subprocess command for printing/logging purposes."""
2125+
return (command if isinstance(command, str)
2126+
else " ".join(shlex.quote(os.fspath(arg)) for arg in command))
2127+
2128+
21222129
def _check_and_log_subprocess(command, logger, **kwargs):
21232130
"""
21242131
Run *command* using `subprocess.check_output`. If it succeeds, return the
21252132
output (stdout and stderr); if not, raise an exception whose text includes
21262133
the failed command and captured output. Both the command and the output
21272134
are logged at DEBUG level on *logger*.
21282135
"""
2129-
logger.debug(command)
2136+
logger.debug('%s', _pformat_subprocess(command))
21302137
try:
21312138
report = subprocess.check_output(
21322139
command, stderr=subprocess.STDOUT, **kwargs)
@@ -2136,7 +2143,7 @@ def _check_and_log_subprocess(command, logger, **kwargs):
21362143
' {}\n'
21372144
'failed and generated the following output:\n'
21382145
'{}'
2139-
.format(command, exc.output.decode('utf-8')))
2146+
.format(_pformat_subprocess(command), exc.output.decode('utf-8')))
21402147
logger.debug(report)
21412148
return report
21422149

lib/matplotlib/texmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def make_tex_preview(self, tex, fontsize):
297297
return texfile
298298

299299
def _run_checked_subprocess(self, command, tex):
300-
_log.debug(command)
300+
_log.debug(cbook._pformat_subprocess(command))
301301
try:
302302
report = subprocess.check_output(command,
303303
cwd=self.texcache,

0 commit comments

Comments
 (0)