def initialize(validate=True): """ Initialize the loader module by loading all type definitions and plugins. :param validate: if True, perform post-initialization validation :type validate: bool """ global _MANAGER # No need to do this twice, so if we're already initialized we just return if _is_initialized(): return _create_manager() plugin_entry_points = ( (ENTRY_POINT_DISTRIBUTORS, _MANAGER.distributors), (ENTRY_POINT_GROUP_DISTRIBUTORS, _MANAGER.group_distributors), (ENTRY_POINT_IMPORTERS, _MANAGER.importers), (ENTRY_POINT_GROUP_IMPORTERS, _MANAGER.group_importers), (ENTRY_POINT_PROFILERS, _MANAGER.profilers), (ENTRY_POINT_CATALOGERS, _MANAGER.catalogers), ) for entry_point in plugin_entry_points: loading.load_plugins_from_entry_point(*entry_point) # post-initialization validation if not validate: return _validate_importers()
def initialize(validate=True): """ Initialize the loader module by loading all type definitions and plugins. @param validate: if True, perform post-initialization validation @type validate: bool """ global _MANAGER # pre-initialization validation assert not _is_initialized() _create_manager() # add plugins here in the form (path, base class, manager map) plugin_tuples = ((_DISTRIBUTORS_DIR, Distributor, _MANAGER.distributors), (_DISTRIBUTORS_DIR, GroupDistributor, _MANAGER.group_distributors), (_IMPORTERS_DIR, GroupImporter, _MANAGER.group_importers), (_IMPORTERS_DIR, Importer, _MANAGER.importers), (_PROFILERS_DIR, Profiler, _MANAGER.profilers)) for path, base_class, plugin_map in plugin_tuples: loading.load_plugins_from_path(path, base_class, plugin_map) plugin_entry_points = ( (ENTRY_POINT_DISTRIBUTORS, _MANAGER.distributors), (ENTRY_POINT_GROUP_DISTRIBUTORS, _MANAGER.group_distributors), (ENTRY_POINT_IMPORTERS, _MANAGER.importers), (ENTRY_POINT_GROUP_IMPORTERS, _MANAGER.group_importers), (ENTRY_POINT_PROFILERS, _MANAGER.profilers), ) for entry_point in plugin_entry_points: loading.load_plugins_from_entry_point(*entry_point) # post-initialization validation if not validate: return _validate_importers()
def initialize(validate=True): """ Initialize the loader module by loading all type definitions and plugins. :param validate: if True, perform post-initialization validation :type validate: bool """ global _MANAGER # No need to do this twice, so if we're already initialized we just return if _is_initialized(): return # Initialize the plugin manager, this includes initialization of the unit_model entry point _create_manager() plugin_entry_points = ( (ENTRY_POINT_DISTRIBUTORS, _MANAGER.distributors), (ENTRY_POINT_GROUP_DISTRIBUTORS, _MANAGER.group_distributors), (ENTRY_POINT_IMPORTERS, _MANAGER.importers), (ENTRY_POINT_GROUP_IMPORTERS, _MANAGER.group_importers), (ENTRY_POINT_PROFILERS, _MANAGER.profilers), (ENTRY_POINT_CATALOGERS, _MANAGER.catalogers), ) for entry_point in plugin_entry_points: loading.load_plugins_from_entry_point(*entry_point) # post-initialization validation if not validate: return _validate_importers()
def test_load_entry_points(self, mock_iter, mock_add): ep = mock.MagicMock() cls = mock.MagicMock() cfg = mock.MagicMock() ep.load.return_value.return_value = (cls, cfg) mock_iter.return_value = [ep] GROUP_NAME = 'abc' plugin_map = mock.MagicMock() # finally, we test loading.load_plugins_from_entry_point(GROUP_NAME, plugin_map) mock_iter.assert_called_once_with(GROUP_NAME) mock_add.assert_called_once_with(cls, cfg, plugin_map)