(args, regex, min_ver=None, ignore_exit_code=False)
| 396 | """ |
| 397 | |
| 398 | def impl(args, regex, min_ver=None, ignore_exit_code=False): |
| 399 | # Execute the subprocess specified by args; capture stdout and stderr. |
| 400 | # Search for a regex match in the output; if the match succeeds, the |
| 401 | # first group of the match is the version. |
| 402 | # Return an _ExecInfo if the executable exists, and has a version of |
| 403 | # at least min_ver (if set); else, raise ExecutableNotFoundError. |
| 404 | try: |
| 405 | output = subprocess.check_output( |
| 406 | args, stderr=subprocess.STDOUT, |
| 407 | text=True, errors="replace", timeout=30) |
| 408 | except subprocess.CalledProcessError as _cpe: |
| 409 | if ignore_exit_code: |
| 410 | output = _cpe.output |
| 411 | else: |
| 412 | raise ExecutableNotFoundError(str(_cpe)) from _cpe |
| 413 | except subprocess.TimeoutExpired as _te: |
| 414 | msg = f"Timed out running {cbook._pformat_subprocess(args)}" |
| 415 | raise ExecutableNotFoundError(msg) from _te |
| 416 | except OSError as _ose: |
| 417 | raise ExecutableNotFoundError(str(_ose)) from _ose |
| 418 | match = re.search(regex, output) |
| 419 | if match: |
| 420 | raw_version = match.group(1) |
| 421 | version = parse_version(raw_version) |
| 422 | if min_ver is not None and version < parse_version(min_ver): |
| 423 | raise ExecutableNotFoundError( |
| 424 | f"You have {args[0]} version {version} but the minimum " |
| 425 | f"version supported by Matplotlib is {min_ver}") |
| 426 | return _ExecInfo(args[0], raw_version, version) |
| 427 | else: |
| 428 | raise ExecutableNotFoundError( |
| 429 | f"Failed to determine the version of {args[0]} from " |
| 430 | f"{' '.join(args)}, which output {output}") |
| 431 | |
| 432 | if name in os.environ.get("_MPLHIDEEXECUTABLES", "").split(","): |
| 433 | raise ExecutableNotFoundError(f"{name} was hidden") |
no test coverage detected
searching dependent graphs…