import pkg_resources
from thrifty.core.exceptions import GeneratorNotFound

GENERATOR_ENTRY_POINT = 'thrifty.generators'


def find_plugin_generators():
    """
    Find all generator plugins using setuptools entrypoints.
    """
    for entrypoint in pkg_resources.iter_entry_points(GENERATOR_ENTRY_POINT):
        yield entrypoint.load()


def get_generator_by_name(_alias):
    """
    Get a generator by an alias.
    """
    for cls in find_plugin_generators():
        if _alias in cls.aliases:
            return cls()
    raise GeneratorNotFound('No generator for alias %r found' % _alias)

import pkg_resources
from thrifty.core.exceptions import GeneratorNotFound

GENERATOR_ENTRY_POINT = 'thrifty.generators'


def find_plugin_generators():
    """
    Find all generator plugins using setuptools entrypoints.
    """
    for entrypoint in pkg_resources.iter_entry_points(GENERATOR_ENTRY_POINT):
        yield entrypoint.load()


def get_generator_by_name(_alias):
    """
    Get a generator by an alias.
    """
    for cls in find_plugin_generators():
        if _alias in cls.aliases:
            return cls()
    raise GeneratorNotFound('No generator for alias %r found' % _alias)

Find all generator plugins using setuptools entrypoints. Get a generator by an alias.