
    	Ae9                         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y)    N   )_tracing)_Result
_multicall)HookImpl
_HookRelay_HookCallernormalize_hookimpl_opts)      metadatac                     t        j                  | t        |       |j                  j                  |j                  j
                         y )N)linenofilename)warningswarn_explicittype__code__co_firstlinenoco_filename)warningfunctions     /lib/python3.12/site-packages/pluggy/_manager.py_warn_for_functionr      s8    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                 :    || _         t        t        |   |       y N)pluginsuper	Exception__init__)selfr!   message	__class__s      r   r$   zPluginValidationError.__init__   s    i'0r   )__name__
__module____qualname____doc__r$   __classcell__)r'   s   @r   r   r      s    1 1r   r   c                   4    e Zd ZdZd Zed        ZddZd Zy)
DistFacadez$Emulate a pkg_resources Distributionc                     || _         y 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                 0    t        | j                  ||      S r    )getattrr0   )r%   attrdefaults      r   __getattr__zDistFacade.__getattr__.   s    tzz411r   c                 H    t        t        | j                        ddgz         S )Nr0   r5   )sorteddirr0   r4   s    r   __dir__zDistFacade.__dir__1   s    c$**o.(AABBr   r    )	r(   r)   r*   r+   r$   propertyr5   r:   r>    r   r   r.   r.   $   s)    . % %2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y)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
                         j                  d      | _        t               | _	        t        | _        y )Npluginmanage)r5   _name2plugin_plugin2hookcallers_plugin_distinfor   	TagTracergettracer   hookr   _inner_hookexec)r%   r5   s     r   r$   zPluginManager.__init__D   sN    (#%  "'')--n=
L	)r   c                 *    | j                  ||||      S r    rL   )r%   	hook_namemethodskwargsfirstresults        r   	_hookexeczPluginManager._hookexecM   s     ##IwLLr   Nc                    |xs | j                  |      }|| j                  v s|| j                  v r;| j                  j                  |d      yt	        d|d|d| j                        || j                  |<   g x| j                  |<   }t        |      D ]  }| j                  ||      }|t        |       t        ||      }t        ||||      }|j                  d      xs |}t        | j                  |d      }|.t        || j                        }t        | j                  ||       n3|j                         r#| j                  ||       |j!                  |       |j#                  |       |j%                  |        |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9Q9Q/Q  $$["5=(9(9;  *0+& :<;  (;K 	)D 44VTBM('6 .#FKO$((4<tyy$5<&tT^^<DDIItT2]]_%%dH5--h7""8,""4(	)  r   c                     t        ||      }t        j                  |      sy 	 t        || j                  dz   d       }|t        |t              sd }|S # t        $ r i }Y #w xY w)N_impl)r7   inspect	isroutiner5   r#   
isinstancedict)r%   r!   r3   re   ress        r   r[   z!PluginManager.parse_hookimpl_optsx   sm    &  (	&$"3"3g"=tDC ?:c4#8C
  	C	s   A A"!A"c                    ||J d       | j                  |      }|| j                  |      }| j                  j                  |      r| j                  |= | j                  j                  |g       D ]  }|j                  |        |S )zlunregister a plugin object and all its contained hook implementations
        from internal data structures.z+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==(D>__T*F   &!!$'2266vrB 	.J%%f-	. r   c                 F    | j                  |       d| j                  |<   y)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                 D    || j                   v xr | 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 ]  }| j                  ||      }|t        | j                  |d      }|0t	        || j
                  ||      }t        | j                  ||       n9|j                  ||       |j                         D ]  }| j                  ||        |j                  |        |st        d| j                  d|      y)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$GI$TYYd3:$T4>>?IVBDIItR0 (()D(*(8(8(: <))"l;<T"	# #D$5$5#8
?BUV  r   c                 N    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007:D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11r   c                 H    t        |dd      xs 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CC6
OCr   c                 8    | j                   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                 (    | j                  |      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                 Z    | j                   j                         D ]  \  }}||k(  s|c S  y)z@Return name for registered plugin or ``None`` if not registered.N)rE   items)r%   r!   r3   vals       r   rp   zPluginManager.get_name   s0    **002 	ID#}	r   c                    |j                         r=|j                  r1t        |j                  d|j                  d|j
                  d      |j                  j                  r*t        |j                  j                  |j                         t        |j                        t        |j                  j                        z
  }|rJt        |j                  d|j                  d|j
                  dt        |j                        d|d	      |j                  rgt        j                  |j                        sGt        |j                  d|j                  d|j
                  dt        |j                        d      y y )	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   s+   ("6"6'''4  99!!tyy55x7H7HI ))*S1C1C-DD	'
 ((IIx001  (C(CHDUDU(V' ''Jx?P?P4QS  )Wr   c           	      (   | j                   j                  D ]y  }|d   dk7  st        | j                   |      }|j                         r3|j	                         D ]4  }|j
                  rt        |j                  d|d|j                         { y)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     II&& 
	DAw#~tyy$/}}$($6$6$8 '44"7 (#'!:# 	
	r   c                    d}t        t        j                               D ]  }|j                  D ]  }|j                  |k7  sG||j
                  |k7  s6| j                  |j
                        s| j                  |j
                        rZ|j                         }| j                  ||j
                         | 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   rw   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9;< 	D'' HH%(RWW_rww/rww/f2773%%,,fj6F-G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                 H    t        | j                  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                 8    | j                   j                  |      S )z.get all hook callers for the specified plugin.)rF   rI   r   s     r   get_hookcallerszPluginManager.get_hookcallers.  s    ''++F33r   c                 N      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      } |        |j                         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 r   )r   	from_call
get_result)rO   r   rQ   rR   outcomeafterbeforer   s   ```` r   traced_hookexecz>PluginManager.add_hookcall_monitoring.<locals>.traced_hookexecA  sA    9j&1''KG '9j&9%%''r   c                       _         y 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  s+     &&	(  /	+ r   c                     | j                   j                  j                  d      fd}fd}| j                  ||      S )z9enable tracing of hook calls and return an undo function.rK   c                 V    j                   xj                  dz  c_         | |       y )Nr   )rootindent)rO   rP   rQ   	hooktraces      r   r   z,PluginManager.enable_tracing.<locals>.beforeT  s"    NN!!Q&!i(r   c                     | j                    d|d| j                                j                  xj                  dz  c_        y )Nfinishz-->r   )excinfor   r   r   )r   rO   rP   rQ   r   s       r   r   z+PluginManager.enable_tracing.<locals>.afterX  s9    &(Iug6H6H6JKNN!!Q&!r   )rJ   r   rI   r   )r%   r   r   r   s      @r   enable_tracingzPluginManager.enable_tracingP  s:    JJOO''/		)	'
 ++FE::r   c                    t        | j                  |      }|D cg c]  }t        ||      s| }}|rt        |j                  |j
                  |j                  j                  |j                  j                        }|j                         D ]O  }|j                  }||vs|j                  |       | j                  j                  |g       j                  |       Q |S |S c c}w )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.)r7   rK   hasattrr	   r3   rS   r   	namespaceoptsr   r!   r`   rF   
setdefaultra   )	r%   r3   remove_pluginsorigplugplugins_to_remover   rf   r!   s	            r   subset_hook_callerz PluginManager.subset_hook_caller_  s     tyy$'.<Tdd@STTT		4>>499+>+>		B !..0 O!!22$$X. ,,77CJJ2NO I Us
   C%C%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
$L&'
M.B-2D+1!F2+
/4<;r   rB   c                 H    | j                    t        j                  |        S r    )r(   rj   	signature)funcs    r   r   r   t  s!    mm_W..t45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      s]     
   ) N Nv8	1I 	1C C"| |~	7r   