diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index d607c4940362..066633d47601 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -354,7 +354,8 @@ def _run(self): # movie file. *args* returns the sequence of command line arguments # from a few configuration options. command = self._args() - _log.info('MovieWriter.run: running command: %s', command) + _log.info('MovieWriter._run: running command: %s', + cbook._pformat_subprocess(command)) PIPE = subprocess.PIPE self._proc = subprocess.Popen( command, stdin=PIPE, stdout=PIPE, stderr=PIPE, diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index bb59960ff57e..bbeb82b18f1a 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -19,6 +19,7 @@ import os from pathlib import Path import re +import shlex import subprocess import sys import time @@ -2119,6 +2120,12 @@ def _unmultiplied_rgba8888_to_premultiplied_argb32(rgba8888): return argb32 +def _pformat_subprocess(command): + """Pretty-format a subprocess command for printing/logging purposes.""" + return (command if isinstance(command, str) + else " ".join(shlex.quote(os.fspath(arg)) for arg in command)) + + def _check_and_log_subprocess(command, logger, **kwargs): """ Run *command* using `subprocess.check_output`. If it succeeds, return the @@ -2126,7 +2133,7 @@ def _check_and_log_subprocess(command, logger, **kwargs): the failed command and captured output. Both the command and the output are logged at DEBUG level on *logger*. """ - logger.debug(command) + logger.debug('%s', _pformat_subprocess(command)) try: report = subprocess.check_output( command, stderr=subprocess.STDOUT, **kwargs) @@ -2136,7 +2143,7 @@ def _check_and_log_subprocess(command, logger, **kwargs): ' {}\n' 'failed and generated the following output:\n' '{}' - .format(command, exc.output.decode('utf-8'))) + .format(_pformat_subprocess(command), exc.output.decode('utf-8'))) logger.debug(report) return report diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 0b1773bd5648..c970526976bc 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -297,7 +297,7 @@ def make_tex_preview(self, tex, fontsize): return texfile def _run_checked_subprocess(self, command, tex): - _log.debug(command) + _log.debug(cbook._pformat_subprocess(command)) try: report = subprocess.check_output(command, cwd=self.texcache,