More robust plugin list in conf
A single plugin name or an absence of it, with or without comma, is now properly handled. Related: #18
This commit is contained in:
parent
f843aebcbd
commit
aa521576f5
@ -68,8 +68,9 @@ pages = string(default='')
|
|||||||
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
# comma-separated list of the plugins to load
|
# Comma-separated list of the plugins to load.
|
||||||
active = list(default=list())
|
# The only current available plugin is alias.
|
||||||
|
active = force_list(default=list('alias'))
|
||||||
|
|
||||||
[[alias]]
|
[[alias]]
|
||||||
# new subcommands can be defined, e.g.:
|
# new subcommands can be defined, e.g.:
|
||||||
|
@ -35,21 +35,22 @@ def load_plugins(conf, ui):
|
|||||||
PapersPlugin subclasses desired.
|
PapersPlugin subclasses desired.
|
||||||
"""
|
"""
|
||||||
for name in conf['plugins']['active']:
|
for name in conf['plugins']['active']:
|
||||||
modname = '%s.%s.%s.%s' % ('pubs', PLUGIN_NAMESPACE, name, name)
|
if len(name) > 0:
|
||||||
try:
|
modname = '{}.{}.{}.{}'.format('pubs', PLUGIN_NAMESPACE, name, name)
|
||||||
namespace = importlib.import_module(modname)
|
try:
|
||||||
except ImportError as exc:
|
namespace = importlib.import_module(modname)
|
||||||
# Again, this is hacky:
|
except ImportError as exc:
|
||||||
if exc.args[0].endswith(' ' + name):
|
# Again, this is hacky:
|
||||||
ui.warning('plugin {} not found'.format(name))
|
if exc.args[0].endswith(' ' + name):
|
||||||
|
ui.warning('plugin {} not found'.format(name))
|
||||||
|
else:
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
raise
|
for obj in namespace.__dict__.values():
|
||||||
else:
|
if isinstance(obj, type) and issubclass(obj, PapersPlugin) \
|
||||||
for obj in namespace.__dict__.values():
|
and obj != PapersPlugin:
|
||||||
if isinstance(obj, type) and issubclass(obj, PapersPlugin) \
|
_classes.append(obj)
|
||||||
and obj != PapersPlugin:
|
_instances[obj] = obj(conf)
|
||||||
_classes.append(obj)
|
|
||||||
_instances[obj] = obj(conf)
|
|
||||||
|
|
||||||
|
|
||||||
def get_plugins():
|
def get_plugins():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user