From eb005efc979d45cc91aa262ec4c607bbcf454849 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 8 Jun 2019 17:20:18 -0400 Subject: [PATCH] Backport PR #14395: MAINT: work around non-zero exit status of "pdftops -v" command. --- lib/matplotlib/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 341d8017d0f0..350d4c554aae 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -313,14 +313,20 @@ def _get_executable_info(name): If the executable is not one that we know how to query. """ - def impl(args, regex, min_ver=None): + def impl(args, regex, min_ver=None, ignore_exit_code=False): # Execute the subprocess specified by args; capture stdout and stderr. # Search for a regex match in the output; if the match succeeds, the # first group of the match is the version. # Return an _ExecInfo if the executable exists, and has a version of # at least min_ver (if set); else, raise FileNotFoundError. - output = subprocess.check_output( - args, stderr=subprocess.STDOUT, universal_newlines=True) + try: + output = subprocess.check_output( + args, stderr=subprocess.STDOUT, universal_newlines=True) + except subprocess.CalledProcessError as _cpe: + if ignore_exit_code: + output = _cpe.output + else: + raise _cpe match = re.search(regex, output) if match: version = LooseVersion(match.group(1)) @@ -377,7 +383,8 @@ def impl(args, regex, min_ver=None): "Failed to find an ImageMagick installation") return impl([path, "--version"], r"^Version: ImageMagick (\S*)") elif name == "pdftops": - info = impl(["pdftops", "-v"], "^pdftops version (.*)") + info = impl(["pdftops", "-v"], "^pdftops version (.*)", + ignore_exit_code=True) if info and not ("3.0" <= info.version # poppler version numbers. or "0.9" <= info.version <= "1.0"):