mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-08 19:12:45 +08:00
Fix: check all io functions when loading of default plugins.
Previously, the first available plugin was loaded and the plugin search quit---even if that plugin didn't provide all io functions. Loop over functions instead to ensure all io funcs have a plugin (if available).
This commit is contained in:
+25
-16
@@ -8,22 +8,6 @@ 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 ['matplotlib', 'pil', 'qt', 'freeimage', 'null']:
|
||||
if preferred_plugin in available_plugins:
|
||||
try:
|
||||
use_plugin(preferred_plugin)
|
||||
break
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Use PIL as the default imread plugin, since matplotlib (1.2.x)
|
||||
# is buggy (flips PNGs around, returns bytes as floats, etc.)
|
||||
try:
|
||||
use_plugin('pil', 'imread')
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from .sift import *
|
||||
from .collection import *
|
||||
@@ -32,6 +16,31 @@ from ._io import *
|
||||
from .video import *
|
||||
|
||||
|
||||
available_plugins = plugins()
|
||||
|
||||
|
||||
def _load_preferred_plugins():
|
||||
# Load preferred plugin for each io function.
|
||||
# ('imread' must be last because the list gets modified on last iteration.)
|
||||
io_funcs = ['imsave', 'imshow', 'imread_collection', 'imread']
|
||||
preferred_plugins = ['matplotlib', 'pil', 'qt', 'freeimage', 'null']
|
||||
for func in io_funcs:
|
||||
if func == 'imread':
|
||||
# Use PIL as the default imread plugin, since matplotlib (1.2.x)
|
||||
# is buggy (flips PNGs around, returns bytes as floats, etc.)
|
||||
preferred_plugins.remove('pil')
|
||||
preferred_plugins.insert(0, 'pil')
|
||||
for plugin in preferred_plugins:
|
||||
if plugin not in available_plugins:
|
||||
continue
|
||||
try:
|
||||
use_plugin(plugin, kind=func)
|
||||
break
|
||||
except (ImportError, RuntimeError):
|
||||
pass
|
||||
_load_preferred_plugins()
|
||||
|
||||
|
||||
def _update_doc(doc):
|
||||
"""Add a list of plugins to the module docstring, formatted as
|
||||
a ReStructuredText table.
|
||||
|
||||
Reference in New Issue
Block a user