Issues

Issue #2462 resolved

clean up entrypoint thing

Mike Bayer
repo owner created an issue

use this approach and provide sqlalchemy.dialect.register(). also write some damn tests.

class PluginLoader(object):
    def __init__(self, group):
        self.group = group
        self.impls = {}

    def load(self, name):
        if name in self.impls:
             return self.impls[name](name)()
        else:
            import pkg_resources
            for impl in pkg_resources.iter_entry_points(
                                self.group, 
                                name):
                self.impls[name](name) = impl.load
                return impl.load()
            else:
                raise Exception(
                        "Can't load plugin %s %s" % 
                        (self.group, name))

    def register(self, name, modulepath, objname):
        def load():
            mod = __import__(modulepath)
            for token in modulepath.split(".")[1:](1:):
                mod = getattr(mod, token)
            return getattr(mod, objname)
        self.impls[name](name) = load

Comments (6)

  1. Mike Bayer reporter

    disturbing here is that at some point we added a system to handle entrypoints like mysql+myspecialdriver, but we are using an inconsistent API in that in that case, we look for the attribute "dialect", but in the case of mydatabase we assume the entry point is the dialect class itself. This is totally wrong. The entrypoint needs to point to the same thing in all cases.

  2. Log in to comment