示例#1
0
    def load_setuptools_entrypoints(self, entrypoint_name):
        """Load modules from querying the specified setuptools entrypoint name.
        Return the number of loaded plugins. """
        logger.info(
            "Loading plugins under entrypoint {}".format(entrypoint_name))
        for ep in iter_entry_points(entrypoint_name):
            if self.get_plugin(ep.name):
                continue

            if self.is_blocked(ep.name):
                self._disabled_plugins.append((ep.name, ep.dist))
                self._plugin_metadata[ep.name] = \
                    parse_pkg_metadata(ep.dist.key)
                continue

            try:
                plugin = ep.load()
            except DistributionNotFound:
                logger.warn("Could not load plugin {}. Passing.".format(
                    ep.name))
                continue
            except VersionConflict as e:
                raise pluggy.PluginValidationError(
                    "Plugin %r could not be loaded: %s!" % (ep.name, e))
            self.register(plugin, name=ep.name)
            self._plugin_distinfo.append((plugin, ep.dist))
            self._plugin_metadata[ep.name] = parse_pkg_metadata(ep.dist.key)
            logger.info("Loaded plugin: {}".format(ep.name))
        logger.info("Loaded {} plugins for entrypoint {}".format(
            len(self._plugin_distinfo), entrypoint_name))
        return len(self._plugin_distinfo)
示例#2
0
    def load_setuptools_entrypoints(self, entrypoint_name):
        """Load modules from querying the specified setuptools entrypoint name.
        Return the number of loaded plugins. """
        logger.info(f"Loading plugins under entrypoint {entrypoint_name}")
        for ep in iter_entry_points(entrypoint_name):
            if self.get_plugin(ep.name) or self.is_blocked(ep.name):
                continue

            try:
                plugin = ep.load()
            except DistributionNotFound:
                logger.warn(f"Could not load plugin '{ep.name}'. Passing.")
                continue
            except VersionConflict as e:
                raise pluggy.PluginValidationError(
                    f"Plugin '{ep.name}' could not be loaded: {e}!")

            self.register(plugin, name=ep.name)
            self.external_plugins.add(ep.name)
            self._plugin_distinfo.append((plugin, ep.dist))
            self.plugin_metadata[ep.name] = parse_pkg_metadata(ep.dist.key)
            logger.info(f"Loaded plugin: {ep.name}")
        logger.info(
            f"Loaded {len(self._plugin_distinfo)} plugins for entrypoint {entrypoint_name}"
        )
        return len(self._plugin_distinfo)