def loadPluginType(cls, ptypeId, ptypeModulePath): """ Loads a plugin type, going through its source tree and loading each plugin as well. """ # we load the plugin type module ptypeModule = cls.importName(ptypeModulePath) metadata = processPluginMetadata(ptypeModule) # check if the plugin should be ignored if metadata['ignore']: # stop loading here! return #if ignore == False, we store the plugin type module in cls._ptypeModules cls._ptypeModules[ptypeId] = ptypeModule missingDeps = cls._checkSetuptoolsDependencies(metadata['requires'], ptypeId) # save missing dependency info, so that the holder will know the module state ptypeModule.__missing_deps__ = missingDeps # save id information ptypeModule.__ptype_id__ = ptypeId cls._pmodules[ptypeId] = {} # check dependencies if len(missingDeps) > 0: # if some dependencies are not met, don't load submodules Logger.get('plugins.loader').warning( "Plugin type %s has unmet dependencies. It will be deactivated." % ptypeId) return else: pluginEps = pkg_resources.iter_entry_points('indico.ext') # we loop through all the specified plugins for epoint in pluginEps: mname = epoint.module_name # ignore plugins that don't match our plugin type if not epoint.name.startswith("%s." % ptypeId): continue else: pid = epoint.name[len(ptypeId) + 1:] # load plugin files cls._loadPluginFromDir(mname, ptypeId, ptypeModule, pid) # load submodules too cls._loadSubModules(ptypeModule)
def _loadPluginFromDir(cls, pModuleName, ptypeId, ptypeModule, pid): """ Loads a possible plugin from a directory """ # we attempt to import the module. try: pmodule = cls.importName(pModuleName) except (ImportError, KeyError): raise Exception("Tried to load the plugin %s but the module " "%s does not exist. " "Is there an __init__.py?" % (pid, pModuleName)) ppath = pmodule.__path__[0] pmetadata = processPluginMetadata(pmodule) # If it was a module, we check that the "type" field in the metadata # of the plugin corresponds to the plugin type we are currently processing if pmetadata['type'] == ptypeId: missingDeps = cls._checkSetuptoolsDependencies(pmetadata['requires'], pid) # save missing dependency info, so that the holder will know the # module state pmodule.__missing_deps__ = missingDeps # save the plugin id, so that the holder will know it pmodule.__plugin_id__ = pid # check dependencies if len(missingDeps) > 0: # if some dependencies are not met, don't load submodules cls._pmodules[ptypeId][pid] = pmodule Logger.get('plugins.loader').warning( "Plugin %s has unmet dependencies. It will be deactivated." % pid) return cls._ptypeModules[ptypeId].__dict__[pid] = pmodule # we store the module inside the cls._pmodules object cls._pmodules[ptypeId][pid] = pmodule # load submodules too cls._loadSubModules(pmodule) else: Logger.get("plugins.loader").warning("Module of type %s inside %s" % (pmetadata['type'], ptypeId))