code: def load_legacy_plugin(plugin, plugin_paths):
      if "." in plugin:
          # it is in a package, try to resolve package first
          package, _, _ = plugin.rpartition(".")
          load_legacy_plugin(package, plugin_paths)
  
      # Try to find plugin in PLUGIN_PATHS
      spec = importlib.machinery.PathFinder.find_spec(
          plugin, plugin_paths
      )
      if spec is None:
          # If failed, try to find it in normal importable locations
          spec = importlib.util.find_spec(plugin)
      if spec is None:
          raise ImportError(f"Cannot import plugin `{plugin}`")
      else:
          # Avoid loading the same plugin twice
          if spec.name in sys.modules:
              return sys.modules[spec.name]
          # create module object from spec
          mod = importlib.util.module_from_spec(spec)
          # place it into sys.modules cache
          # necessary if module imports itself at some point (e.g. packages)
          sys.modules[spec.name] = mod
          try:
              # try to execute it inside module object
              spec.loader.exec_module(mod)
          except Exception:  # problem with import
              try:
                  # remove module from sys.modules since it can't be loaded
                  del sys.modules[spec.name]
              except KeyError:
                  pass
              raise
  
          # if all went well, we have the plugin module
          return mod
  
file_path: pelican/pelican/plugins/_utils.py
imports: import importlib
  import importlib.machinery
  import importlib.util
  import inspect
  import logging
  import pkgutil
  import sys
label_desc: Use image node_id 5 for calling a global function with example usage: load_legacy_plugin(plugin, plugin_paths) and returns: mod, sys