From 36339eb03c82073a44dd83d3cd0e01aa024b981d Mon Sep 17 00:00:00 2001 From: Cong Ma Date: Fri, 31 May 2019 10:50:50 +0200 Subject: [PATCH 1/2] MAINT: work around non-zero exit status of "pdftops -v" command. In the function responsible for probing the presence of external command ("_get_executable_info"), add an optional argument "ignore_error" (default False). If set to True, the external command is allowed to exit with non-zero status, and the content of the output is used anyway. This works around the problem with certain xpdf versions where the exit status of "pdftops -v" command is nonzero. Compatibility is maintained because the optional argument defaults to False which doesn't introduce any new behaviour. --- 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 a367dd729f9f..bb03c76d11ca 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -314,14 +314,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_error=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_error: + output = _cpe.output + else: + raise _cpe match = re.search(regex, output) if match: version = LooseVersion(match.group(1)) @@ -378,7 +384,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_error=True) if info and not ("3.0" <= info.version # poppler version numbers. or "0.9" <= info.version <= "1.0"): From ad5ffed6953f5bee27b0fb4f91c0555f4bcb56dc Mon Sep 17 00:00:00 2001 From: Cong Ma Date: Sun, 2 Jun 2019 11:56:13 +0200 Subject: [PATCH 2/2] MAINT: use more descriptive argument name. The optional argument "ignore_error" is changed to "ignore_exit_code" based on the suggestion of @timhoffm. --- lib/matplotlib/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index bb03c76d11ca..eec1e6373c7b 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -314,7 +314,7 @@ def _get_executable_info(name): If the executable is not one that we know how to query. """ - def impl(args, regex, min_ver=None, ignore_error=False): + 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. @@ -324,7 +324,7 @@ def impl(args, regex, min_ver=None, ignore_error=False): output = subprocess.check_output( args, stderr=subprocess.STDOUT, universal_newlines=True) except subprocess.CalledProcessError as _cpe: - if ignore_error: + if ignore_exit_code: output = _cpe.output else: raise _cpe @@ -385,7 +385,7 @@ def impl(args, regex, min_ver=None, ignore_error=False): return impl([path, "--version"], r"^Version: ImageMagick (\S*)") elif name == "pdftops": info = impl(["pdftops", "-v"], "^pdftops version (.*)", - ignore_error=True) + ignore_exit_code=True) if info and not ("3.0" <= info.version # poppler version numbers. or "0.9" <= info.version <= "1.0"):