code: def _import_module(
      name: str, file_dir: str | None = None
  ) -> ModuleType:
      """Imports module and extract preload interface functions.
  
      Import modules specified by name and extract 'dask_setup'
      and 'dask_teardown' if present.
  
      Parameters
      ----------
      name : str
          Module name, file path, or text of module or script
      file_dir : string
          Path of a directory where files should be copied
  
      Returns
      -------
      Nest dict of names to extracted module interface components if present
      in imported module.
      """
      if name.endswith(".py"):
          # name is a file path
          if file_dir is not None:
              basename = os.path.basename(name)
              copy_dst = os.path.join(file_dir, basename)
              if os.path.exists(copy_dst):
                  if not filecmp.cmp(name, copy_dst):
                      logger.error("File name collision: %s", basename)
              shutil.copy(name, copy_dst)
              module = import_file(copy_dst)[0]
          else:
              module = import_file(name)[0]
  
      elif " " not in name:
          # name is a module name
          if name not in sys.modules:
              import_module(name)
          module = sys.modules[name]
  
      else:
          # not a name, actually the text of the script
          with tmpfile(extension=".py") as fn:
              with open(fn, mode="w") as f:
                  f.write(name)
              return _import_module(fn, file_dir=file_dir)
  
      logger.info("Import preload module: %s", name)
      return module
  
imports: from __future__ import annotations
  import filecmp
  import inspect
  import logging
  import os
  import shutil
  import sys
  from collections.abc import Iterable, Sequence
  from importlib import import_module
  from types import ModuleType
  from typing import TYPE_CHECKING, cast
  import click
  from dask.utils import tmpfile
  from distributed.core import Server
  from distributed.utils import import_file
label_desc: Use image node_id 3 for calling a global function with example usage: _import_module(name, file_dir) and returns: module, _import_module