ó
;^c           @   s  d  Z  d d l Z y: d d l m Z m Z d d l m Z d d l m Z Wn e	 k
 r_ n Xd d l
 m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   sÊ  
Adds a sphinx directive that can be used to automatically document a plugin.

this::

 .. autoplugin :: nose.plugins.foo
    :plugin: Pluggy
    
produces::

  .. automodule :: nose.plugins.foo
  
  Options
  -------

  .. cmdoption :: --foo=BAR, --fooble=BAR

    Do the foo thing to the new thing.

  Plugin
  ------

  .. autoclass :: nose.plugins.foo.Pluggy
     :members:

  Source
  ------

  .. include :: path/to/nose/plugins/foo.py
     :literal:

iÿÿÿÿN(   t   nodest   utils(   t   ViewList(   t
   directives(   t   resolve_name(   t   Plugin(   t   BuiltinPluginManager(   t   Config(   t   TestProgram(   t   isclassc	         C   sø  | d }	 t  |	 ƒ }
 | j d d  ƒ } | r@ t |
 | ƒ } na x^ t |
 ƒ D]P } t |
 | ƒ } t | ƒ rM t | t ƒ rM | t k	 rM d |	 | f } PqM qM Wt ƒ  } | j	 d |	 d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d d ƒ | ƒ  } t
 ƒ  } | j | i  ƒ x_ | D]W } | j	 | j ƒ  d ƒ | j	 d	 d ƒ | j	 d
 | j d d ƒ | j	 d d ƒ q'W| j	 d d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d | d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d d ƒ | j	 d t j | j d t j j |
 j j d d ƒ ƒ ƒ d ƒ | j	 d d ƒ | j	 d d ƒ t j ƒ  } | j | _ | j j } | j j } g  | j _ d | j _ | j | d | d d ƒ| | j _ | | j _ | j S(   Ni    t   plugins   %s.%ss   .. automodule :: %s
s	   <autodoc>t    t   Optionss   -------s      
s      s   
R   s   ------s   .. autoclass :: %s
s      :members:
s      :show-inheritance:
t   Sources   .. include :: %s
t   sources   .pycs   .pys      :literal:
t   match_titlesi   (   R   t   gett   Nonet   getattrt   dirR	   t
   issubclassR   R   t   appendt	   OptBuckett   optionst   helpR   t   relative_patht   documentt   ost   patht   abspatht   __file__t   replaceR    t   sectiont   memot   title_stylest   section_levelt   nested_parset   children(   t   dirnamet	   argumentsR   t   contentt   linenot   content_offsett
   block_textt   statet   state_machinet   mod_namet   modt	   plug_namet   objt   entryt   rstt   plugt   optst   optt   nodet   surrounding_title_stylest   surrounding_section_level(    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt   autoplugin_directive1   sd    
'				
"c	         C   sx  t  d t d t ƒ  ƒ }	 |	 j t j ƒ  ƒ }
 t ƒ  } x- |
 j ƒ  j d ƒ D] } | j	 | d ƒ qL W| j	 d d ƒ | j	 d d ƒ | j	 d d ƒ x_ |
 D]W } | j	 | j
 ƒ  d ƒ | j	 d d ƒ | j	 d	 | j d d ƒ | j	 d d ƒ q Wt j ƒ  } | j | _ | j j } | j j } g  | j _ d
 | j _ | j | d
 | d d ƒ| | j _ | | j _ | j S(   s   produces rst from nose helpt   parserClasst   pluginss   
s	   <autodoc>R   s   -------R   s      
s      i    R   i   (   R   R   R   t	   getParserR   t   usageR   t   format_helpt   splitR   R   R   R    R    R   R!   R"   R#   R$   R%   (   R&   R'   R   R(   R)   R*   R+   R,   R-   t   configt   parserR3   t   lineR6   R7   R8   R9   (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt   autohelp_directivet   s0    	R   c           B   s2   e  Z d d  d „ Z d „  Z d „  Z d „  Z RS(   t	   nosetestsc         C   s   g  |  _  | |  _ | |  _ d  S(   N(   R5   t   doct   prog(   t   selfRF   RG   (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt   __init__”   s    		c         C   s   t  |  j ƒ S(   N(   t   iterR5   (   RH   (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt   __iter__™   s    c         C   s"   |  j  j d |  j ƒ j d d ƒ S(   Ns   %progs   :
s   ::
(   RF   R   RG   (   RH   (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyR?   œ   s    c         O   s   |  j  j t | | Ž  ƒ d  S(   N(   R5   R   t   Opt(   RH   t   argt   kw(    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt
   add_optionŸ   s    N(   t   __name__t
   __module__R   RI   RK   R?   RO   (    (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyR   “   s   		RL   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         O   sa   | |  _  | j d d  ƒ |  _ | j d d  ƒ |  _ | j d d  ƒ |  _ | j d d  ƒ |  _ d  S(   Nt   actiont   defaultt   metavarR   (   R5   t   popR   RR   RS   RT   R   (   RH   RM   RN   (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyRI   ¤   s
    	c         C   sg   g  } xM |  j  D]B } | } |  j d k rE | d |  j | ƒ 7} n  | j | ƒ q Wd d j | ƒ S(   Nt
   store_truet   store_falses   =%ss   .. cmdoption :: s   , (   RV   RW   (   R5   RR   t   metaR   t   join(   RH   t   buft	   optstringt   desc(    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyR   «   s    c         C   s   |  j  p d S(   Nt   DEFAULT(   RT   (   RH   R[   (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyRX   ´   s    (   RP   RQ   RI   R   RX   (    (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyRL   £   s   			c         C   s9   |  j  d t d d d t j ƒ|  j  d t d d ƒ d  S(   Nt
   autoplugini   i    R
   t   autohelp(   i   i    i   (   i    i    i   (   t   add_directiveR:   R   t	   unchangedRD   (   t   app(    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt   setup¹   s    	
(   t   __doc__R   t   docutilsR    R   t   docutils.statemachineR   t   docutils.parsers.rstR   t   ImportErrort	   nose.utilR   t   nose.plugins.baseR   t   nose.plugins.managerR   t   nose.configR   t	   nose.coreR   t   inspectR	   R:   RD   t   objectR   RL   Rc   (    (    (    s8   /tmp/pip-unpacked-wheel-IhimZu/nose/sphinx/pluginopts.pyt   <module>    s$   	C	