From aa521576f5d508c2aa3482e8376ad2f0b59cd435 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Wed, 16 Dec 2015 17:02:10 +0100 Subject: [PATCH] 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 --- pubs/config/spec.py | 5 +++-- pubs/plugins.py | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 27cf449..f13398c 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -68,8 +68,9 @@ pages = string(default='') [plugins] -# comma-separated list of the plugins to load -active = list(default=list()) +# Comma-separated list of the plugins to load. +# The only current available plugin is alias. +active = force_list(default=list('alias')) [[alias]] # new subcommands can be defined, e.g.: diff --git a/pubs/plugins.py b/pubs/plugins.py index 20653bb..17e2256 100644 --- a/pubs/plugins.py +++ b/pubs/plugins.py @@ -35,21 +35,22 @@ def load_plugins(conf, ui): PapersPlugin subclasses desired. """ for name in conf['plugins']['active']: - modname = '%s.%s.%s.%s' % ('pubs', PLUGIN_NAMESPACE, name, name) - try: - namespace = importlib.import_module(modname) - except ImportError as exc: - # Again, this is hacky: - if exc.args[0].endswith(' ' + name): - ui.warning('plugin {} not found'.format(name)) + if len(name) > 0: + modname = '{}.{}.{}.{}'.format('pubs', PLUGIN_NAMESPACE, name, name) + try: + namespace = importlib.import_module(modname) + except ImportError as exc: + # Again, this is hacky: + if exc.args[0].endswith(' ' + name): + ui.warning('plugin {} not found'.format(name)) + else: + raise else: - raise - else: - for obj in namespace.__dict__.values(): - if isinstance(obj, type) and issubclass(obj, PapersPlugin) \ - and obj != PapersPlugin: - _classes.append(obj) - _instances[obj] = obj(conf) + for obj in namespace.__dict__.values(): + if isinstance(obj, type) and issubclass(obj, PapersPlugin) \ + and obj != PapersPlugin: + _classes.append(obj) + _instances[obj] = obj(conf) def get_plugins():