code: def test_imports(fname, assert_version, update_versions):
      global ERROR
      global ERROR_MSG
      global WARN
      global WARN_MSG
      global PRINT_MSG
      versions_to_update = {}
      msg = f"\nasserting imports work for: {fname}\n\n"
      PRINT_MSG += msg
      ERROR_MSG += msg
      WARN_MSG += msg
      with open(fname, "r") as f:
          file_lines = f.readlines()
      mod_names_n_versions = [parse(req) for req in file_lines]
      for line_num, (
          mod_name,
          expected_version,
          expected_op,
      ) in enumerate(mod_names_n_versions):
          # noinspection PyBroadException
          try:
              mod = importlib.import_module(mod_name)
          except Exception as e:
              ERROR = True
              msg = f"{mod_name} could not be imported: {e}\n"
              ERROR_MSG += msg
              PRINT_MSG += msg
              continue
          # noinspection PyBroadException
          try:
              # noinspection PyUnresolvedReferences
              detected_version = mod.__version__
          except AttributeError:
              try:
                  detected_version = ".".join(
                      [str(n) for n in mod.VERSION]
                  )
              except AttributeError:
                  continue
          except Exception:
              detected_version = None
          if detected_version and expected_version:
              if compare(
                  detected_version, expected_version, expected_op
              ):
                  msg = f"{mod_name} detected correct version: {detected_version}\n"
              else:
                  msg = (
                      f"expected version {expected_version} for module {mod_name}, but"
                      f" detected version {detected_version}\n"
                  )
                  versions_to_update[line_num] = {
                      "expected": expected_version,
                      "detected": detected_version,
                  }
                  if assert_version:
                      ERROR = True
                      ERROR_MSG += msg
                  else:
                      WARN = True
                      WARN_MSG += msg
              PRINT_MSG += msg
          else:
              if detected_version:
                  msg = (
                      f"{mod_name} detected version: {detected_version}, but no expected"
                      " version provided\n"
                  )
              elif expected_version:
                  msg = (
                      f"{mod_name} expected version: {expected_version}, but unable to"
                      " detect version\n"
                  )
              else:
                  msg = (
                      "no expected version provided, and unable to detect version for"
                      f" {mod_name}\n"
                  )
              WARN = True
              PRINT_MSG += msg
              WARN_MSG += msg
      if not update_versions:
          return
      for line_num, versions in versions_to_update.items():
          orig_str = file_lines[line_num]
          new_str = orig_str.replace(
              versions["expected"], versions["detected"]
          )
          file_lines[line_num] = new_str
      with open(fname, "w") as f:
          f.writelines(file_lines)
  
file_path: ivy/scripts/test_dependencies.py
imports: import os
  import argparse
  import termcolor
  import importlib
  import faulthandler
  from packaging import version
label_desc: Use image node_id 3 for calling a global function with example usage: test_imports(fname, assert_version, update_versions) without return types