code: def get_package_info(
      pkgs: Iterable[
          str | tuple[str, Callable[[ModuleType], str | None] | None]
      ]
  ) -> dict[str, str | None]:
      """get package versions for the passed required & optional packages"""
  
      pversions: dict[str, str | None] = {
          "python": ".".join(map(str, sys.version_info))
      }
      for pkg in pkgs:
          if isinstance(pkg, (tuple, list)):
              modname, ver_f = pkg
              if ver_f is None:
                  ver_f = version_of_package
          else:
              modname = pkg
              ver_f = version_of_package
  
          try:
              mod = importlib.import_module(modname)
              pversions[modname] = ver_f(mod)
          except Exception:
              pversions[modname] = None
  
      return pversions
  
file_path: distributed/distributed/versions.py
imports: from __future__ import annotations
  import importlib
  import os
  import platform
  import struct
  import sys
  from collections.abc import Callable, Iterable
  from itertools import chain
  from types import ModuleType
  from typing import Any
  from packaging.requirements import Requirement
label_desc: Use image node_id 4 for calling a global function with example usage: get_package_info(pkgs) and returns: pversions