code: def get_version(
      program: str,
      *,
      version_arg: str = "--version",
      regex=r"(\d+(\.\d+)*)",
      env: OsEnviron | None = None,
  ) -> str:
      """Get the version of the specified program.
  
      Arguments:
          program: The program to version check.
          version_arg: The argument needed to ask for its version, e.g. ``--version``.
          regex: A regular expression to parse the program's output and obtain the
              version.
          env: Custom ``os.environ`` in which to run program.
      """
      args_prog = [program, version_arg]
      try:
          proc = run(
              args_prog,
              close_fds=True,
              text=True,
              stdout=PIPE,
              stderr=STDOUT,
              check=True,
              env=env,
          )
          output: str = proc.stdout
      except FileNotFoundError as e:
          raise MissingDependencyError(
              f"Could not find program '{program}' on the PATH"
          ) from e
      except CalledProcessError as e:
          if e.returncode != 0:
              raise MissingDependencyError(
                  f"Ran program '{program}' but it exited with an error:\n{e.output}"
              ) from e
          raise MissingDependencyError(
              f"Could not find program '{program}' on the PATH"
          ) from e
  
      match = re.match(regex, output.strip())
      if not match:
          raise MissingDependencyError(
              f"The program '{program}' did not report its version. "
              f"Message was:\n{output}"
          )
      version = match.group(1)
  
      return 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 4 for calling a global function with example usage: get_version(program) and returns: version