我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用pkg_resources.working_set.iter_entry_points()。
def reload_hooks(): # Update working set before using it import imp import pkg_resources imp.reload(pkg_resources) # Import plugin managers after reloading pkg_resources from hookshub.plugins import plugins from pkg_resources import working_set logger = logging.getLogger() for entrypoint in working_set.iter_entry_points('hookshub.plugins'): try: plugin = entrypoint.load() except Exception as e: logger.error('Could not load plugin {}:\n{}'.format( entrypoint, e )) else: plugins.register(plugin)
def _find_checkers(): checkers = [] try: from pkg_resources import working_set except ImportError: pass else: for entry_point in working_set.iter_entry_points('babel.checkers'): checkers.append(entry_point.load()) if len(checkers) == 0: # if pkg_resources is not available or no usable egg-info was found # (see #230), just resort to hard-coded checkers return [num_plurals, python_format] return checkers
def discovery(): return working_set.iter_entry_points('promgen.discovery')
def notifications(): return working_set.iter_entry_points('promgen.notification') # Since plugins may need to load other resources bundled with them, we loop # through an additional promgen.apps entry point so that the default django # project loaders work as expected. This also should simplfy some configuration # for plugin authors