mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Plugin loading: When multiple plugin classes are present in the __init__.py namespace, use the one with the qualified name that has the least components
This commit is contained in:
parent
63b512054c
commit
c5ee7f9080
@ -195,14 +195,18 @@ class PluginLoader(object):
|
|||||||
reload(m)
|
reload(m)
|
||||||
else:
|
else:
|
||||||
m = importlib.import_module(plugin_module)
|
m = importlib.import_module(plugin_module)
|
||||||
|
plugin_classes = []
|
||||||
for obj in m.__dict__.itervalues():
|
for obj in m.__dict__.itervalues():
|
||||||
if isinstance(obj, type) and issubclass(obj, Plugin) and \
|
if isinstance(obj, type) and issubclass(obj, Plugin) and \
|
||||||
obj.name != 'Trivial Plugin':
|
obj.name != 'Trivial Plugin':
|
||||||
ans = obj
|
plugin_classes.append(obj)
|
||||||
break
|
if not plugin_classes:
|
||||||
if ans is None:
|
|
||||||
raise InvalidPlugin('No plugin class found in %s:%s'%(
|
raise InvalidPlugin('No plugin class found in %s:%s'%(
|
||||||
as_unicode(path_to_zip_file), plugin_name))
|
as_unicode(path_to_zip_file), plugin_name))
|
||||||
|
if len(plugin_classes) > 1:
|
||||||
|
plugin_classes.sort(key=lambda c:(getattr(c, '__module__', None) or '').count('.'))
|
||||||
|
|
||||||
|
ans = plugin_classes[0]
|
||||||
|
|
||||||
if ans.minimum_calibre_version > numeric_version:
|
if ans.minimum_calibre_version > numeric_version:
|
||||||
raise InvalidPlugin(
|
raise InvalidPlugin(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user