code: def check_external_program(
      *,
      program: str,
      package: str,
      version_checker: Callable[[], Version],
      need_version: str | Version,
      required_for: str | None = None,
      recommended: bool = False,
      version_parser: type[Version] = Version,
  ) -> None:
      """Check for required version of external program and raise exception if not.
  
      Args:
          program: The name of the program to test.
          package: The name of a software package that typically supplies this program.
              Usually the same as program.
          version_checker: A callable without arguments that retrieves the installed
              version of program.
          need_version: The minimum required version.
          required_for: The name of an argument of feature that requires this program.
          recommended: If this external program is recommended, instead of raising
              an exception, log a warning and allow execution to continue.
          version_parser: A class that should be used to parse and compare version
              numbers. Used when version numbers do not follow standard conventions.
      """
      if not isinstance(need_version, Version):
          need_version = version_parser(need_version)
      try:
          found_version = version_checker()
      except (CalledProcessError, FileNotFoundError) as e:
          _error_missing_program(
              program, package, required_for, recommended
          )
          if not recommended:
              raise MissingDependencyError(program) from e
          return
      except MissingDependencyError:
          _error_missing_program(
              program, package, required_for, recommended
          )
          if not recommended:
              raise
          return
  
      if found_version and found_version < need_version:
          _error_old_version(
              program,
              package,
              str(need_version),
              str(found_version),
              required_for,
          )
          if not recommended:
              raise MissingDependencyError(program)
  
      log.debug("Found %s %s", program, found_version)
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import sys
  from collections.abc import Mapping, Sequence
  from contextlib import suppress
  from pathlib import Path
  from subprocess import PIPE, STDOUT, CalledProcessError, CompletedProcess, Popen
  from subprocess import run
  from typing import Callable, Union
  from packaging.version import Version
  from ocrmypdf.exceptions import MissingDependencyError
label_desc: Use image node_id 9 for calling a global function with example usage: check_external_program() without return types