B
    kž6S  ã               @   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 W n e	k
rL   Y nX 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dlmZ dd„ Zdd„ ZG dd„ deƒZG dd„ deƒZdd„ ZdS )aÊ  
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:

é    N)ÚnodesÚutils)ÚViewList)Ú
directives)Úresolve_name)ÚPlugin)ÚBuiltinPluginManager)ÚConfig)ÚTestProgram)Úisclassc	             C   s*  |d }	t |	ƒ}
| dd ¡}|r,t|
|ƒ}nDxBt|
ƒD ]6}t|
|ƒ}t|ƒr6t|tƒr6|tk	r6d|	|f }P q6W tƒ }| d|	 d¡ | dd¡ | dd¡ | dd¡ | dd¡ |ƒ }t	ƒ }| 
|i ¡ xJ|D ]B}| | 
¡ d¡ | d	d¡ | d
|j d d¡ | dd¡ qÔW | dd¡ | dd¡ | dd¡ | d| d¡ | dd¡ | dd¡ | dd¡ | dd¡ | dd¡ | dt |jd tj |
j dd¡¡¡ d¡ | dd¡ | dd¡ t ¡ }|j|_|jj}|jj}g |j_d|j_|j|d|dd ||j_||j_|jS )Nr   Úpluginz%s.%sz.. automodule :: %s
z	<autodoc>Ú ÚOptionsz-------z   
z   Ú
r   z------z.. autoclass :: %s
z   :members:
z   :show-inheritance:
ZSourcez.. include :: %s
Úsourcez.pycz.pyz   :literal:
é   )Úmatch_titles)r   ÚgetÚgetattrÚdirr   Ú
issubclassr   r   ÚappendÚ	OptBucketÚoptionsÚhelpr   Zrelative_pathÚdocumentÚosÚpathÚabspathÚ__file__Úreplacer   ÚsectionÚmemoÚtitle_stylesÚsection_levelÚnested_parseÚchildren)ÚdirnameÚ	argumentsr   ÚcontentÚlinenoÚcontent_offsetÚ
block_textÚstateÚstate_machineÚmod_nameÚmodZ	plug_nameÚobjÚentryÚrstZplugÚoptsÚoptÚnodeÚsurrounding_title_stylesÚsurrounding_section_level© r9   ú5lib/python3.7/site-packages/nose/sphinx/pluginopts.pyÚautoplugin_directive1   sd    

r;   c	             C   s  t ttƒ d}	|	 t ¡ ¡}
tƒ }x"|
 ¡  d¡D ]}| 	|d¡ q2W | 	dd¡ | 	dd¡ | 	dd¡ xJ|
D ]B}| 	| 
¡ d¡ | 	dd¡ | 	d|j d d¡ | 	dd¡ qpW t ¡ }|j|_|jj}|jj}g |j_d	|j_|j|d	|d
d ||j_||j_|jS )zproduces rst from nose help)ZparserClassZpluginsr   z	<autodoc>r   z-------r   z   
z   r   r   )r   )r	   r   r   Z	getParserr
   Zusager   Úformat_helpÚsplitr   r   r   r   r!   r   r"   r#   r$   r%   r&   )r'   r(   r   r)   r*   r+   r,   r-   r.   ZconfigÚparserr3   Úliner5   r6   r7   r8   r9   r9   r:   Úautohelp_directivet   s0    

r@   c               @   s.   e Zd Zddd„Zdd„ Zdd„ Zd	d
„ ZdS )r   NÚ	nosetestsc             C   s   g | _ || _|| _d S )N)r4   ÚdocÚprog)ÚselfrB   rC   r9   r9   r:   Ú__init__”   s    zOptBucket.__init__c             C   s
   t | jƒS )N)Úiterr4   )rD   r9   r9   r:   Ú__iter__™   s    zOptBucket.__iter__c             C   s   | j  d| j¡ dd¡S )Nz%progz:
z::
)rB   r    rC   )rD   r9   r9   r:   r<   œ   s    zOptBucket.format_helpc             O   s   | j  t||Ž¡ d S )N)r4   r   ÚOpt)rD   ÚargÚkwr9   r9   r:   Ú
add_optionŸ   s    zOptBucket.add_option)NrA   )Ú__name__Ú
__module__Ú__qualname__rE   rG   r<   rK   r9   r9   r9   r:   r   “   s   
r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )rH   c             O   sB   || _ | dd ¡| _| dd ¡| _| dd ¡| _| dd ¡| _d S )NÚactionÚdefaultÚmetavarr   )r4   ÚpoprO   rP   rQ   r   )rD   rI   rJ   r9   r9   r:   rE   ¤   s
    zOpt.__init__c             C   sL   g }x8| j D ].}|}| jdkr0|d|  |¡ 7 }| |¡ qW dd |¡ S )N)Ú
store_trueZstore_falsez=%sz.. cmdoption :: z, )r4   rO   Úmetar   Újoin)rD   ZbufÚ	optstringZdescr9   r9   r:   r   «   s    
zOpt.optionsc             C   s
   | j pdS )NZDEFAULT)rQ   )rD   rV   r9   r9   r:   rT   ´   s    zOpt.metaN)rL   rM   rN   rE   r   rT   r9   r9   r9   r:   rH   £   s   	rH   c             C   s*   | j dtddtjd |   dtdd¡ d S )NZ
autopluginr   )r   r   r   )r   Zautohelpr   )r   r   r   )Zadd_directiver;   r   Z	unchangedr@   )Zappr9   r9   r:   Úsetup¹   s    
rW   )Ú__doc__r   Zdocutilsr   r   Zdocutils.statemachiner   Zdocutils.parsers.rstr   ÚImportErrorZ	nose.utilr   Znose.plugins.baser   Znose.plugins.managerr   Znose.configr	   Z	nose.corer
   Úinspectr   r;   r@   Úobjectr   rH   rW   r9   r9   r9   r:   Ú<module>    s$   C