
    0Ic9                         d dl Z d dlZd dlZddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ ej        dk    rd dlmZ nd dlZd Z G d	 d
e          Z G d d          Z G d d          Zd ZdS )    N   )_tracing)_Result
_multicall)HookImpl
_HookRelay_HookCallernormalize_hookimpl_opts)      metadatac                 x    t          j        | t          |           |j        j        |j        j                   d S )N)linenofilename)warningswarn_explicittype__code__co_firstlinenoco_filename)warningfunctions     /lib/python3.11/site-packages/pluggy/_manager.py_warn_for_functionr      sD    W /".	         c                   "     e Zd ZdZ fdZ xZS )PluginValidationErrorzplugin failed validation.

    :param object plugin: the plugin which failed validation,
        may be a module or an arbitrary object.
    c                 f    || _         t          t          |                               |           d S N)pluginsuper	Exception__init__)selfr!   message	__class__s      r   r$   zPluginValidationError.__init__   s.    i''00000r   )__name__
__module____qualname____doc__r$   __classcell__)r'   s   @r   r   r      sB         1 1 1 1 1 1 1 1 1r   r   c                   <    e Zd ZdZd Zed             ZddZd ZdS )
DistFacadez$Emulate a pkg_resources Distributionc                     || _         d S r    )_dist)r%   dists     r   r$   zDistFacade.__init__'   s    


r   c                     | j         d         S )Nnamer   r%   s    r   project_namezDistFacade.project_name*   s    }V$$r   Nc                 .    t          | j        ||          S r    )getattrr0   )r%   attrdefaults      r   __getattr__zDistFacade.__getattr__.   s    tz4111r   c                 N    t          t          | j                  ddgz             S )Nr0   r5   )sorteddirr0   r4   s    r   __dir__zDistFacade.__dir__1   s"    c$*oo.(AABBBr   r    )	r(   r)   r*   r+   r$   propertyr5   r:   r>    r   r   r.   r.   $   sl        ..   % % X%2 2 2 2C C C C Cr   r.   c                       e Zd ZdZd Zd ZddZd ZddZd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd ZdS )PluginManagera  Core :py:class:`.PluginManager` class which manages registration
    of plugin objects and 1:N hook calling.

    You can register new hooks by calling :py:meth:`add_hookspecs(module_or_class)
    <.PluginManager.add_hookspecs>`.
    You can register plugin objects (which contain hooks) by calling
    :py:meth:`register(plugin) <.PluginManager.register>`.  The :py:class:`.PluginManager`
    is initialized with a prefix that is searched for in the names of the dict
    of registered plugin objects.

    For debugging purposes you can call :py:meth:`.PluginManager.enable_tracing`
    which will subsequently send debug information to the trace helper.
    c                     || _         i | _        i | _        g | _        t	          j                                        d          | _        t                      | _	        t          | _        d S )Npluginmanage)r5   _name2plugin_plugin2hookcallers_plugin_distinfor   	TagTracergettracer   hookr   _inner_hookexec)r%   r5   s     r   r$   zPluginManager.__init__D   sY    (#%  "'))--n==
LL	)r   c                 2    |                      ||||          S r    rL   )r%   	hook_namemethodskwargsfirstresults        r   	_hookexeczPluginManager._hookexecM   s     ##IwLLLr   Nc                 :   |p|                      |          }|| j        v s	|| j        v r:| j                            |d          dS t	          d|d|d| j                  || j        |<   g x| j        |<   }t          |          D ]}|                     ||          }|t          |           t          ||          }t          ||||          }|                    d          p|}t          | j
        |d          }|,t          || j                  }t          | j
        ||           n?|                                r+|                     ||           |                    |           |                    |           |                    |           |S )zRegister a plugin and return its canonical name or ``None`` if the name
        is blocked from registering.  Raise a :py:class:`ValueError` if the plugin
        is already registered.NzPlugin already registered: =
specname)get_canonical_namerE   rF   rI   
ValueErrorr=   parse_hookimpl_optsr
   r7   r   rK   r	   rS   setattrhas_spec_verify_hook_maybe_apply_history_add_hookimplappend)	r%   r!   r3   plugin_namehookcallershookimpl_optsmethodhookimplrK   s	            r   registerzPluginManager.registerR   s    =d55f==$++ 	v9Q/Q 	 $$["55 *;;(9(9;   *0+& :<; (;KK 	) 	)D 44VTBBM )'666 ..#FKOO$((44<ty$55 8&tT^<<DDItT2222]]__ 8%%dH555--h777""8,,,""4(((r   c                     t          ||          }t          j        |          sd S 	 t          || j        dz   d           }n# t          $ r i }Y nw xY w|t          |t                    sd }|S )N_impl)r7   inspect	isroutiner5   r#   
isinstancedict)r%   r!   r3   re   ress        r   r[   z!PluginManager.parse_hookimpl_optsx   s    && (( 	F	&$"3g"=tDDCC 	 	 	CCC	 	:c4#8#8 	C
s   A AAc                 $   |!|
J d            |                      |          }||                     |          }| j                            |          r| j        |= | j                            |g           D ]}|                    |           |S )zlunregister a plugin object and all its contained hook implementations
        from internal data structures.Nz+one of name or plugin needs to be specified)get_name
get_pluginrE   rI   rF   pop_remove_plugin)r%   r!   r3   
hookcallers       r   
unregisterzPluginManager.unregister   s      	)TT'TTTT==((D 	+__T**F   && 	(!$'266vrBB 	. 	.J%%f----r   c                 F    |                      |           d| j        |<   dS )zHblock registrations of the given name, unregister if already registered.r3   N)ru   rE   r%   r3   s     r   set_blockedzPluginManager.set_blocked   s)    T""""&$r   c                 2    || j         v o| j         |         du S )z4return ``True`` if the given plugin name is blocked.N)rE   rx   s     r   
is_blockedzPluginManager.is_blocked   s"    t((LT->t-D-LLr   c                    g }t          |          D ]}|                     ||          }|t          | j        |d          }|.t	          || j        ||          }t          | j        ||           nC|                    ||           |                                D ]}| 	                    ||           |
                    |           |st          d| j        d|          dS )zadd new hook specifications defined in the given ``module_or_class``.
        Functions are recognized if they have been decorated accordingly.Nzdid not find any z
 hooks in )r=   parse_hookspec_optsr7   rK   r	   rS   r\   set_specificationget_hookimplsr^   ra   rZ   r5   )r%   module_or_classnamesr3   	spec_optshchookfunctions          r   add_hookspecszPluginManager.add_hookspecs   s    (( 	# 	#D00$GGI 
#TYd33 <$T4>?IVVBDItR0000 (()DDD(*(8(8(:(: < <))"l;;;;T""" 	VD$5VV?VV  	 	r   c                 T    t          ||          }t          || j        dz   d           S )N_spec)r7   r5   )r%   r   r3   re   s       r   r}   z!PluginManager.parse_hookspec_opts   s+    $//vt07:DAAAr   c                 *    t          | j                  S )z%return the set of registered plugins.)setrF   r4   s    r   get_pluginszPluginManager.get_plugins   s    4+,,,r   c                     || j         v S )z4Return ``True`` if the plugin is already registered.)rF   r%   r!   s     r   is_registeredzPluginManager.is_registered   s    111r   c                 \    t          |dd          pt          t          |                    S )aV  Return canonical name for a plugin object. Note that a plugin
        may be registered under a different name which was specified
        by the caller of :py:meth:`register(plugin, name) <.PluginManager.register>`.
        To obtain the name of an registered plugin use :py:meth:`get_name(plugin)
        <.PluginManager.get_name>` instead.r(   N)r7   stridr   s     r   rY   z PluginManager.get_canonical_name   s'     vz400CC6

OOCr   c                 6    | j                             |          S )z/Return a plugin or ``None`` for the given name.)rE   rI   rx   s     r   rq   zPluginManager.get_plugin   s     $$T***r   c                 0    |                      |          duS )z>Return ``True`` if a plugin with the given name is registered.N)rq   rx   s     r   
has_pluginzPluginManager.has_plugin   s    t$$D00r   c                 X    | j                                         D ]\  }}||k    r|c S dS )z@Return name for registered plugin or ``None`` if not registered.N)rE   items)r%   r!   r3   vals       r   rp   zPluginManager.get_name   sH    *0022 	 	ID#} 	 	r   c                 t   |                                 r-|j        r&t          |j        d|j        d|j        d          |j        j        rt          |j        j        |j	                   t          |j                  t          |j        j                  z
  }|r>t          |j        d|j        d|j        dt          |j	                  d|d	          |j        rTt          j        |j	                  s=t          |j        d|j        d|j        dt          |j	                  d          d S d S )	NzPlugin z
hook z%
historic incompatible to hookwrapperz
 for hook z
hookimpl definition: z
Argument(s) zB are declared in the hookimpl but can not be found in the hookspeczF
Declared as hookwrapper=True but function is not a generator function)is_historichookwrapperr   r!   rb   r3   specwarn_on_implr   r   r   argnames
_formatdefrj   isgeneratorfunction)r%   rK   rf   	notinspecs       r   r^   zPluginManager._verify_hook   st    	("6 	''''4   9! 	Jty5x7HIII )**S1C-D-DD	 	'
 (((IIIx01111II    	(CHDU(V(V 	' '''Jx?P4Q4Q4Q4QS  	 	 	 	r   c           	      
   | j         j        D ]u}|d         dk    rgt          | j         |          }|                                s>|                                D ])}|j        s t          |j        d|d|j                  *vdS )zVerify that all hooks which have not been verified against
        a hook specification are optional, otherwise raise :py:class:`.PluginValidationError`.r   _zunknown hook z in plugin N)rK   __dict__r7   r]   r   optionalhookr   r!   )r%   r3   rK   rf   s       r   check_pendingzPluginManager.check_pending   s     I& 
	 
	DAw#~ 	ty$//}} $($6$6$8$8  '4 "7 (#'44!:# # 
	 
	r   c                    d}t          t          j                              D ]}|j        D ]}|j        |k    sA||j        |k    s4|                     |j                  s|                     |j                  rO|                                }| 	                    ||j                   | j
                            |t          |          f           |dz  }|S )a*  Load modules from querying the specified setuptools ``group``.

        :param str group: entry point group to load plugins
        :param str name: if given, loads only plugins with the given ``name``.
        :rtype: int
        :return: return the number of loaded plugins by this call.
        r   Nrw   r   )listimportlib_metadatadistributionsentry_pointsgroupr3   rq   r{   loadrg   rG   ra   r.   )r%   r   r3   countr1   epr!   s          r   load_setuptools_entrypointsz)PluginManager.load_setuptools_entrypoints  s     +9;;<< 	 	D'  H%-/W_ rw//	
 rw// f27333%,,fj6F6F-GHHH
 r   c                 *    t          | j                  S )zTreturn list of distinfo/plugin tuples for all setuptools registered
        plugins.)r   rG   r4   s    r   list_plugin_distinfoz"PluginManager.list_plugin_distinfo%  s     D)***r   c                 N    t          | j                                                  S )z!return list of name/plugin pairs.)r   rE   r   r4   s    r   list_name_pluginzPluginManager.list_name_plugin*  s    D%++--...r   c                 6    | j                             |          S )z.get all hook callers for the specified plugin.)rF   rI   r   s     r   get_hookcallerszPluginManager.get_hookcallers.  s    '++F333r   c                 D      j         fd}| _          fd}|S )aP  add before/after tracing functions for all hooks
        and return an undo function which, when called,
        will remove the added tracers.

        ``before(hook_name, hook_impls, kwargs)`` will be called ahead
        of all hook calls and receive a hookcaller instance, a list
        of HookImpl instances and the keyword arguments for the hook call.

        ``after(outcome, hook_name, hook_impls, kwargs)`` receives the
        same arguments as ``before`` but also a :py:class:`pluggy._callers._Result` object
        which represents the result of the overall hook call.
        c                                   t          j         fd          } |            |                                S )Nc                                   S r    r@   )rR   
hook_implsrO   rQ   oldcalls   r   <lambda>zPPluginManager.add_hookcall_monitoring.<locals>.traced_hookexec.<locals>.<lambda>D  s    	:v{KK r   )r   	from_call
get_result)rO   r   rQ   rR   outcomeafterbeforer   s   ```` r   traced_hookexecz>PluginManager.add_hookcall_monitoring.<locals>.traced_hookexecA  so    F9j&111'KKKKKKKK G E'9j&999%%'''r   c                       _         d S r    rN   )r   r%   s   r   undoz3PluginManager.add_hookcall_monitoring.<locals>.undoK  s    #*D   r   rN   )r%   r   r   r   r   r   s   ```  @r   add_hookcall_monitoringz%PluginManager.add_hookcall_monitoring2  sb     &	( 	( 	( 	( 	( 	( 	(  /	+ 	+ 	+ 	+ 	+ 	+ r   c                     | j         j                            d          fd}fd}|                     ||          S )z9enable tracing of hook calls and return an undo function.rK   c                 J    j         xj        dz  c_         | |           d S )Nr   )rootindent)rO   rP   rQ   	hooktraces      r   r   z,PluginManager.enable_tracing.<locals>.beforeT  s1    N!!Q&!!Ii(((((r   c                     | j           d|d|                                            j        xj        dz  c_        d S )Nfinishz-->r   )excinfor   r   r   )r   rO   rP   rQ   r   s       r   r   z+PluginManager.enable_tracing.<locals>.afterX  sL     L	(Iug6H6H6J6JKKKN!!Q&!!!!r   )rJ   r   rI   r   )r%   r   r   r   s      @r   enable_tracingzPluginManager.enable_tracingP  sd    JO''//		) 	) 	) 	) 	)	' 	' 	' 	' 	'
 ++FE:::r   c                    t          | j                  }fd|D             }|rt          |j        |j        |j        j        |j        j                  }|                                D ]P}|j	        }||vrC|
                    |           | j                            |g                               |           Q|S |S )zReturn a new :py:class:`._hooks._HookCaller` instance for the named method
        which manages calls to all registered plugins except the
        ones from remove_plugins.c                 4    g | ]}t          |          |S r@   )hasattr).0plugr3   s     r   
<listcomp>z4PluginManager.subset_hook_caller.<locals>.<listcomp>d  s(    TTTdd@S@STTTTTr   )r7   rK   r	   r3   rS   r   	namespaceoptsr   r!   r`   rF   
setdefaultra   )r%   r3   remove_pluginsorigplugins_to_remover   rf   r!   s    `      r   subset_hook_callerz PluginManager.subset_hook_caller_  s     ty$''TTTTnTTT 		4>49+>	 B !..00 O O!!22 O$$X... ,77CCJJ2NNNIr   r    )NN)r(   r)   r*   r+   r$   rS   rg   r[   ru   ry   r{   r   r}   r   r   rY   rq   r   rp   r^   r   r   r   r   r   r   r   r   r@   r   r   rB   rB   5   s        * * *M M M
$ $ $ $L     &' ' '
M M M  .B B B- - -2 2 2D D D+ + +1 1 1  ! ! !F     2+ + +
/ / /4 4 4  <; ; ;    r   rB   c                 <    | j          t          j        |            S r    )r(   rj   	signature)funcs    r   r   r   t  s     m6W.t44666r   )rj   sysr    r   _callersr   r   _hooksr   r   r	   r
   version_info	importlibr   r   r   r#   r   r.   rB   r   r@   r   r   <module>r      sR    



        ) ) ) ) ) ) ) ) N N N N N N N N N N N Nv 8888888  	1 	1 	1 	1 	1I 	1 	1 	1C C C C C C C C"| | | | | | | |~	7 7 7 7 7r   