a
    ¯éa  ã                   @   sÐ   d Z ddlZz,ddlmZmZ ddlmZ ddlmZ W n e	yJ   Y n0 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|
|ƒ}nBt|
ƒD ]8}t|
|ƒ}t|ƒr4t|tƒr4|tur4d|	|f } qnq4tƒ }| d|	 d¡ | dd¡ | dd¡ | dd¡ | dd¡ |ƒ }t	ƒ }| 
|i ¡ |D ]B}| | 
¡ d¡ | d	d¡ | d
|j d d¡ | dd¡ qÐ| 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
ú	<autodoc>Ú ÚOptionsú-------ú   
ú   Ú
r   z------z.. autoclass :: %s
z   :members:
z   :show-inheritance:
ZSourcez.. include :: %s
Úsourcez.pycz.pyz   :literal:
é   ©Zmatch_titles)r   ÚgetÚgetattrÚdirr   Ú
issubclassr   r   ÚappendÚ	OptBucketÚoptionsÚhelpr   Ú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© r>   ú5lib/python3.9/site-packages/nose/sphinx/pluginopts.pyÚautoplugin_directive1   sh    
þür@   c	                 C   s  t ttƒ d}	|	 t ¡ ¡}
tƒ }|
 ¡  d¡D ]}| 	|d¡ q0| 	dd¡ | 	dd¡ | 	dd¡ |
D ]B}| 	| 
¡ d¡ | 	dd¡ | 	d|j d d¡ | 	dd¡ qjt ¡ }|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   r   r   r   r   r   r   r   r   r   )r	   r   r   Z	getParserr
   Úusager   Úformat_helpÚsplitr   r   r   r   r&   r    r'   r(   r)   r*   r+   )r,   r-   r   r.   r/   r0   r1   r2   r3   ZconfigÚparserr8   Úliner:   r;   r<   r=   r>   r>   r?   Úautohelp_directivet   s2    ÿrF   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)r9   ÚdocÚprog)ÚselfrI   rJ   r>   r>   r?   Ú__init__”   s    zOptBucket.__init__c                 C   s
   t | jƒS rH   )Úiterr9   ©rK   r>   r>   r?   Ú__iter__™   s    zOptBucket.__iter__c                 C   s   | j  d| j¡ dd¡S )Nz%progz:
z::
)rI   r%   rJ   rN   r>   r>   r?   rB   œ   s    zOptBucket.format_helpc                 O   s   | j  t|i |¤Ž¡ d S rH   )r9   r   ÚOpt©rK   ÚargÚkwr>   r>   r?   Ú
add_optionŸ   s    zOptBucket.add_option)NrG   )Ú__name__Ú
__module__Ú__qualname__rL   rO   rB   rT   r>   r>   r>   r?   r   “   s   
r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )rP   c                 O   sB   || _ | dd ¡| _| dd ¡| _| dd ¡| _| dd ¡| _d S )NÚactionÚdefaultÚmetavarr   )r9   ÚpoprX   rY   rZ   r   rQ   r>   r>   r?   rL   ¤   s
    zOpt.__init__c                 C   sH   g }| j D ].}|}| jdvr.|d|  |¡ 7 }| |¡ q
dd |¡ S )N)Ú
store_trueÚstore_falsez=%sz.. cmdoption :: z, )r9   rX   Úmetar   Újoin)rK   ÚbufÚ	optstringZdescr>   r>   r?   r   «   s    

zOpt.optionsc                 C   s
   | j pdS )NZDEFAULT)rZ   )rK   ra   r>   r>   r?   r^   ´   s    zOpt.metaN)rU   rV   rW   rL   r   r^   r>   r>   r>   r?   rP   £   s   	rP   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	unchangedrF   )Zappr>   r>   r?   Úsetup¹   s
    þrb   )Ú__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@   rF   Úobjectr   rP   rb   r>   r>   r>   r?   Ú<module>   s$    C