mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-01 08:02:47 +08:00
io: Combine use_plugin and load_plugin.
This commit is contained in:
@@ -4,13 +4,12 @@ The following plug-ins are available:
|
||||
|
||||
"""
|
||||
|
||||
from _plugins import load as load_plugin
|
||||
from _plugins import use as use_plugin
|
||||
from _plugins import available as plugins
|
||||
from _plugins import info as plugin_info
|
||||
|
||||
# Add this plugin so that we can read images by default
|
||||
load_plugin('pil')
|
||||
use_plugin('pil')
|
||||
|
||||
from sift import *
|
||||
from collection import *
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ['use', 'load', 'available', 'call', 'info']
|
||||
__all__ = ['use', 'available', 'call', 'info']
|
||||
|
||||
import warnings
|
||||
from ConfigParser import ConfigParser
|
||||
@@ -87,7 +87,8 @@ command. A list of all available plugins can be found using
|
||||
return func(*args, **kwargs)
|
||||
|
||||
def use(name, kind=None):
|
||||
"""Set the default plugin for a specified operation.
|
||||
"""Set the default plugin for a specified operation. The plugin
|
||||
will be loaded if it hasn't been already.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -97,10 +98,14 @@ def use(name, kind=None):
|
||||
Set the plugin for this function. By default,
|
||||
the plugin is set for all functions.
|
||||
|
||||
See Also
|
||||
--------
|
||||
plugins : List of available plugins
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
Use Python Imaging Library to read images:
|
||||
Use the Python Imaging Library to read images:
|
||||
|
||||
>>> from scikits.image.io import plugin
|
||||
>>> plugin.use('PIL', 'read')
|
||||
@@ -109,13 +114,13 @@ def use(name, kind=None):
|
||||
if kind is None:
|
||||
kind = plugin_store.keys()
|
||||
else:
|
||||
kind = [kind]
|
||||
if not kind in plugin_provides[name]:
|
||||
raise RuntimeError("Plugin %s does not support `%s`." % \
|
||||
(name, kind))
|
||||
kind = [kind]
|
||||
|
||||
if not name in available(loaded=True):
|
||||
raise RuntimeError("No plugin '%s' has been loaded." % name)
|
||||
_load(name)
|
||||
|
||||
for k in kind:
|
||||
if not k in plugin_store:
|
||||
@@ -153,7 +158,7 @@ def available(loaded=False):
|
||||
|
||||
return d
|
||||
|
||||
def load(plugin):
|
||||
def _load(plugin):
|
||||
"""Load the given plugin.
|
||||
|
||||
Parameters
|
||||
|
||||
@@ -8,7 +8,7 @@ from copy import deepcopy
|
||||
|
||||
def setup_module(self):
|
||||
self.backup_plugin_store = deepcopy(plugin.plugin_store)
|
||||
plugin.load('test')
|
||||
plugin.use('test')
|
||||
|
||||
def teardown_module(self):
|
||||
plugin.plugin_store = self.backup_plugin_store
|
||||
@@ -25,8 +25,9 @@ class TestPlugin:
|
||||
|
||||
def test_use(self):
|
||||
plugin.use('test')
|
||||
plugin.use('test', 'imshow')
|
||||
|
||||
@raises(RuntimeError)
|
||||
@raises(ValueError)
|
||||
def test_failed_use(self):
|
||||
plugin.use('asd')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user