Пример #1
0
    def collect_plugins(self,
                        entry_points=None,
                        verify_requirements=False):

        if entry_points is None:
            entry_points = self.entry_point_names
        else:
            entry_points = util.return_set(entry_points)

        plugins = []
        for name in entry_points:
            for entry_point in pkg_resources.iter_entry_points(name):
                if (hasattr(entry_point, 'resolve') and
                        hasattr(entry_point, 'require')):

                    if verify_requirements:
                        entry_point.require()

                    plugin = entry_point.resolve()
                else:
                    plugin = entry_point.load()

                plugins.append(plugin)

        return plugins
    def add_entry_points(self, names):
        """
        adds `names` to the internal collection of entry points to track

        `names` can be a single object or an iterable but
        must be a string or iterable of strings.
        """
        names = util.return_set(names)
        self.entry_point_names.update(names)
Пример #3
0
    def remove_entry_points(self, names):
        """
        removes `names` from the set of entry points to track.

        `names` can be a single object or an iterable.
        """
        names = util.return_set(names)
        util.remove_from_set(self.entry_point_names,
                             names)
Пример #4
0
    def add_entry_points(self, names):
        """
        adds `names` to the internal collection of entry points to track

        `names` can be a single object or an iterable but
        must be a string or iterable of strings.
        """
        names = util.return_set(names)
        self.entry_point_names.update(names)
    def remove_entry_points(self, names):
        """
        removes `names` from the set of entry points to track.

        `names` can be a single object or an iterable.
        """
        names = util.return_set(names)
        util.remove_from_set(self.entry_point_names,
                             names)
Пример #6
0
    def set_entry_points(self, names):
        """
        sets the internal collection of entry points to be
        equal to `names`

        `names` can be a single object or an iterable but
        must be a string or iterable of strings.
        """
        names = util.return_set(names)
        self.entry_point_names = names
    def set_entry_points(self, names):
        """
        sets the internal collection of entry points to be
        equal to `names`

        `names` can be a single object or an iterable but
        must be a string or iterable of strings.
        """
        names = util.return_set(names)
        self.entry_point_names = names
Пример #8
0
    def add_to_loaded_modules(self, modules):
        """
        Manually add in `modules` to be tracked by the module manager.

        `modules` may be a single object or an iterable.
        """
        modules = util.return_set(modules)
        for module in modules:
            if not isinstance(module, str):
                module = module.__name__
            self.loaded_modules.add(module)
Пример #9
0
    def add_to_loaded_modules(self, modules):
        """
        Manually add in `modules` to be tracked by the module manager.

        `modules` may be a single object or an iterable.
        """
        modules = util.return_set(modules)
        for module in modules:
            if not isinstance(module, str):
                module = module.__name__
            self.loaded_modules.add(module)
    def collect_plugins(self,
                        entry_points=None,
                        verify_requirements=False,
                        return_dict=False):

        """
        collects the plugins from the `entry_points`. If `entry_points` is not
        explicitly defined, this method will pull from the internal state
        defined using the add/set entry points methods.

        `entry_points` can be a single object or an iterable, but must be
        either a string or an iterable of strings.

        returns a list of plugins or an empty list.
        """

        if entry_points is None:
            entry_points = self.entry_point_names
        else:
            entry_points = util.return_set(entry_points)

        plugins = []
        plugin_names = []
        for name in entry_points:
            for entry_point in pkg_resources.iter_entry_points(name):
                if (hasattr(entry_point, 'resolve') and
                        hasattr(entry_point, 'require')):

                    if verify_requirements:
                        entry_point.require()

                    plugin = entry_point.resolve()
                else:
                    plugin = entry_point.load()

                plugins.append(plugin)
                plugin_names.append(entry_point.name)

        if return_dict:
            return {n: v for n, v in zip(plugin_names, plugins)}

        return plugins, plugin_names
Пример #11
0
    def load_modules(self, filepaths):
        """
        Loads the modules from their `filepaths`. A filepath may be
        a directory filepath if there is an `__init__.py` file in the
        directory.

        If a filepath errors, the exception will be caught and logged
        in the logger.

        Returns a list of modules.
        """
        # removes filepaths from processed if they are not in sys.modules
        self._update_loaded_modules()
        filepaths = util.return_set(filepaths)

        modules = []
        for filepath in filepaths:
            filepath = self._clean_filepath(filepath)
            # check to see if already processed and move onto next if so
            if self._processed_filepath(filepath):
                continue

            module_name = util.get_module_name(filepath)
            plugin_module_name = util.create_unique_module_name(module_name)

            try:
                module = load_source(plugin_module_name, filepath)
            # Catch all exceptions b/c loader will return errors
            # within the code itself, such as Syntax, NameErrors, etc.
            except Exception:
                exc_info = sys.exc_info()
                self._log.error(msg=self._error_string.format(filepath),
                                exc_info=exc_info)
                continue

            self.loaded_modules.add(module.__name__)
            modules.append(module)
            self.processed_filepaths[module.__name__] = filepath

        return modules
Пример #12
0
    def load_modules(self, filepaths):
        """
        Loads the modules from their `filepaths`. A filepath may be
        a directory filepath if there is an `__init__.py` file in the
        directory.

        If a filepath errors, the exception will be caught and logged
        in the logger.

        Returns a list of modules.
        """
        # removes filepaths from processed if they are not in sys.modules
        self._update_loaded_modules()
        filepaths = util.return_set(filepaths)

        modules = []
        for filepath in filepaths:
            filepath = self._clean_filepath(filepath)
            # check to see if already processed and move onto next if so
            if self._processed_filepath(filepath):
                continue

            module_name = util.get_module_name(filepath)
            plugin_module_name = util.create_unique_module_name(module_name)

            try:
                module = load_source(plugin_module_name, filepath)
            # Catch all exceptions b/c loader will return errors
            # within the code itself, such as Syntax, NameErrors, etc.
            except Exception:
                exc_info = sys.exc_info()
                self._log.error(msg=self._error_string.format(filepath),
                                exc_info=exc_info)
                continue

            self.loaded_modules.add(module.__name__)
            modules.append(module)
            self.processed_filepaths[module.__name__] = filepath

        return modules
Пример #13
0
    def collect_plugins(self,
                        entry_points=None,
                        verify_requirements=False):

        """
        collects the plugins from the `entry_points`. If `entry_points` is not
        explicitly defined, this method will pull from the internal state
        defined using the add/set entry points methods.

        `entry_points` can be a single object or an iterable, but must be
        either a string or an iterable of strings.

        returns a list of plugins or an empty list.
        """

        if entry_points is None:
            entry_points = self.entry_point_names
        else:
            entry_points = util.return_set(entry_points)

        plugins = []
        plugin_names = []
        for name in entry_points:
            for entry_point in pkg_resources.iter_entry_points(name):
                if (hasattr(entry_point, 'resolve') and
                        hasattr(entry_point, 'require')):

                    if verify_requirements:
                        entry_point.require()

                    plugin = entry_point.resolve()
                else:
                    plugin = entry_point.load()

                plugins.append(plugin)
                plugin_names.append(entry_point.name)

        return plugins, plugin_names
Пример #14
0
 def add_entry_points(self, names):
     names = util.return_set(names)
     self.entry_point_names.update(names)
Пример #15
0
 def remove_entry_points(self, names):
     names = util.return_set(names)
     util.remove_from_set(self.entry_point_names,
                          names)
Пример #16
0
    def __init__(self, entry_point_names=None):
        if entry_point_names is None:
            entry_point_names = set()

        self.entry_point_names = util.return_set(entry_point_names)
    def __init__(self, entry_point_names=None):
        if entry_point_names is None:
            entry_point_names = set()

        self.entry_point_names = util.return_set(entry_point_names)
Пример #18
0
 def set_entry_points(self, names):
     names = util.return_set(names)
     self.entry_point_names = names