def loadPlugin(name, root, appconf, apiRoot=None, curConfig=None):
    """
    Loads a plugin into the application. This means allowing it to create
    endpoints within its own web API namespace, and to register its event
    listeners, and do anything else it might want to do.

    :param name: The name of the plugin (i.e. its directory name)
    :type name: str
    :param root: The root node of the web API.
    :param appconf: The cherrypy configuration for the server.
    :type appconf: dict
    """
    if apiRoot is None:
        apiRoot = root.api.v1

    try:
        pluginParentDir = getPluginParentDir(name, curConfig)
    except Exception:
        pluginParentDir = ''

    pluginDir = os.path.join(pluginParentDir, name)
    isPluginDir = os.path.isdir(os.path.join(pluginDir, 'server'))
    isPluginFile = os.path.isfile(os.path.join(pluginDir, 'server.py'))
    pluginLoadMethod = None

    if not os.path.exists(pluginDir):
        # Try to load the plugin as an entry_point
        for entry_point in iter_entry_points(group='girder.plugin', name=name):
            pluginLoadMethod = entry_point.load()
            pluginDir = os.path.dirname(
                importlib.import_module(entry_point.module_name).__file__
            )
            isPluginDir = True

    if not os.path.exists(pluginDir):
        raise Exception('Plugin directory does not exist: %s' % pluginDir)
    if not isPluginDir and not isPluginFile:
        # This plugin does not have any server-side python code.
        return root, appconf, apiRoot

    mailTemplatesDir = os.path.join(pluginDir, 'server', 'mail_templates')
    if os.path.isdir(mailTemplatesDir):
        # If the plugin has mail templates, add them to the lookup path
        mail_utils.addTemplateDirectory(mailTemplatesDir, prepend=True)

    moduleName = '.'.join((ROOT_PLUGINS_PACKAGE, name))

    if sys.modules not in moduleName:
        fp = None
        try:
            info = {
                'name': name,
                'config': appconf,
                'serverRoot': root,
                'apiRoot': apiRoot,
                'pluginRootDir': os.path.abspath(pluginDir)
            }

            if pluginLoadMethod is None:
                fp, pathname, description = imp.find_module(
                    'server', [pluginDir]
                )
                module = imp.load_module(moduleName, fp, pathname, description)
                module.PLUGIN_ROOT_DIR = pluginDir
                girder.plugins.__dict__[name] = module
                pluginLoadMethod = getattr(module, 'load', None)

            if pluginLoadMethod is not None:
                pluginLoadMethod(info)

            root, appconf, apiRoot = (
                info['serverRoot'], info['config'], info['apiRoot'])

        finally:
            if fp:
                fp.close()

        return root, appconf, apiRoot
dataset/ETHPy150Open girder/girder/girder/utility/plugin_utilities.py/loadPlugin/swapped operands of `not in`