def load_plugins(entry_points=None, ext_registry=None): if entry_points is None: entry_points = list(iter_entry_points(group=PLUGIN_ENTRY_POINT_GROUP_NAME, name=None)) \ + discover_plugin_modules() if ext_registry is None: from xcube.util.extension import get_extension_registry ext_registry = get_extension_registry() plugins = {} for entry_point in entry_points: # TODO (forman): Consider turning this into debug log: # print(f'loading xcube plugin {entry_point.name!r}') t0 = time.perf_counter() # noinspection PyBroadException try: plugin_init_function = entry_point.load() except Exception as e: _handle_error(entry_point, e) continue millis = int(1000 * (time.perf_counter() - t0)) if millis >= PLUGIN_LOAD_TIME_WARN_LIMIT: warnings.warn( f'loading xcube plugin {entry_point.name!r} took {millis} ms, ' f'consider code optimization!') if not callable(plugin_init_function): # We use warning and not raise to allow loading xcube despite a broken plugin. Raise would stop xcube. warnings.warn( f'xcube plugin {entry_point.name!r} ' f'must be callable but got a {type(plugin_init_function)!r}') continue t0 = time.perf_counter() # noinspection PyBroadException try: plugin_init_function(ext_registry) except Exception as e: _handle_error(entry_point, e) continue millis = int(1000 * (time.perf_counter() - t0)) if millis >= PLUGIN_INIT_TIME__WARN_LIMIT: warnings.warn( f'initializing xcube plugin {entry_point.name!r} took {millis} ms, ' f'consider code optimization!') plugins[entry_point.name] = { 'name': entry_point.name, 'doc': plugin_init_function.__doc__ } return plugins
def test_get_extension_reg(self): self.assertIsInstance(get_extension_registry(), ExtensionRegistry)
def get_extension_registry(): """Get populated extension registry.""" from xcube.util.extension import get_extension_registry init_plugins() return get_extension_registry()
def extension(self) -> Optional[Extension]: """ :return: The extension for this component. None, if it has not (yet) been registered as an extension. """ return get_extension_registry().get_extension(self._extension_point, self._name)