code: def _patch_import():
      """
      Enhance relative import statements in config files, so that they:
      1. locate files purely based on relative location, regardless of packages.
         e.g. you can import file without having __init__
      2. do not cache modules globally; modifications of module states has no side effect
      3. support other storage system through PathManager, so config files can be in the cloud
      4. imported dict are turned into omegaconf.DictConfig automatically
      """
      old_import = builtins.__import__
  
      def find_relative_file(
          original_file, relative_import_path, level
      ):
          # NOTE: "from . import x" is not handled. Because then it's unclear
          # if such import should produce `x` as a python module or DictConfig.
          # This can be discussed further if needed.
          relative_import_err = """
  Relative import of directories is not allowed within config files.
  Within a config file, relative import can only import other config files.
  """.replace(
              "\n", " "
          )
          if not len(relative_import_path):
              raise ImportError(relative_import_err)
  
          cur_file = os.path.dirname(original_file)
          for _ in range(level - 1):
              cur_file = os.path.dirname(cur_file)
          cur_name = relative_import_path.lstrip(".")
          for part in cur_name.split("."):
              cur_file = os.path.join(cur_file, part)
          if not cur_file.endswith(".py"):
              cur_file += ".py"
          if not PathManager.isfile(cur_file):
              cur_file_no_suffix = cur_file[: -len(".py")]
              if PathManager.isdir(cur_file_no_suffix):
                  raise ImportError(
                      f"Cannot import from {cur_file_no_suffix}."
                      + relative_import_err
                  )
              else:
                  raise ImportError(
                      f"Cannot import name {relative_import_path} from "
                      f"{original_file}: {cur_file} does not exist."
                  )
          return cur_file
  
      def new_import(
          name, globals=None, locals=None, fromlist=(), level=0
      ):
          if (
              # Only deal with relative imports inside config files
              level != 0
              and globals is not None
              and (globals.get("__package__", "") or "").startswith(
                  _CFG_PACKAGE_NAME
              )
          ):
              cur_file = find_relative_file(
                  globals["__file__"], name, level
              )
              _validate_py_syntax(cur_file)
              spec = importlib.machinery.ModuleSpec(
                  _random_package_name(cur_file), None, origin=cur_file
              )
              module = importlib.util.module_from_spec(spec)
              module.__file__ = cur_file
              with PathManager.open(cur_file) as f:
                  content = f.read()
              exec(compile(content, cur_file, "exec"), module.__dict__)
              for (
                  name
              ) in (
                  fromlist
              ):  # turn imported dict into DictConfig automatically
                  val = _cast_to_config(module.__dict__[name])
                  module.__dict__[name] = val
              return module
          return old_import(
              name, globals, locals, fromlist=fromlist, level=level
          )
  
      builtins.__import__ = new_import
      yield new_import
      builtins.__import__ = old_import
  
imports: import ast
  import builtins
  import collections.abc
  import importlib
  import inspect
  import logging
  import os
  import uuid
  from contextlib import contextmanager
  from copy import deepcopy
  from dataclasses import is_dataclass
  from typing import List, Tuple, Union
  import cloudpickle
  import yaml
  from omegaconf import DictConfig, ListConfig, OmegaConf, SCMode
  from detectron2.utils.file_io import PathManager
  from detectron2.utils.registry import _convert_target_to_string
label_desc: Use image node_id 5 for calling a global function with example usage: _patch_import() and returns: cur_file, old_import, module