def detect_provider(cls, identifier_type): plugins = [] for plugin_class in config.provider_detection.get(identifier_type, []): # all provider plugins run, until each plugin has had a go at determining provider information klazz = plugloader.load(plugin_class) plugins.append(klazz()) # append an instance of the class return plugins
def test_04_with_search(self): old_search_list = config.module_search_list config.module_search_list = ["openarticlegauge.tests"] call = plugloader.load("test_plugloader.patch") assert call is not None res = call() assert res == "patched" config.module_search_list = old_search_list
def type_detect_verify(cls): # FIXME: this should be updated to utilise the "capabilities" aspect of the plugin plugins = [] for plugin_class in config.type_detection: klazz = plugloader.load(plugin_class) if klazz is None: log.warn("unable to load plugin for detecting identifier type from " + str(plugin_class)) continue plugins.append(klazz()) # append an instance of the class return plugins
def license_detect(cls, provider_record): for plugin_class in config.license_detection: log.debug("checking " + plugin_class + " for support of provider " + str(provider_record)) klazz = plugloader.load(plugin_class) if klazz is None: continue inst = klazz() if inst.supports(provider_record): log.debug(plugin_class + " (" + inst._short_name + " v" + inst.__version__ + ") services provider " + str(provider_record)) return inst return None
def canonicalise(cls, identifier_type): """ Load the plugin which is capable of producing canonical versions of the supplied identifier_type arguments: identifier_type -- string representation of the identifier type (e.g. "doi" or "pmid") returns a plugin object (instance, not class), which implements the plugin.canonicalise method """ plugin_class = config.canonicalisers.get(identifier_type) klazz = plugloader.load(plugin_class) return klazz() # return an instance of the class
def type_detect_verify(cls): """ Load the list of plugins responsible for detecting and verifying the types of identifiers returns a list of plugin objects (instances, not classes), which all implement the plugin.type_detect_verify method """ # FIXME: this should be updated to utilise the "capabilities" aspect of the plugin plugins = [] for plugin_class in config.type_detection: klazz = plugloader.load(plugin_class) if klazz is None: log.warn("unable to load plugin for detecting identifier type from " + str(plugin_class)) continue plugins.append(klazz()) # append an instance of the class return plugins
def detect_provider(cls, identifier_type): """ Load the list of plugins which may be responsible for determining the provider for the given identifier_type arguments: identifier_type -- string representation of the identifier type (e.g. "doi" or "pmid") returns a list of plugin objects (instances, not classes), which all implement the plugin.detect_provider method """ plugins = [] for plugin_class in config.provider_detection.get(identifier_type, []): # all provider plugins run, until each plugin has had a go at determining provider information klazz = plugloader.load(plugin_class) plugins.append(klazz()) # append an instance of the class return plugins
def license_detect(cls, provider_record): """ Return a plugin which asserts that it is capable of determining the licence type for a resource held by the supplied provider arguments provider_record -- an OAG provider record data structure. See the top-level documentation for details on its structure returns a plugin object (instance, not class) which implements the plugin.license_detect method """ for plugin_class in config.license_detection: log.debug("checking " + plugin_class + " for support of provider " + str(provider_record)) klazz = plugloader.load(plugin_class) if klazz is None: continue inst = klazz() if inst.supports(provider_record): log.debug(plugin_class + " (" + inst._short_name + " v" + inst.__version__ + ") services provider " + str(provider_record)) return inst return None
def test_09_load_class(self): doi_class = plugloader.load("openarticlegauge.plugins.doi.DOIPlugin") doi = doi_class()
def test_03_load_error(self): # an attempt to load a non existant callable from an # existing module call = plugloader.load("tests.test_plugloader.nothing") assert call is None
def test_02_load_none(self): # shouldn't find the test_plugloader module in this context, so # call will fail call = plugloader.load("test_plugloader.patch") assert call is None
def test_01_load_monkey_patch(self): call = plugloader.load("tests.test_plugloader.patch") assert call is not None res = call() assert res == "patched"
def canonicalise(cls, identifier_type): plugin_class = config.canonicalisers.get(identifier_type) klazz = plugloader.load(plugin_class) return klazz() # return an instance of the class