ó
„¾^Yc           @   s"  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z e j	 e
 ƒ Z d Z e ƒ  Z d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   s0   Plugin loading and management logic and classes.iÿÿÿÿN(   t
   exceptions(   t   utils(   t   notifiert   Checkerst	   Listenerst   Plugint   PluginManagert   ReportFormattersc           B   sÚ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z d „  Z d „  Z e d „ Z d d „ Z d „  Z d „  Z d „  Z RS(   s3   Wrap an EntryPoint from setuptools and other logic.c         C   sL   | |  _  | |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d S(   s  "Initialize our Plugin.

        :param str name:
            Name of the entry-point as it was registered with setuptools.
        :param entry_point:
            EntryPoint returned by setuptools.
        :type entry_point:
            setuptools.EntryPoint
        N(	   t   namet   entry_pointt   Nonet   _plugint   _parameterst   _parameter_namest   _groupt   _plugin_namet   _version(   t   selfR   R	   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   __init__   s    
							c         C   s   d j  |  j |  j ƒ S(   s:   Provide an easy to read description of the current plugin.s%   Plugin(name="{0}", entry_point="{1}")(   t   formatR   R	   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   __repr__.   s    c         C   s6   i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6S(   s$   Convert this plugin to a dictionary.R   t
   parameterst   parameter_namest   plugint   plugin_name(   R   R   R   R   R   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   to_dictionary4   s    



c         C   s   |  j  ƒ  d k	 S(   s£   Determine if this plugin is in a group.

        :returns:
            True if the plugin is in a group, otherwise False.
        :rtype:
            bool
        N(   t   groupR
   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   is_in_a_group>   s    c         C   sl   |  j  d k rR |  j j d d ƒ } t | ƒ d k rF | d |  _  qR t |  _  n  |  j  t k re d S|  j  S(   s*   Find and parse the group the plugin is in.t   .i   i    N(   R   R
   R   t   splitt   lent   NO_GROUP_FOUND(   R   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   H   s    c         C   s+   |  j  d k r$ t j |  ƒ |  _  n  |  j  S(   s7   List of arguments that need to be passed to the plugin.N(   R   R
   R   t   parameters_for(   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   T   s    c         C   s+   |  j  d k r$ t |  j ƒ |  _  n  |  j  S(   s<   List of argument names that need to be passed to the plugin.N(   R   R
   t   listR   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   [   s    c         C   s   |  j  ƒ  |  j S(   s   The loaded (and cached) plugin associated with the entry-point.

        This property implicitly loads the plugin and then caches it.
        (   t   load_pluginR   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   b   s    
c         C   sF   |  j  d k r? |  j ƒ  r- t |  ƒ |  _  q? |  j j |  _  n  |  j  S(   s!   Return the version of the plugin.N(   R   R
   R   t   version_forR   t   version(   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR$   k   s
    c         C   sF   |  j  d k r? |  j ƒ  r- |  j ƒ  |  _  q? |  j j |  _  n  |  j  S(   s   Return the name of the plugin.N(   R   R
   R   R   R   R   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   v   s
    c         C   s   t  |  j d t ƒ S(   s0   Return whether the plugin is ignored by default.t   off_by_default(   t   getattrR   t   False(   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR%      s    c         O   s   |  j  | | Ž  S(   s+   Call the plugin with \*args and \*\*kwargs.(   R   (   R   t   argst   kwargs(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   execute†   s    c         C   s¼   t  |  j d d  ƒ } t  |  j d d  ƒ } | rh | rh | rY t j d |  j ƒ | ƒ  n  | ƒ  |  _ n |  j j d | ƒ |  _ t |  j ƒ s¸ d |  j } t j	 | ƒ t
 | ƒ ‚ n  d  S(   Nt   resolvet   requires%   Verifying plugin "%s"'s requirements.st   Plugin %r is not a callable. It might be written for an older version of flake8 and might not work with this version(   R&   R	   R
   t   LOGt   debugR   R   t   loadt   callablet   criticalt	   TypeError(   R   t   verify_requirementsR+   R,   t   msg(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   _loadŠ   s    	


c         C   sŽ   |  j  d k rŠ t j d |  j ƒ y |  j | ƒ WqŠ t k
 r† } t j | ƒ t j	 d |  d | ƒ } t j
 t | ƒ ƒ | ‚ qŠ Xn  d S(   s§  Retrieve the plugin for this entry-point.

        This loads the plugin, stores it on the instance and then returns it.
        It does not reload it after the first time, it merely returns the
        cached plugin.

        :param bool verify_requirements:
            Whether or not to make setuptools verify that the requirements for
            the plugin are satisfied.
        :returns:
            Nothing
        s%   Loading plugin "%s" from entry-point.R   t	   exceptionN(   R   R
   R-   t   infoR   R5   t	   ExceptionR6   R    t   FailedToLoadPluginR1   t   str(   R   R3   t   load_exceptiont   failed_to_load(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR"   Ÿ   s    		c         C   sx   | j  |  j g ƒ | j |  j g ƒ | s0 d Sy | j j |  j ƒ Wn* t t f k
 rs t j d |  j ƒ n Xd S(   s0   Remove plugin name from the default ignore list.NsP   Attempted to remove %s from the ignore list but it was not a member of the list.(	   t   remove_from_default_ignoreR   t   extend_default_selectt   ignoret   removet
   ValueErrort   KeyErrorR-   R.   (   R   t
   optmanagert   options(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   enable¹   s    	c         C   s   | j  |  j g ƒ d S(   s/   Add the plugin name to the default ignore list.N(   t   extend_default_ignoreR   (   R   RC   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   disableÅ   s    c         C   s’   t  |  j d d ƒ } | d k	 ri t j d |  j ƒ y | | | | ƒ Wqi t k
 re | | ƒ qi Xn  |  j | j k rŽ |  j | | ƒ n  d S(   s:   Pass the parsed options and extra arguments to the plugin.t   parse_optionss!   Providing options to plugin "%s".N(	   R&   R   R
   R-   R.   R   R2   t   enable_extensionsRE   (   R   RC   RD   t
   extra_argsRH   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   provide_optionsÉ   s    c         C   sa   t  |  j d d ƒ } | d k	 rD t j d |  j | ƒ | | ƒ n  |  j r] |  j | ƒ n  d S(   s  Register the plugin's command-line options on the OptionManager.

        :param optmanager:
            Instantiated OptionManager to register options on.
        :type optmanager:
            flake8.options.manager.OptionManager
        :returns:
            Nothing
        t   add_optionss8   Registering options from plugin "%s" on OptionManager %rN(   R&   R   R
   R-   R.   R   R%   RG   (   R   RC   RL   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   register_optionsÖ   s    
	N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   t   propertyR   R   R   R$   R   R%   R*   R5   R'   R"   R
   RE   RG   RK   RM   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR      s&   			
	
						c           B   s5   e  Z d  Z e d „ Z d „  Z d „  Z d „  Z RS(   s%   Find and manage plugins consistently.c         C   s2   | |  _  | |  _ i  |  _ g  |  _ |  j ƒ  d S(   s'  Initialize the manager.

        :param str namespace:
            Namespace of the plugins to manage, e.g., 'flake8.extension'.
        :param bool verify_requirements:
            Whether or not to make setuptools verify that the requirements for
            the plugin are satisfied.
        N(   t	   namespaceR3   t   pluginst   namest   _load_all_plugins(   R   RR   R3   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   ï   s
    					c         C   s}   t  j d |  j ƒ xc t j |  j ƒ D]O } | j } t | | ƒ |  j | <|  j j	 | ƒ t  j
 d |  j | | ƒ q& Wd  S(   Ns   Loading entry-points for "%s".s   Loaded %r for plugin "%s".(   R-   R7   RR   t   pkg_resourcest   iter_entry_pointsR   R   RS   RT   t   appendR.   (   R   R	   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRU   þ   s    	c         o   s0   x) |  j  D] } | |  j | | | Ž Vq
 Wd S(   sù  Call ``func`` with the plugin and \*args and \**kwargs after.

        This yields the return value from ``func`` for each plugin.

        :param collections.Callable func:
            Function to call with each plugin. Signature should at least be:

            .. code-block:: python

                def myfunc(plugin):
                     pass

            Any extra positional or keyword arguments specified with map will
            be passed along to this function after the plugin. The plugin
            passed is a :class:`~flake8.plugins.manager.Plugin`.
        :param args:
            Positional arguments to pass to ``func`` after each plugin.
        :param kwargs:
            Keyword arguments to pass to ``func`` after each plugin.
        N(   RT   RS   (   R   t   funcR(   R)   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   map  s    c         c   sg   t  ƒ  } xW |  j D]L } |  j | } | j } | j | k rD q n  | j | ƒ | | j f Vq Wd S(   s‘   Generate the versions of plugins.

        :returns:
            Tuples of the plugin_name and version
        :rtype:
            tuple
        N(   t   setRT   RS   R   t   addR$   (   R   t   plugins_seent   entry_point_nameR   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   versions  s    			(   RN   RO   RP   R'   R   RU   RZ   R_   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   ì   s
   		c         C   sA   |  j  j } y t | ƒ } Wn t k
 r0 d SXt | d d ƒ S(   sÑ   Determine the version of a plugin by it's module.

    :param plugin:
        The loaded plugin
    :type plugin:
        Plugin
    :returns:
        version string for the module
    :rtype:
        str
    t   __version__N(   R   RO   t
   __import__t   ImportErrorR
   R&   (   R   t   module_namet   module(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR#   1  s    t   PluginTypeManagerc           B   sŒ   e  Z d  Z d Z d „  Z d „  Z d „  Z d d „ Z e	 d „  ƒ Z
 e	 d „  ƒ Z e d „  ƒ Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s3   Parent class for most of the specific plugin types.c         C   s   t  |  j ƒ |  _ t |  _ d S(   s%   Initialize the plugin type's manager.N(   R   RR   t   managerR'   t   plugins_loaded(   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   L  s    c         C   s   t  j d | ƒ | |  j k S(   s=   Check if the entry-point name is in this plugin type manager.s)   Checking for "%s" in plugin type manager.(   R-   R.   RS   (   R   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   __contains__Q  s    c         C   s   t  j d | ƒ |  j | S(   s   Retrieve a plugin by its name.s   Retrieving plugin for "%s".(   R-   R.   RS   (   R   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   __getitem__V  s    c         C   s   | |  k r |  | S| S(   sI  Retrieve the plugin referred to by ``name`` or return the default.

        :param str name:
            Name of the plugin to retrieve.
        :param default:
            Default value to return.
        :returns:
            Plugin object referred to by name, if it exists.
        :rtype:
            :class:`Plugin`
        (    (   R   R   t   default(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   get[  s    c         C   s
   |  j  j S(   s&   Proxy attribute to underlying manager.(   Rf   RT   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRT   k  s    c         C   s
   |  j  j S(   s&   Proxy attribute to underlying manager.(   Rf   RS   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRS   p  s    c            s   ‡  ‡ ‡ ‡ f d †  } | S(   Nc            sD   t  |  ˆ d ƒ } | d k	 r@ t | t j ƒ r@ | ˆ ˆ  ˆ Ž Sd S(   s=   Function that attempts to call a specific method on a plugin.N(   R&   R
   t
   isinstancet   collectionst   Callable(   R   t   method(   R(   R)   t   method_nameRC   (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   generated_functionw  s    (    (   Rp   RC   R(   R)   Rq   (    (   R(   R)   Rp   RC   s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   _generate_call_functionu  s    c         C   s;   |  j  r d Sd „  } t |  j j | ƒ ƒ } t |  _  | S(   s?   Load all plugins of this type that are managed by this manager.Nc         S   s
   |  j  ƒ  S(   s&   Call each plugin's load_plugin method.(   R"   (   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR"   „  s    (   Rg   R!   Rf   RZ   t   True(   R   R"   RS   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   load_plugins  s    			c         C   sD   |  j  ƒ  x3 |  j j ƒ  D]" \ } } | j d | d | ƒ q Wd S(   s?   Register the plugins and their versions with the OptionManager.R   R$   N(   Rt   Rf   R_   t   register_plugin(   R   RC   R   R$   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   register_plugin_versions  s    
c         C   s6   |  j  ƒ  |  j d | ƒ } t |  j j | ƒ ƒ d S(   s;   Register all of the checkers' options to the OptionManager.RM   N(   Rt   Rr   R!   Rf   RZ   (   R   RC   t   call_register_options(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRM   “  s    
c         C   s2   |  j  d | | | ƒ } t |  j j | ƒ ƒ d S(   s:   Provide parsed options and extra arguments to the plugins.RK   N(   Rr   R!   Rf   RZ   (   R   RC   RD   RJ   t   call_provide_options(    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRK   œ  s    N(   RN   RO   RP   R
   RR   R   Rh   Ri   Rk   RQ   RT   RS   t   staticmethodRr   Rt   Rv   RM   RK   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRe   G  s   			
				t   NotifierBuilderMixinc           B   s   e  Z d  Z d „  Z RS(   s8   Mixin class that builds a Notifier from a PluginManager.c         C   s;   t  j ƒ  } x( |  j D] } | j | |  j | ƒ q W| S(   sÚ   Build a Notifier for our Listeners.

        :returns:
            Object to notify our listeners of certain error codes and
            warnings.
        :rtype:
            :class:`~flake8.notifier.Notifier`
        (   R   t   NotifierRT   t   register_listenerRf   (   R   t   notifier_trieR   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   build_notifier¨  s    	(   RN   RO   RP   R~   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRz   ¥  s   c           B   s\   e  Z d  Z d Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 RS(   s4   All of the checkers registered through entry-ponits.s   flake8.extensionc         c   s9   x2 |  j  j ƒ  D]! } | | j d k r | Vq q Wd S(   s“   Retrieve checks that expect an argument with the specified name.

        Find all checker plugins that are expecting a specific argument.
        i    N(   RS   t   valuesR   (   R   t   argument_nameR   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   checks_expecting¼  s    c         C   sm   i g  |  j  D] } | j ƒ  ^ q d 6g  |  j D] } | j ƒ  ^ q0 d 6g  |  j D] } | j ƒ  ^ qS d 6S(   s2   Return a dictionary of AST and line-based plugins.t   ast_pluginst   logical_line_pluginst   physical_line_plugins(   R‚   R   Rƒ   R„   (   R   R   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   Å  s    ##c            sH   |  j  ƒ  |  j d ˆ ƒ ‰  ‡  ‡ f d †  } t |  j j | ƒ ƒ d S(   sÏ   Register all of the checkers' options to the OptionManager.

        This also ensures that plugins that are not part of a group and are
        enabled by default are enabled on the option manager.
        RM   c            s:   ˆ  |  ƒ |  j  ƒ  d  k r6 |  j r6 |  j ˆ ƒ n  d  S(   N(   R   R
   R%   RE   (   R   (   Rw   RC   (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   register_and_enableã  s    
N(   Rt   Rr   R!   Rf   RZ   (   R   RC   R…   (    (   Rw   RC   s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRM   Ó  s
    
c         C   s=   t  |  d g  ƒ } | s9 t |  j d ƒ ƒ } | |  _ n  | S(   s)   List of plugins that expect the AST tree.t   _ast_pluginst   tree(   R&   R!   R   R†   (   R   RS   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR‚   ê  s
    c         C   s=   t  |  d g  ƒ } | s9 t |  j d ƒ ƒ } | |  _ n  | S(   s.   List of plugins that expect the logical lines.t   _logical_line_pluginst   logical_line(   R&   R!   R   Rˆ   (   R   RS   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyRƒ   ó  s
    c         C   s=   t  |  d g  ƒ } | s9 t |  j d ƒ ƒ } | |  _ n  | S(   s/   List of plugins that expect the physical lines.t   _physical_line_pluginst   physical_line(   R&   R!   R   RŠ   (   R   RS   (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR„   ü  s
    (   RN   RO   RP   RR   R   R   RM   RQ   R‚   Rƒ   R„   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR   ·  s   						c           B   s   e  Z d  Z d Z RS(   s5   All of the listeners registered through entry-points.s   flake8.listen(   RN   RO   RP   RR   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR     s   c           B   s   e  Z d  Z d Z RS(   s=   All of the report formatters registered through entry-points.s   flake8.report(   RN   RO   RP   RR   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyR     s   (   s   Checkerss	   Listenerss   Plugins   PluginManagers   ReportFormatters(   RP   Rm   t   loggingRV   t   flake8R    R   t   flake8.pluginsR   t	   getLoggerRN   R-   t   __all__t   objectR   R   R   R#   Re   Rz   R   R   R   (    (    (    s6   /tmp/pip-build-EndXZ2/flake8/flake8/plugins/manager.pyt   <module>   s*       	ÔE	^O