Python pkg_resources.iter_entry_points() Examples

The following are 30 code examples of pkg_resources.iter_entry_points(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pkg_resources , or try the search function .
Example #1
Source File: format_manager.py    From ipymd with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def register_entrypoints(self):
        """Look through the `setup_tools` `entry_points` and load all of
           the formats.
        """
        for spec in iter_entry_points(self.entry_point_group):
            format_properties = {"name": spec.name}
            try:
                format_properties.update(spec.load())
            except (DistributionNotFound, ImportError) as err:
                self.log.info(
                    "ipymd format {} could not be loaded: {}".format(
                        spec.name, err))
                continue

            self.register(**format_properties)

        return self 
Example #2
Source File: langhelpers.py    From jbox with MIT License 6 votes vote down vote up
def load(self, name):
        if name in self.impls:
            return self.impls[name]()

        if self.auto_fn:
            loader = self.auto_fn(name)
            if loader:
                self.impls[name] = loader
                return loader()

        try:
            import pkg_resources
        except ImportError:
            pass
        else:
            for impl in pkg_resources.iter_entry_points(
                    self.group, name):
                self.impls[name] = impl.load
                return impl.load()

        raise exc.NoSuchModuleError(
            "Can't load plugin: %s:%s" %
            (self.group, name)) 
Example #3
Source File: dist.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def finalize_options(self):
        _Distribution.finalize_options(self)
        if self.features:
            self._set_global_opts_from_features()

        for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
            value = getattr(self, ep.name, None)
            if value is not None:
                ep.require(installer=self.fetch_build_egg)
                ep.load()(self, ep.name, value)
        if getattr(self, 'convert_2to3_doctests', None):
            # XXX may convert to set here when we can rely on set being builtin
            self.convert_2to3_doctests = [
                os.path.abspath(p)
                for p in self.convert_2to3_doctests
            ]
        else:
            self.convert_2to3_doctests = [] 
Example #4
Source File: cli.py    From sea with MIT License 6 votes vote down vote up
def _load_jobs():
    path = os.getcwd()
    sys.path.append(path)

    # load builtin
    import_string('sea.cmds')

    # load lib jobs
    for ep in pkg_resources.iter_entry_points('sea.jobs'):
        try:
            ep.load()
        except Exception as e:
            logger = logging.getLogger('sea.cmd')
            logger.debug(
                'error has occurred during pkg loading: {}'.format(e))

    # load app jobs
    appjobs = os.path.join(path, 'jobs')
    if os.path.exists(appjobs):
        import_string('jobs')
        for m in os.listdir(appjobs):
            if m != '__init__.py' and m.endswith('.py'):
                import_string('jobs.{}'.format(m[:-3])) 
Example #5
Source File: dist.py    From lambda-packs with MIT License 6 votes vote down vote up
def finalize_options(self):
        _Distribution.finalize_options(self)
        if self.features:
            self._set_global_opts_from_features()

        for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
            value = getattr(self, ep.name, None)
            if value is not None:
                ep.require(installer=self.fetch_build_egg)
                ep.load()(self, ep.name, value)
        if getattr(self, 'convert_2to3_doctests', None):
            # XXX may convert to set here when we can rely on set being builtin
            self.convert_2to3_doctests = [
                os.path.abspath(p)
                for p in self.convert_2to3_doctests
            ]
        else:
            self.convert_2to3_doctests = [] 
Example #6
Source File: dist.py    From pledgeservice with Apache License 2.0 6 votes vote down vote up
def __init__(self, attrs=None):
        have_package_data = hasattr(self, "package_data")
        if not have_package_data:
            self.package_data = {}
        _attrs_dict = attrs or {}
        if 'features' in _attrs_dict or 'require_features' in _attrs_dict:
            Feature.warn_deprecated()
        self.require_features = []
        self.features = {}
        self.dist_files = []
        self.src_root = attrs and attrs.pop("src_root", None)
        self.patch_missing_pkg_info(attrs)
        # Make sure we have any eggs needed to interpret 'attrs'
        if attrs is not None:
            self.dependency_links = attrs.pop('dependency_links', [])
            assert_string_list(self,'dependency_links',self.dependency_links)
        if attrs and 'setup_requires' in attrs:
            self.fetch_build_eggs(attrs.pop('setup_requires'))
        for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
            if not hasattr(self,ep.name):
                setattr(self,ep.name,None)
        _Distribution.__init__(self,attrs)
        if isinstance(self.metadata.version, numeric_types):
            # Some people apparently take "version number" too literally :)
            self.metadata.version = str(self.metadata.version) 
Example #7
Source File: __init__.py    From custodia with GNU General Public License v3.0 6 votes vote down vote up
def handle_plugins(args):
    result = []
    errmsg = "**ERR** {0} ({1.__class__.__name__}: {1})"
    for plugin in PLUGINS:
        result.append('[{}]'.format(plugin))
        eps = pkg_resources.iter_entry_points(plugin)
        eps = sorted(eps, key=operator.attrgetter('name'))
        for ep in eps:
            try:
                if hasattr(ep, 'resolve'):
                    ep.resolve()
                else:
                    ep.load(require=False)
            except Exception as e:  # pylint: disable=broad-except
                if args.verbose:
                    result.append(errmsg.format(ep, e))
            else:
                result.append(str(ep))
        result.append('')
    return result[:-1] 
Example #8
Source File: __init__.py    From custodia with GNU General Public License v3.0 6 votes vote down vote up
def _load_plugin_class(menu, name):
    """Load Custodia plugin

    Entry points are preferred over dotted import path.
    """
    group = 'custodia.{}'.format(menu)
    eps = list(pkg_resources.iter_entry_points(group, name))
    if len(eps) > 1:
        raise ValueError(
            "Multiple entry points for {} {}: {}".format(menu, name, eps))
    elif len(eps) == 1:
        # backwards compatibility with old setuptools
        ep = eps[0]
        if hasattr(ep, 'resolve'):
            return ep.resolve()
        else:
            return ep.load(require=False)
    elif '.' in name:
        # fall back to old style dotted name
        module, classname = name.rsplit('.', 1)
        m = importlib.import_module(module)
        return getattr(m, classname)
    else:
        raise ValueError("{}: {} not found".format(menu, name)) 
Example #9
Source File: core.py    From daf-recipes with GNU General Public License v3.0 6 votes vote down vote up
def _get_service(plugin_name):
    '''
    Return a service (ie an instance of a plugin class).

    :param plugin_name: the name of a plugin entry point
    :type plugin_name: string

    :return: the service object
    '''

    if isinstance(plugin_name, basestring):
        for group in GROUPS:
            iterator = iter_entry_points(
                group=group,
                name=plugin_name
            )
            plugin = next(iterator, None)
            if plugin:
                return plugin.load()(name=plugin_name)
        raise PluginNotFoundException(plugin_name)
    else:
        raise TypeError('Expected a plugin name', plugin_name) 
Example #10
Source File: sdist.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def walk_revctrl(dirname=''):
    """Find all files under revision control"""
    for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):
        for item in ep.load()(dirname):
            yield item 
Example #11
Source File: dist.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_command_list(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                # don't require extras as the commands won't be invoked
                cmdclass = ep.resolve()
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.get_command_list(self) 
Example #12
Source File: dist.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def print_commands(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                # don't require extras as the commands won't be invoked
                cmdclass = ep.resolve()
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.print_commands(self) 
Example #13
Source File: dist.py    From lambda-packs with MIT License 5 votes vote down vote up
def get_command_list(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                # don't require extras as the commands won't be invoked
                cmdclass = ep.resolve()
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.get_command_list(self) 
Example #14
Source File: dist.py    From kobo-predict with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def get_command_class(self, command):
        """Pluggable version of get_command_class()"""
        if command in self.cmdclass:
            return self.cmdclass[command]

        for ep in pkg_resources.iter_entry_points('distutils.commands', command):
            ep.require(installer=self.fetch_build_egg)
            self.cmdclass[command] = cmdclass = ep.load()
            return cmdclass
        else:
            return _Distribution.get_command_class(self, command) 
Example #15
Source File: wl_runtime_hook_pymorphy2.py    From Wordless with GNU General Public License v3.0 5 votes vote down vote up
def iter_entry_points(group, name = None):
    for entry_point in entry_points:
        if entry_point.find(group) > -1:
            entry_point_parsed = pkg_resources.EntryPoint.parse(entry_point)
            entry_point_parsed.dist = pkg_resources.Distribution()

            yield entry_point_parsed 
Example #16
Source File: dist.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def get_command_list(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                # don't require extras as the commands won't be invoked
                cmdclass = ep.resolve()
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.get_command_list(self) 
Example #17
Source File: dist.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def print_commands(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                # don't require extras as the commands won't be invoked
                cmdclass = ep.resolve()
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.print_commands(self) 
Example #18
Source File: dist.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def get_command_class(self, command):
        """Pluggable version of get_command_class()"""
        if command in self.cmdclass:
            return self.cmdclass[command]

        eps = pkg_resources.iter_entry_points('distutils.commands', command)
        for ep in eps:
            ep.require(installer=self.fetch_build_egg)
            self.cmdclass[command] = cmdclass = ep.load()
            return cmdclass
        else:
            return _Distribution.get_command_class(self, command) 
Example #19
Source File: processors.py    From daf-recipes with GNU General Public License v3.0 5 votes vote down vote up
def _load_profiles(self, profile_names):
        '''
        Loads the specified RDF parser profiles

        These are registered on ``entry_points`` in setup.py, under the
        ``[ckan.rdf.profiles]`` group.
        '''
        profiles = []
        loaded_profiles_names = []

        for profile_name in profile_names:
            for profile in iter_entry_points(
                    group=RDF_PROFILES_ENTRY_POINT_GROUP,
                    name=profile_name):
                profile_class = profile.load()
                # Set a reference to the profile name
                profile_class.name = profile.name
                profiles.append(profile_class)
                loaded_profiles_names.append(profile.name)
                break

        unknown_profiles = set(profile_names) - set(loaded_profiles_names)
        if unknown_profiles:
            raise RDFProfileException(
                'Unknown RDF profiles: {0}'.format(
                    ', '.join(sorted(unknown_profiles))))

        return profiles 
Example #20
Source File: cli.py    From RSSNewsGAE with Apache License 2.0 5 votes vote down vote up
def _load_plugin_commands(self):
        if self._loaded_plugin_commands:
            return
        try:
            import pkg_resources
        except ImportError:
            self._loaded_plugin_commands = True
            return

        for ep in pkg_resources.iter_entry_points('flask.commands'):
            self.add_command(ep.load(), ep.name)
        self._loaded_plugin_commands = True 
Example #21
Source File: sdist.py    From lambda-packs with MIT License 5 votes vote down vote up
def walk_revctrl(dirname=''):
    """Find all files under revision control"""
    for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):
        for item in ep.load()(dirname):
            yield item 
Example #22
Source File: dist.py    From lambda-chef-node-cleanup with Apache License 2.0 5 votes vote down vote up
def get_command_class(self, command):
        """Pluggable version of get_command_class()"""
        if command in self.cmdclass:
            return self.cmdclass[command]

        for ep in pkg_resources.iter_entry_points('distutils.commands',command):
            ep.require(installer=self.fetch_build_egg)
            self.cmdclass[command] = cmdclass = ep.load()
            return cmdclass
        else:
            return _Distribution.get_command_class(self, command) 
Example #23
Source File: dist.py    From lambda-packs with MIT License 5 votes vote down vote up
def print_commands(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                # don't require extras as the commands won't be invoked
                cmdclass = ep.resolve()
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.print_commands(self) 
Example #24
Source File: dist.py    From lambda-packs with MIT License 5 votes vote down vote up
def get_command_class(self, command):
        """Pluggable version of get_command_class()"""
        if command in self.cmdclass:
            return self.cmdclass[command]

        eps = pkg_resources.iter_entry_points('distutils.commands', command)
        for ep in eps:
            ep.require(installer=self.fetch_build_egg)
            self.cmdclass[command] = cmdclass = ep.load()
            return cmdclass
        else:
            return _Distribution.get_command_class(self, command) 
Example #25
Source File: upload_docs.py    From pledgeservice with Apache License 2.0 5 votes vote down vote up
def has_sphinx(self):
        if self.upload_dir is None:
            for ep in iter_entry_points('distutils.commands', 'build_sphinx'):
                return True 
Example #26
Source File: dist.py    From pledgeservice with Apache License 2.0 5 votes vote down vote up
def print_commands(self):
        for ep in pkg_resources.iter_entry_points('distutils.commands'):
            if ep.name not in self.cmdclass:
                cmdclass = ep.load(False) # don't require extras, we're not running
                self.cmdclass[ep.name] = cmdclass
        return _Distribution.print_commands(self) 
Example #27
Source File: dist.py    From pledgeservice with Apache License 2.0 5 votes vote down vote up
def get_command_class(self, command):
        """Pluggable version of get_command_class()"""
        if command in self.cmdclass:
            return self.cmdclass[command]

        for ep in pkg_resources.iter_entry_points('distutils.commands',command):
            ep.require(installer=self.fetch_build_egg)
            self.cmdclass[command] = cmdclass = ep.load()
            return cmdclass
        else:
            return _Distribution.get_command_class(self, command) 
Example #28
Source File: dist.py    From pledgeservice with Apache License 2.0 5 votes vote down vote up
def finalize_options(self):
        _Distribution.finalize_options(self)
        if self.features:
            self._set_global_opts_from_features()

        for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
            value = getattr(self,ep.name,None)
            if value is not None:
                ep.require(installer=self.fetch_build_egg)
                ep.load()(self, ep.name, value)
        if getattr(self, 'convert_2to3_doctests', None):
            # XXX may convert to set here when we can rely on set being builtin
            self.convert_2to3_doctests = [os.path.abspath(p) for p in self.convert_2to3_doctests]
        else:
            self.convert_2to3_doctests = [] 
Example #29
Source File: importer.py    From python-netsurv with MIT License 5 votes vote down vote up
def discover_post_import_hooks(group):
    try:
        import pkg_resources
    except ImportError:
        return

    for entrypoint in pkg_resources.iter_entry_points(group=group):
        callback = _create_import_hook_from_entrypoint(entrypoint)
        register_post_import_hook(callback, entrypoint.name)

# Indicate that a module has been loaded. Any post import hooks which
# were registered against the target module will be invoked. If an
# exception is raised in any of the post import hooks, that will cause
# the import of the target module to fail. 
Example #30
Source File: sdist.py    From python-netsurv with MIT License 5 votes vote down vote up
def walk_revctrl(dirname=''):
    """Find all files under revision control"""
    for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):
        for item in ep.load()(dirname):
            yield item