
    a6d(                         d Z ddlZddlZddlmZ ddlmZ ddlmZ g dZ	da
i Zi Zi Zg dd	gd	gd
Zd Z e             d Zd Zd Zd Zd Z e             ddZ e            Zd ZddZd Zd Zd Zd ZdS )aA  Handle image reading, writing and plotting plugins.

To improve performance, plugins are only loaded as needed. As a result, there
can be multiple states for a given plugin:

    available: Defined in an *ini file located in `skimage.io._plugins`.
        See also `skimage.io.available_plugins`.
    partial definition: Specified in an *ini file, but not defined in the
        corresponding plugin module. This will raise an error when loaded.
    available but not on this system: Defined in `skimage.io._plugins`, but
        a dependent library (e.g. Qt, PIL) is not available on your system.
        This will raise an error when loaded.
    loaded: The real availability is determined when it's explicitly loaded,
        either because it's one of the default plugins, or because it's
        loaded explicitly by the user.

    N)ConfigParser)glob   )imread_collection_wrapper)
use_plugincall_pluginplugin_infoplugin_orderreset_pluginsfind_available_pluginsavailable_plugins)imageiopil
matplotlibr   )allimshowimshow_collectionc                      g g g g g g da dS )zMClear the plugin state to the default, i.e., where no plugins are loaded
    )imreadimsaver   imread_collectionr   	_app_showNplugin_store     9lib/python3.11/site-packages/skimage/io/manage_plugins.py_clear_pluginsr   /   s&     !  )+)+!#% %LLLr   c                      g d} | D ]}t          |t          d                    d t                                          D             }|D ]}t          |t          |                    d S )N)r   r   r   r   r   r   c              3   &   K   | ]}|d k    |V  dS )r   Nr   .0ps     r   	<genexpr>z*_load_preferred_plugins.<locals>.<genexpr>E   s&      FF!1::A::::FFr   )_set_pluginpreferred_pluginskeys)io_typesp_typeplugin_typess      r   _load_preferred_pluginsr+   >   s      H 6 6F-e45555FF05577FFFL 7 7F-f566667 7r   c                     |D ]=}|t           vr	 t          ||             d S # t          t          t          f$ r Y :w xY wd S )N)kind)r   r   ImportErrorRuntimeErrorOSError)plugin_typeplugin_listplugins      r   r%   r%   J   sp      ***	vK0000EE\73 	 	 	D	 s   $>>c                  >    t                       t                       d S N)r   r+   r   r   r   r   r   U   s     r   c                     t                      }|                    |            |                                d         }i }|                    |          D ]}|                    ||          ||<   ||fS )z>Return plugin name and meta-data dict from plugin config file.r   )r   readsectionsoptionsget)filenameparsername	meta_dataopts        r   _parse_config_filer@   Z   st    ^^F
KK??QDI~~d## / /D#..	#?r   c            	         t           j                            t                    } t	          t           j                            | dd                    }|D ]}t          |          \  }}d|vrt          j        d| d           1|t          |<   d |d         
                    d          D             }d |D             }|D ]!}|t          vrt          d	| d
| d           "d|vod|v }|r|                    d           |t          |<   t           j                            |          dd         t           |<   dS )z]Scan the plugins directory for .ini files and parse them
    to gather plugin meta-data.
    _pluginsz*.iniprovideszfile z6 not recognized as a scikit-image io plugin, skipping.c                 6    g | ]}|                                 S r   )strip)r"   ss     r   
<listcomp>z!_scan_plugins.<locals>.<listcomp>t   s     HHH!AGGIIHHHr   ,c                 $    g | ]}|t           v |S r   r   r!   s     r   rG   z!_scan_plugins.<locals>.<listcomp>u   s"    CCCl1B1B!1B1B1Br   zPlugin `z!` wants to provide non-existent `z`. Ignoring.r   r   N)ospathdirname__file__r   joinr@   warningswarnplugin_meta_datasplitr   printappendplugin_providesbasenameplugin_module_name)	pdconfig_filesr;   r=   r>   rC   valid_providesr#   need_to_add_collections	            r   _scan_pluginsr]   g   s{    
	"	"BRW==>>L  C C,X66iY&&Mb(bbbccc!*HHy'<'B'B3'G'GHHHCCXCCC 	Y 	YA$$WWWWWWXXX #6^"K #="*n"< 	! 	7!!"5666 .#%7#3#3H#=#=crc#B4  +C Cr   Fc                     t                      }t                                          D ]}|D ]\  }}|                    |            i }t          D ]"}| r||v rd t          |         D             ||<   #|S )a1  List available plugins.

    Parameters
    ----------
    loaded : bool
        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.

    c                 <    g | ]}|                     d           |S )_)
startswith)r"   fs     r   rG   z*find_available_plugins.<locals>.<listcomp>   s8     3 3 3q !S 1 13 3 3 3r   )setr   valuesaddrV   )loadedactive_pluginsplugin_funcr3   funcds         r   r   r      s      UUN#**,, ' '' 	' 	'LFDv&&&&	' 	A! 3 3 	3>113 3OF$; 3 3 3AfI Hr   c                    | t           vrt          d|  d          t           |          }t          |          dk    rd|  d}t          |          |                    dd          |d         \  }}nIt                     	 fd|D             d         }n$# t          $ r t          d	 d
|  d          w xY w ||i |S )a  Find the appropriate plugin of 'kind' and execute it.

    Parameters
    ----------
    kind : {'imshow', 'imsave', 'imread', 'imread_collection'}
        Function to look up.
    plugin : str, optional
        Plugin to load.  Defaults to None, in which case the first
        matching plugin is used.
    *args, **kwargs : arguments and keyword arguments
        Passed to the plugin function.

    zInvalid function (z) requested.r   z"No suitable plugin registered for z.

You may load I/O plugins with the `skimage.io.use_plugin` command.  A list of all available plugins are shown in the `skimage.io` docstring.r3   Nc                 &    g | ]\  }}|k    |S r   r   )r"   r#   rb   r3   s      r   rG   zcall_plugin.<locals>.<listcomp>   s"    @@@&1aAKKAKKKr   zCould not find the plugin "z" for .)r   
ValueErrorlenr/   pop_load
IndexError)r-   argskwargsplugin_funcsmsgr`   ri   r3   s          @r   r   r      s    <@d@@@AAA%L
<A)D ) ) ) 3ZZ$''F~q/44f	T@@@@L@@@CDD 	T 	T 	TRVRR4RRRSSS	T 4    s   B !B=c                 n    |t                                           }n3|t                    vrt          d  d| d          |dk    r|dg}n|g}t	                      |D ]R}|t           vrt          d| d          t           |         } fd	|D              fd
|D             z   }|t           |<   SdS )aS  Set the default plugin for a specified operation.  The plugin
    will be loaded if it hasn't been already.

    Parameters
    ----------
    name : str
        Name of plugin.
    kind : {'imsave', 'imread', 'imshow', 'imread_collection', 'imshow_collection'}, optional
        Set the plugin for this function.  By default,
        the plugin is set for all functions.

    See Also
    --------
    available_plugins : List of available plugins

    Examples
    --------
    To use Matplotlib as the default image reader, you would write:

    >>> from skimage import io
    >>> io.use_plugin('matplotlib', 'imread')

    To see a list of available plugins run ``io.available_plugins``. Note that
    this lists plugins that are defined, but the full list may not be usable
    if your system does not have the required libraries installed.

    NPlugin z does not support `z`.r   r   'z!' is not a known plugin function.c                 *    g | ]\  }}|k    ||fS r   r   r"   nrb   r=   s      r   rG   zuse_plugin.<locals>.<listcomp>  &    999FQqDyy!Qyyyr   c                 *    g | ]\  }}|k    ||fS r   r   r{   s      r   rG   zuse_plugin.<locals>.<listcomp>  r}   r   )r   r'   rV   r/   rq   )r=   r-   kfuncss   `   r   r   r      s   8 |  ""t,,,JJJ$JJJKKK8+&DD6D	$KKK    L  G1GGGHHHQ :999e9999999e999:  Q   r   c                     t          | d          sBt          | d          r4t          | d          }t          |          }t          | d|           dS dS dS )z9Add `imread_collection` to module if not already present.r   r   N)hasattrgetattrr   setattr)moduler   ri   s      r   #_inject_imread_collection_if_neededr     so    6.// 3GFH4M4M 3**(00+T222223 3 3 3r   c                    | t          d          v rdS | t          vrt          d|  d          t          |          }t          d|z   |g          }t          |          }|D ]y}|dk    rt          |           n't          ||          st          d|  d	| d
           ?t          |         }t          ||          }| |f|vr|
                    | |f           zdS )zLoad the given plugin.

    Parameters
    ----------
    plugin : str
        Name of plugin to load.

    See Also
    --------
    plugins : List of available plugins

    T)rf   Nrx   z not found.zskimage.io._plugins.)fromlistr   z does not provide z as advertised.  Ignoring.)r   rX   rn   
__import__rV   r   r   rT   r   r   rU   )r3   modnameplugin_modulerC   r#   storeri   s          r   rq   rq     s(    't44444'''66666777$V,"#9G#C-4I7 7 7 v&H 
) 
)###/>>>>** 	SFSSaSSSTTTQ}a((D>&&LL&$(((
) 
)r   c                 `    	 t           |          S # t          $ r t          d|  d          w xY w)zReturn plugin meta-data.

    Parameters
    ----------
    plugin : str
        Name of plugin.

    Returns
    -------
    m : dict
        Meta data as specified in plugin ``.ini``.

    zNo information on plugin "")rR   KeyErrorrn   )r3   s    r   r	   r	   3  sL    A'' A A A?f???@@@As    -c                  R    i } t           D ]}d t           |         D             | |<   | S )zReturn 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.

    c                     g | ]\  }}|S r   r   )r"   plugin_namerb   s      r   rG   z plugin_order.<locals>.<listcomp>S  s    JJJ#3K;JJJr   r   )r#   ri   s     r   r
   r
   G  s=     	A K KJJ|D7IJJJ$Hr   )Fr5   )__doc__os.pathrK   rP   configparserr   r   
collectionr   __all__r   rV   rX   rR   r&   r   r+   r%   r   r@   r]   r   r   r   r   r   rq   r	   r
   r   r   r   <module>r      s   "   % % % % % %       1 1 1 1 1 1K K K
   
 ,++n&	  	% 	% 	%    	7 	7 	7    

 
 
C C C>    < +*,, #! #! #!L4  4  4  4 n3 3 3!) !) !)HA A A(    r   