Merge pull request #90 from stefanv/plugin_load_fix

BUG: Fix selective plugin loading. Also provide a function to inspect the current plugin configuration.
This commit is contained in:
Stefan van der Walt
2011-12-05 20:26:55 -08:00
3 changed files with 51 additions and 6 deletions
+28 -4
View File
@@ -2,7 +2,7 @@
"""
__all__ = ['use', 'available', 'call', 'info']
__all__ = ['use', 'available', 'call', 'info', 'configuration']
import warnings
from ConfigParser import ConfigParser
@@ -118,7 +118,11 @@ def use(name, kind=None):
if not kind in plugin_provides[name]:
raise RuntimeError("Plugin %s does not support `%s`." % \
(name, kind))
kind = [kind]
if kind == 'imshow':
kind = [kind, '_app_show']
else:
kind = [kind]
if not name in available(loaded=True):
_load(name)
@@ -145,6 +149,12 @@ def available(loaded=False):
If True, show only those plugins currently loaded. By default,
all plugins are shown.
Returns
-------
p : dict
Dictionary with plugin names as keys and exposed functions as
values.
"""
active_plugins = set()
for plugin_func in plugin_store.itervalues():
@@ -187,8 +197,8 @@ def _load(plugin):
else:
store = plugin_store[p]
func = getattr(plugin_module, p)
if not func in store:
store.insert(0, (plugin, func))
if not (plugin, func) in store:
store.append((plugin, func))
def info(plugin):
"""Return plugin meta-data.
@@ -209,3 +219,17 @@ def info(plugin):
except KeyError:
raise ValueError('No information on plugin "%s"' % plugin)
def configuration():
"""Return the currently preferred plugin order.
Returns
-------
p : dict
Dictionary of preferred plugin order, with function name as key and
plugins (in order of preference) as value.
"""
p = {}
for func in plugin_store:
p[func] = [plugin_name for (plugin_name, f) in plugin_store[func]]
return p