a
    ©ˆc  ã                   @   sf   d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	 ddl
mZ e e¡ZG dd„ deƒZdS )	z3 A plugin manager that gets its plugins from Eggs. é    N)ÚInstanceÚListÚStré   )Úget_entry_points_in_egg_order)ÚPluginManagerc                   @   sV   e Zd ZdZdZeejƒZe	e
ƒZe	e
ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚEggPluginManagera=   A plugin manager that gets its plugins from Eggs.

    To declare a plugin (or plugins) in your egg use an entry point in your
    'setup.py' file, e.g.

    [envisage.plugins]
    acme.foo = acme.foo.foo_plugin:FooPlugin

    The left hand side of the entry point declaration must be the same as the
    'id' trait of the plugin (e.g. the 'FooPlugin' would have its 'id' trait
    set to 'acme.foo'). This allows the plugin manager to filter out plugins
    using the 'include' and 'exclude' lists (if specified) *without* having to
    import and instantiate them.

    zenvisage.pluginsc                 C   sT   g }t | j| jƒD ]0}|  |j¡r|  |j¡s|  |¡}| |¡ qt 	d|¡ |S )ú Trait initializer. z%egg plugin manager found plugins <%s>)
r   Úworking_setÚPLUGINSÚ_is_includedÚnameÚ_is_excludedÚ_create_plugin_from_epÚappendÚloggerÚdebug)ÚselfZpluginsÚepÚplugin© r   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/envisage/egg_plugin_manager.pyZ__plugins_defaultN   s    ÿ
z"EggPluginManager.__plugins_defaultc                 C   s   t jS )r	   )Úpkg_resourcesr
   )r   r   r   r   Ú_working_set_default]   s    z%EggPluginManager._working_set_defaultc                 C   s:   |  ¡ }|| jd�}|j|jkr6t d|j|jf ¡ |S )z* Create a plugin from an extension point. )Úapplicationz>entry point name <%s> should be the same as the plugin id <%s>)Úloadr   r   Úidr   Úwarning)r   r   Úklassr   r   r   r   r   f   s    
ÿÿz'EggPluginManager._create_plugin_from_epc                 C   s8   t | jƒdkrdS | jD ]}t ||¡dur dS qdS )zŸ Return True if the plugin Id is excluded.

        If no 'exclude' patterns are specified then this method returns False
        for all plugin Ids.

        r   FNT)ÚlenÚexcludeÚreÚmatch©r   Z	plugin_idÚpatternr   r   r   r   v   s    
zEggPluginManager._is_excludedc                 C   s8   t | jƒdkrdS | jD ]}t ||¡dur dS qdS )zž Return True if the plugin Id is included.

        If no 'include' patterns are specified then this method returns True
        for all plugin Ids.

        r   TNF)r   Úincluder!   r"   r#   r   r   r   r   ‡   s    
zEggPluginManager._is_includedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú
WorkingSetr
   r   r   r    r%   Z"_EggPluginManager__plugins_defaultr   r   r   r   r   r   r   r   r       s   
	r   )r)   Úloggingr!   r   Z
traits.apir   r   r   Z	egg_utilsr   Zplugin_managerr   Ú	getLoggerr&   r   r   r   r   r   r   Ú<module>
   s   
