Python pkg_resources.get_entry_map() Examples

The following are 8 code examples of pkg_resources.get_entry_map(). 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: __init__.py    From mkdocs with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def get_themes():
    """ Return a dict of all installed themes as (name, entry point) pairs. """

    themes = {}
    builtins = pkg_resources.get_entry_map(dist='mkdocs', group='mkdocs.themes')

    for theme in pkg_resources.iter_entry_points(group='mkdocs.themes'):

        if theme.name in builtins and theme.dist.key != 'mkdocs':
            raise exceptions.ConfigurationError(
                "The theme {} is a builtin theme but {} provides a theme "
                "with the same name".format(theme.name, theme.dist.key))

        elif theme.name in themes:
            multiple_packages = [themes[theme.name].dist.key, theme.dist.key]
            log.warning("The theme %s is provided by the Python packages "
                        "'%s'. The one in %s will be used.",
                        theme.name, ','.join(multiple_packages), theme.dist.key)

        themes[theme.name] = theme

    return themes 
Example #2
Source File: plugin_manager.py    From treadmill with Apache License 2.0 6 votes vote down vote up
def dump_cache(cache_file, distributions):
    """Write entry points in the distributions to the cache."""
    import pkg_resources

    cache = {}
    for dist in distributions:
        for section, entries in pkg_resources.get_entry_map(dist).items():
            if section not in cache:
                cache[section] = {}

            for name, entry in entries.items():
                cache[section][name] = {
                    'module': entry.module_name,
                    'attrs': list(entry.attrs)
                }

    with io.open(cache_file, 'w') as f:
        f.write(json.dumps(cache)) 
Example #3
Source File: __init__.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
def get_themes():
    """ Return a dict of all installed themes as (name, entry point) pairs. """

    themes = {}
    builtins = pkg_resources.get_entry_map(dist='mkdocs', group='mkdocs.themes')

    for theme in pkg_resources.iter_entry_points(group='mkdocs.themes'):

        if theme.name in builtins and theme.dist.key != 'mkdocs':
            raise exceptions.ConfigurationError(
                "The theme {} is a builtin theme but {} provides a theme "
                "with the same name".format(theme.name, theme.dist.key))

        elif theme.name in themes:
            multiple_packages = [themes[theme.name].dist.key, theme.dist.key]
            log.warning("The theme %s is provided by the Python packages "
                        "'%s'. The one in %s will be used.",
                        theme.name, ','.join(multiple_packages), theme.dist.key)

        themes[theme.name] = theme

    return themes 
Example #4
Source File: test_cli.py    From brozzler with Apache License 2.0 5 votes vote down vote up
def cli_commands():
    commands = set(pkg_resources.get_entry_map(
        'brozzler')['console_scripts'].keys())
    commands.remove('brozzler-wayback')
    try:
        import gunicorn
    except ImportError:
        commands.remove('brozzler-dashboard')
    try:
        import pywb
    except ImportError:
        commands.remove('brozzler-easy')
    return commands 
Example #5
Source File: test_cli.py    From brozzler with Apache License 2.0 5 votes vote down vote up
def test_call_entrypoint(capsys, cmd):
    entrypoint = pkg_resources.get_entry_map(
            'brozzler')['console_scripts'][cmd]
    callable = entrypoint.resolve()
    with pytest.raises(SystemExit):
        callable(['/whatever/bin/%s' % cmd, '--version'])
    out, err = capsys.readouterr()
    assert out == 'brozzler %s - %s\n' % (brozzler.__version__, cmd)
    assert err == '' 
Example #6
Source File: resilient_config.py    From resilient-python-api with MIT License 5 votes vote down vote up
def get_config_data(package):
    """Read the default configuration-data section from the given package"""
    data = None
    try:
        dist = pkg_resources.get_distribution(package)
        entries = pkg_resources.get_entry_map(dist, "resilient.circuits.configsection")
        if entries:
            entry = next(iter(entries))
            func = entries[entry].load()
            data = func()
    except pkg_resources.DistributionNotFound:
        pass
    return data or "" 
Example #7
Source File: resilient_customize.py    From resilient-python-api with MIT License 5 votes vote down vote up
def get_customization_definitions(package):
    """Read the default configuration-data section from the given package"""
    data = None
    try:
        dist = pkg_resources.get_distribution(package)
        entries = pkg_resources.get_entry_map(dist, "resilient.circuits.customize")
        if entries:
            for entry in iter(entries):
                func = entries[entry].load()
                data = func(client=None)
    except pkg_resources.DistributionNotFound:
        pass
    return data or [] 
Example #8
Source File: utils.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_installed_tools():
    """Get list of installed scripts via ``pkg-resources``.

    See http://peak.telecommunity.com/DevCenter/PkgResources#convenience-api

    TODO: not sure if this will be useful ... maybe to check if the list
    of installed packages matches the available scripts somehow?
    """
    from pkg_resources import get_entry_map

    console_tools = get_entry_map("ctapipe")["console_scripts"]
    return console_tools