mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-07 13:21:49 +08:00
BUG: Fix selective plugin loading. Provide function to inspect current plugin configuration.
This commit is contained in:
@@ -7,6 +7,7 @@ The following plug-ins are available:
|
||||
from ._plugins import use as use_plugin
|
||||
from ._plugins import available as plugins
|
||||
from ._plugins import info as plugin_info
|
||||
from ._plugins import configuration as plugin_order
|
||||
available_plugins = plugins()
|
||||
|
||||
for preferred_plugin in ['pil', 'matplotlib', 'qt', 'null']:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ['use', 'available', 'call', 'info']
|
||||
__all__ = ['use', 'available', 'call', 'info', 'configuration']
|
||||
|
||||
import warnings
|
||||
from ConfigParser import ConfigParser
|
||||
@@ -145,6 +145,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 +193,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 +215,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
|
||||
|
||||
@@ -53,14 +53,34 @@ class TestPlugin:
|
||||
def test_use_priority(self):
|
||||
plugin.use(priority_plugin)
|
||||
plug, func = plugin.plugin_store['imread'][0]
|
||||
print(plugin.plugin_store)
|
||||
assert_equal(plug, priority_plugin)
|
||||
|
||||
plugin.use('test')
|
||||
plug, func = plugin.plugin_store['imread'][0]
|
||||
print(plugin.plugin_store)
|
||||
assert_equal(plug, 'test')
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_use_priority_with_func(self):
|
||||
plugin.use('pil')
|
||||
plug, func = plugin.plugin_store['imread'][0]
|
||||
assert_equal(plug, 'pil')
|
||||
|
||||
plugin.use('test', 'imread')
|
||||
plug, func = plugin.plugin_store['imread'][0]
|
||||
assert_equal(plug, 'test')
|
||||
|
||||
plug, func = plugin.plugin_store['imsave'][0]
|
||||
assert_equal(plug, 'pil')
|
||||
|
||||
plugin.use('test')
|
||||
plug, func = plugin.plugin_store['imsave'][0]
|
||||
assert_equal(plug, 'test')
|
||||
|
||||
def test_plugin_order(self):
|
||||
p = io.plugin_order()
|
||||
assert 'imread' in p
|
||||
assert 'test' in p['imread']
|
||||
|
||||
def test_available(self):
|
||||
assert 'qt' in io.plugins()
|
||||
assert 'test' in io.plugins(loaded=True)
|
||||
|
||||
Reference in New Issue
Block a user