a
    /§»aè,  ã                   @   sŽ   d Z ddlZddlZddlZG dd„ dƒZG dd„ dƒZdd„ Zeed	ƒZd
d„ Z	G dd„ dƒZ
G dd„ dƒZG dd„ dƒZG dd„ dƒZdS )zA
Internal hook annotation, representation and calling machinery.
é    Nc                   @   s"   e Zd ZdZdd„ Zddd„ZdS )	ÚHookspecMarkera,  Decorator helper class for marking functions as hook specifications.

    You can instantiate it with a project_name to get a decorator.
    Calling :py:meth:`.PluginManager.add_hookspecs` later will discover all marked functions
    if the :py:class:`.PluginManager` uses the same project_name.
    c                 C   s
   || _ d S ©N©Úproject_name©Úselfr   © r   úG/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/pluggy/_hooks.pyÚ__init__   s    zHookspecMarker.__init__NFc                    s*   ‡ ‡‡‡fdd„}|dur"||ƒS |S dS )ak  if passed a function, directly sets attributes on the function
        which will make it discoverable to :py:meth:`.PluginManager.add_hookspecs`.
        If passed no function, returns a decorator which can be applied to a function
        later using the attributes supplied.

        If ``firstresult`` is ``True`` the 1:N hook call (N being the number of registered
        hook implementation functions) will stop at I<=N when the I'th function
        returns a non-``None`` result.

        If ``historic`` is ``True`` calls to a hook will be memorized and replayed
        on later registered plugins.

        c                    s0   ˆrˆ rt dƒ‚t| ˆjd tˆ ˆˆd�ƒ | S )Nz'cannot have a historic firstresult hookÚ_spec)ÚfirstresultÚhistoricÚwarn_on_impl)Ú
ValueErrorÚsetattrr   Údict©Úfunc©r   r   r   r   r   r	   Úsetattr_hookspec_opts%   s    ýý	z6HookspecMarker.__call__.<locals>.setattr_hookspec_optsNr   )r   Úfunctionr   r   r   r   r   r   r	   Ú__call__   s    zHookspecMarker.__call__)NFFN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r	   r   	   s    ÿr   c                   @   s"   e Zd ZdZdd„ Zddd„ZdS )	ÚHookimplMarkera)  Decorator helper class for marking functions as hook implementations.

    You can instantiate with a ``project_name`` to get a decorator.
    Calling :py:meth:`.PluginManager.register` later will discover all marked functions
    if the :py:class:`.PluginManager` uses the same project_name.
    c                 C   s
   || _ d S r   r   r   r   r   r	   r
   A   s    zHookimplMarker.__init__NFc                    s.   ‡ ‡‡‡‡‡fdd„}|du r"|S ||ƒS dS )a~  if passed a function, directly sets attributes on the function
        which will make it discoverable to :py:meth:`.PluginManager.register`.
        If passed no function, returns a decorator which can be applied to a
        function later using the attributes supplied.

        If ``optionalhook`` is ``True`` a missing matching hook specification will not result
        in an error (by default it is an error if no matching spec is found).

        If ``tryfirst`` is ``True`` this hook implementation will run as early as possible
        in the chain of N hook implementations for a specification.

        If ``trylast`` is ``True`` this hook implementation will run as late as possible
        in the chain of N hook implementations.

        If ``hookwrapper`` is ``True`` the hook implementations needs to execute exactly
        one ``yield``.  The code before the ``yield`` is run early before any non-hookwrapper
        function is run.  The code after the ``yield`` is run after all non-hookwrapper
        function have run.  The ``yield`` receives a :py:class:`.callers._Result` object
        representing the exception or result outcome of the inner calls (including other
        hookwrapper calls).

        If ``specname`` is provided, it will be used instead of the function name when
        matching this hook implementation to a hook specification during registration.

        c              
      s$   t | ˆjd tˆ ˆˆˆˆd�ƒ | S )NÚ_impl)ÚhookwrapperÚoptionalhookÚtryfirstÚtrylastÚspecname)r   r   r   r   ©r   r    r   r#   r!   r"   r   r	   Úsetattr_hookimpl_optsh   s    ûýz6HookimplMarker.__call__.<locals>.setattr_hookimpl_optsNr   )r   r   r   r    r!   r"   r#   r%   r   r$   r	   r   D   s    $zHookimplMarker.__call__)NFFFFNr   r   r   r   r	   r   9   s         ùr   c                 C   s@   |   dd¡ |   dd¡ |   dd¡ |   dd¡ |   dd ¡ d S )Nr!   Fr"   r   r    r#   )Ú
setdefault)Úoptsr   r   r	   Únormalize_hookimpl_opts|   s
    r(   Úpypy_version_infoc                 C   s  t  | ¡r,z
| j} W q\ ty(   Y dS 0 n0t  | ¡s\zt| d| ƒ} W n tyZ   Y dS 0 zt  | ¡}W n ty~   Y dS 0 t	|j
ƒ|j }}|rÀt|ƒ }|d|… t	||d… ƒ }}nd}tsÌdnd}|�rt  | ¡�sdt| ddƒv �r|d	 |v �r|d
d… }||fS )zâReturn tuple of positional and keywrord argument names for a function,
    method, class or callable.

    In case of a class, its ``__init__`` method is considered.
    For methods the ``self`` parameter is not included.
    )r   r   r   Nr   ©r   )r   ÚobjÚ.r   r   é   )ÚinspectÚisclassr
   ÚAttributeErrorÚ	isroutineÚgetattrÚ	ExceptionÚgetfullargspecÚ	TypeErrorÚtupleÚargsÚdefaultsÚlenÚ_PYPYÚismethod)r   Úspecr7   r8   ÚindexÚkwargsZimplicit_namesr   r   r	   Úvarnames‡   s8    




 ÿ
ÿr?   c                   @   s   e Zd ZdZdS )Ú
_HookRelayzghook holder object for performing 1:N hook calls where N is the number
    of registered plugins.

    N)r   r   r   r   r   r   r   r	   r@   ±   s   r@   c                   @   sp   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zddd„Zdd„ Zdd„ ZdS )Ú_HookCallerNc                 C   sH   || _ g | _g | _|| _d | _d | _|d urD|d us8J ‚|  ||¡ d S r   )ÚnameÚ	_wrappersÚ_nonwrappersÚ	_hookexecÚ_call_historyr<   Úset_specification)r   rB   Zhook_executeÚspecmodule_or_classÚ	spec_optsr   r   r	   r
   ¹   s    z_HookCaller.__init__c                 C   s
   | j d uS r   )r<   r*   r   r   r	   Úhas_specÄ   s    z_HookCaller.has_specc                 C   s0   |   ¡ rJ ‚t|| j|ƒ| _| d¡r,g | _d S )Nr   )rJ   ÚHookSpecrB   r<   ÚgetrF   )r   rH   rI   r   r   r	   rG   Ç   s    
z_HookCaller.set_specificationc                 C   s
   | j d uS r   )rF   r*   r   r   r	   Úis_historicÍ   s    z_HookCaller.is_historicc                    s<   ‡ fdd„}|| j ƒd u r8|| jƒd u r8tdˆ ›d�ƒ‚d S )Nc                    s,   t | ƒD ]\}}|jˆ kr| |=  dS qd S )NT)Ú	enumerateÚplugin)ÚwrappersÚiÚmethod©rO   r   r	   ÚremoveÑ   s    
z*_HookCaller._remove_plugin.<locals>.removezplugin z
 not found)rC   rD   r   )r   rO   rT   r   rS   r	   Ú_remove_pluginÐ   s    z_HookCaller._remove_pluginc                 C   s   | j | j S r   )rD   rC   r*   r   r   r	   Úget_hookimplsÛ   s    z_HookCaller.get_hookimplsc                 C   sv   |j r| j}n| j}|jr(| d|¡ nJ|jr:| |¡ n8t|ƒd }|dkrb|| jrb|d8 }qF| |d |¡ dS )z,Add an implementation to the callback chain.r   r-   N)r   rC   rD   r"   Úinsertr!   Úappendr9   )r   ÚhookimplÚmethodsrQ   r   r   r	   Ú_add_hookimplß   s    
z_HookCaller._add_hookimplc                 C   s   d| j ›d�S )Nz<_HookCaller ú>)rB   r*   r   r   r	   Ú__repr__ñ   s    z_HookCaller.__repr__c                 O   sŽ   |rt dƒ‚|  ¡ rJ ‚| jrt| jjD ]<}||vr&tt| jjƒ| ¡  ƒ}tjd 	|¡dd�  qdq&| jj
 d¡}nd}|  | j|  ¡ ||¡S )Nz,hook calling supports only keyword argumentszTArgument(s) {} which are declared in the hookspec can not be found in this hook callé   )Ú
stacklevelr   F)r5   rM   r<   Úargnamesr6   ÚsetÚkeysÚwarningsÚwarnÚformatr'   rL   rE   rB   rV   )r   r7   r>   ÚargnameZ	notincallr   r   r   r	   r   ô   s"    ÿýz_HookCaller.__call__c                 C   sP   | j  |pi |f¡ |  | j|  ¡ |d¡}|du r6dS |p<g D ]}||ƒ q>dS )a  Call the hook with given ``kwargs`` for all registered plugins and
        for all plugins which will be registered afterwards.

        If ``result_callback`` is not ``None`` it will be called for for each
        non-``None`` result obtained from a hook implementation.
        FN)rF   rX   rE   rB   rV   )r   Úresult_callbackr>   ÚresÚxr   r   r	   Úcall_historic  s    z_HookCaller.call_historicc              	   C   st   t | jƒt | jƒf}|D ]*}tdddd�}tdd||ƒ}|  |¡ qz| f i |¤ŽW |\| _| _S |\| _| _0 dS )zCall the hook with some additional temporarily participating
        methods using the specified ``kwargs`` as call parameters.F)r   r"   r!   Nz<temp>)ÚlistrD   rC   r   ÚHookImplr[   )r   rZ   r>   ÚoldrR   r'   rY   r   r   r	   Ú
call_extra  s    þz_HookCaller.call_extrac                 C   sH   |   ¡ rD| jD ]4\}}|  | j|g|d¡}|r|dur||d ƒ qdS )zAApply call history to a new hookimpl if it is marked as historic.FNr   )rM   rF   rE   rB   )r   rR   r>   rg   rh   r   r   r	   Ú_maybe_apply_history(  s
    z _HookCaller._maybe_apply_history)NN)NN)r   r   r   r
   rJ   rG   rM   rU   rV   r[   r]   r   rj   rn   ro   r   r   r   r	   rA   ¸   s   

rA   c                   @   s   e Zd Zdd„ Zdd„ ZdS )rl   c                 C   s:   || _ t| j ƒ\| _| _|| _|| _|| _| j |¡ d S r   )	r   r?   r`   Ú
kwargnamesrO   r'   Úplugin_nameÚ__dict__Úupdate)r   rO   rq   r   Zhook_impl_optsr   r   r	   r
   2  s    zHookImpl.__init__c                 C   s   d| j ›d| j›d�S )Nz<HookImpl plugin_name=z	, plugin=r\   )rq   rO   r*   r   r   r	   r]   :  s    zHookImpl.__repr__N)r   r   r   r
   r]   r   r   r   r	   rl   1  s   rl   c                   @   s   e Zd Zdd„ ZdS )rK   c                 C   sB   || _ t||ƒ | _}|| _t|ƒ\| _| _|| _| d¡| _	d S )Nr   )
Ú	namespacer2   r   rB   r?   r`   rp   r'   rL   r   )r   rt   rB   r'   r   r   r   r	   r
   ?  s    zHookSpec.__init__N)r   r   r   r
   r   r   r   r	   rK   >  s   rK   )r   r.   Úsysrc   r   r   r(   Úhasattrr:   r?   r@   rA   rl   rK   r   r   r   r	   Ú<module>   s   0C
*y