code: def _gs_version_in_path_key(path: Path) -> tuple[str, Version | None]:
      """Key function for comparing Ghostscript and Tesseract paths.
  
      Ghostscript installs on Windows:
          %PROGRAMFILES%/gs/gs9.56.1/bin -> ('gs', Version('9.56.1'))
          %PROGRAMFILES%/gs/9.24/bin -> ('gs', Version('9.24'))
  
      Tesseract looks like:
          %PROGRAMFILES%/Tesseract-OCR -> ('Tesseract-OCR', None)
  
      Thus ensuring the resulting tuple will order the alternatives correctly,
      e.g. gs10.0 > gs9.99.
      """
      match = re.search(r"gs[/\\]?([0-9.]+)[/\\]bin", str(path))
      if match:
          try:
              version_str = match.group(1)
              version = Version(version_str)
              return "gs", version
          except InvalidVersion:
              pass
      return path.name, None
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import shutil
  import sys
  from collections.abc import Iterable, Iterator
  from itertools import chain
  from pathlib import Path
  from typing import Any, Callable, TypeVar
  from packaging.version import InvalidVersion, Version
label_desc: Use image node_id 7 for calling a global function with example usage: _gs_version_in_path_key(path) and returns: path,  None, str,  version