
    F-PhN                       d dl mZ d dlmZ d dlmZ d dlmZ d dlZd dl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l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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lmZ ddlmZ erd dl Z!e
e"ee         ee"e	f         gdf         Z#e
ee	         e"ee         ee"e	f         gdf         Z$d)dZ% G d  d!e&          Z' G d" d#          Z( G d$ d%          Z)d*d(Z*dS )+    )annotations)Iterable)Mapping)SequenceN)Any)Callable)cast)Final)TYPE_CHECKING   )_tracing)
_multicall)_HookImplFunction)
_Namespace)_Plugin)_SubsetHookCaller)
HookCaller)HookImpl)HookimplOpts)	HookRelay)HookspecOpts)normalize_hookimpl_opts)ResultwarningWarningfunctionCallable[..., object]returnNonec                    t          t          j        |          }t          j        | t          |           |j        j        |j        j                   d S )N)linenofilename)	r	   typesFunctionTypewarningswarn_explicittype__code__co_firstlinenoco_filename)r   r   funcs      O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pluggy/_manager.py_warn_for_functionr-   '   sT    "H--DW}+*	         c                  $     e Zd ZdZd	 fdZ xZS )
PluginValidationErrorzyPlugin failed validation.

    :param plugin: The plugin which failed validation.
    :param message: Error message.
    pluginr   messagestrr   r   c                X    t                                          |           || _        d S N)super__init__r1   )selfr1   r2   	__class__s      r,   r7   zPluginValidationError.__init__8   s&    !!!r.   )r1   r   r2   r3   r   r   )__name__
__module____qualname____doc__r7   __classcell__)r9   s   @r,   r0   r0   1   sG                  r.   r0   c                  D    e Zd ZdZddZedd            ZdddZddZd	S )
DistFacadez$Emulate a pkg_resources Distributiondistimportlib.metadata.Distributionr   r   c                    || _         d S r5   )_dist)r8   rA   s     r,   r7   zDistFacade.__init__A   s    


r.   r3   c                     | j         d         }|S )Nname)metadatar8   rF   s     r,   project_namezDistFacade.project_nameD   s    M&)r.   Nattrdefault
Any | Noner   c                .    t          | j        ||          S r5   )getattrrD   )r8   rJ   rK   s      r,   __getattr__zDistFacade.__getattr__I   s    tz4111r.   	list[str]c                N    t          t          | j                  ddgz             S )NrD   rI   )sorteddirrD   r8   s    r,   __dir__zDistFacade.__dir__L   s"    c$*oo.(AABBBr.   )rA   rB   r   r   )r   r3   r5   )rJ   r3   rK   rL   r   r   )r   rP   )	r:   r;   r<   r=   r7   propertyrI   rO   rU    r.   r,   r@   r@   >   s        ..       X2 2 2 2 2C C C C C Cr.   r@   c                      e Zd ZdZdCdZdDdZdEdFdZdGdZ	 dHdIdZdJdZ	dKdZ
dKdZdLd ZdMd"ZdNd$ZdOd%ZdPd&ZdQd'ZdKd(ZdRd)ZdSd.ZdTd/ZdEdUd2ZdVd4ZdWd6ZdXd8ZdYd>ZdZd?Zd[dBZdS )\PluginManageraQ  Core class which manages registration of plugin objects and 1:N hook
    calling.

    You can register new hooks by calling :meth:`add_hookspecs(module_or_class)
    <PluginManager.add_hookspecs>`.

    You can register plugin objects (which contain hook implementations) by
    calling :meth:`register(plugin) <PluginManager.register>`.

    For debugging purposes you can call :meth:`PluginManager.enable_tracing`
    which will subsequently send debug information to the trace helper.

    :param project_name:
        The short project name. Prefer snake case. Make sure it's unique!
    rI   r3   r   r   c                    || _         i | _        g | _        t                      | _        t          j                                        d          | _        t          | _
        d S )Npluginmanage)rI   _name2plugin_plugin_distinfor   hookr   	TagTracergettracer   _inner_hookexec)r8   rI   s     r,   r7   zPluginManager.__init__a   sZ    #/79IK %;;	3;3E3G3G3K3K4
 4

  *r.   	hook_namemethodsSequence[HookImpl]kwargsMapping[str, object]firstresultboolobject | list[object]c                2    |                      ||||          S r5   rb   )r8   rc   rd   rf   rh   s        r,   	_hookexeczPluginManager._hookexeco   s     ##IwLLLr.   Nr1   r   rF   
str | Nonec                R   |p|                      |          }|| j        v r:| j                            |d          dS t          d| d| d| j                   || j                                        v rt          d| d| d| j                   || j        |<   t          |          D ]}|                     ||          }|t          |           t          ||          }t          ||||          }|                    d          p|}t          | j
        |d          }|,t          || j                  }t          | j
        ||           n?|                                r+|                     ||           |                    |           |                    |           |S )a  Register a plugin and return its name.

        :param name:
            The name under which to register the plugin. If not specified, a
            name is generated using :func:`get_canonical_name`.

        :returns:
            The plugin name. If the name is blocked from registering, returns
            ``None``.

        If the plugin is already registered, raises a :exc:`ValueError`.
        Nz Plugin name already registered: =
z2Plugin already registered under a different name: specname)get_canonical_namer\   r`   
ValueErrorvaluesrS   parse_hookimpl_optsr   rN   r   r^   r   rm   setattrhas_spec_verify_hook_maybe_apply_history_add_hookimpl)r8   r1   rF   plugin_namehookimpl_optsmethodhookimplr^   s           r,   registerzPluginManager.registerz   s    =d55f==$+++ $$["55=t?? ?!'? ?+/+<? ?  
 T&--////?? ?!'? ?+/+<? ?   *0+& KK 	- 	-D 44VTBBM('6664;FD4I4I#FKOO$((44<*1$)T4*H*H<%dDN;;DDItT2222]]__ 8%%dH555--h777""8,,,r.   HookimplOpts | Nonec                    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 )a  Try to obtain a hook implementation from an item with the given name
        in the given plugin which is being searched for hook impls.

        :returns:
            The parsed hookimpl options, or None to skip the given item.

        This method can be overridden by ``PluginManager`` subclasses to
        customize how hook implementation are picked up. By default, returns the
        options for items decorated with :class:`HookimplMarker`.
        N_impl)rN   inspect	isroutinerI   	Exception
isinstancedict)r8   r1   rF   r   ress        r,   rw   z!PluginManager.parse_hookimpl_opts   s     !.. (( 	4	'.)G3T( (CC  	 	 	CCC	?:c4#8#8?C
s   A AA_Plugin | NonerL   c                H   |-|
J d            |                      |          }|
J d            ||                     |          }|dS |                     |          }|r|D ]}|                    |           | j                            |          r|J | j        |= |S )a
  Unregister a plugin and all of its hook implementations.

        The plugin can be specified either by the plugin object or the plugin
        name. If both are specified, they must agree.

        Returns the unregistered plugin, or ``None`` if not found.
        Nz+one of name or plugin needs to be specifiedzplugin is not registered)get_name
get_pluginget_hookcallers_remove_pluginr\   r`   )r8   r1   rF   hookcallers
hookcallers        r,   
unregisterzPluginManager.unregister   s     <%%'T%%%==((D##%?###>__T**F~t**622 	2) 2 2
))&1111   && 	(###!$'r.   c                F    |                      |           d| j        |<   dS )zHBlock registrations of the given name, unregister if already registered.rF   N)r   r\   rH   s     r,   set_blockedzPluginManager.set_blocked   s)    T""""&$r.   c                2    || j         v o| j         |         du S )z0Return whether the given plugin name is blocked.N)r\   rH   s     r,   
is_blockedzPluginManager.is_blocked   s"    t((LT->t-D-LLr.   c                P    | j                             |d          
| j         |= dS dS )zQUnblocks a name.

        Returns whether the name was actually blocked.
        rp   NTFr\   r`   rH   s     r,   unblockzPluginManager.unblock   s2    
   r**2!$'4ur.   module_or_classr   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 as hook specifications if they have been
        decorated with a matching :class:`HookspecMarker`.
        Nzdid not find any z
 hooks in )rS   parse_hookspec_optsrN   r^   r   rm   rx   set_specificationget_hookimplsrz   appendru   rI   )r8   r   namesrF   	spec_optshchookfunctions          r,   add_hookspecszPluginManager.add_hookspecs   s    (( 	# 	#D00$GGI$(/	4(F(F:#D$./9UUBDItR0000 (()DDD(*(8(8(:(: < <))"l;;;;T""" 	VD$5VV?VV  	 	r.   HookspecOpts | Nonec                X    t          ||          }t          || j        dz   d          }|S )a  Try to obtain a hook specification from an item with the given name
        in the given module or class which is being searched for hook specs.

        :returns:
            The parsed hookspec options for defining a hook, or None to skip the
            given item.

        This method can be overridden by ``PluginManager`` subclasses to
        customize how hook specifications are picked up. By default, returns the
        options for items decorated with :class:`HookspecMarker`.
        _specN)rN   rI   )r8   r   rF   r   optss        r,   r   z!PluginManager.parse_hookspec_opts  s2     $//$+FD4E4OQU$V$Vr.   set[Any]c                H    d | j                                         D             S )z.Return a set of all registered plugin objects.c                    h | ]}||S r5   rW   ).0xs     r,   	<setcomp>z,PluginManager.get_plugins.<locals>.<setcomp>'  s    GGGar.   )r\   rv   rT   s    r,   get_pluginszPluginManager.get_plugins%  s%    GG4,3355GGGGr.   c                h    t          fd| j                                        D                       S )z0Return whether the plugin is already registered.c              3  $   K   | ]
}|k    V  d S r5   rW   )r   valr1   s     r,   	<genexpr>z.PluginManager.is_registered.<locals>.<genexpr>+  s'      GGS6S=GGGGGGr.   )anyr\   rv   )r8   r1   s    `r,   is_registeredzPluginManager.is_registered)  s5    GGGGD,=,D,D,F,FGGGGGGr.   c                `    t          |dd          }|pt          t          |                    S )a3  Return a canonical name for a plugin object.

        Note that a plugin may be registered under a different name
        specified by the caller of :meth:`register(plugin, name) <register>`.
        To obtain the name of a registered plugin use :meth:`get_name(plugin)
        <get_name>` instead.
        r:   N)rN   r3   id)r8   r1   rF   s      r,   rt   z PluginManager.get_canonical_name-  s,     #6:t<<&s2f::&r.   c                6    | j                             |          S )z:Return the plugin registered under the given name, if any.r   rH   s     r,   r   zPluginManager.get_plugin8  s     $$T***r.   c                0    |                      |          duS )z:Return whether a plugin with the given name is registered.N)r   rH   s     r,   
has_pluginzPluginManager.has_plugin<  s    t$$D00r.   c                X    | j                                         D ]\  }}||k    r|c S dS )zPReturn the name the plugin is registered under, or ``None`` if
        is isn't.N)r\   items)r8   r1   rF   r   s       r,   r   zPluginManager.get_name@  sB     *0022 	 	ID#}} tr.   r^   r   r   r   c                   |                                 r4|j        s|j        r&t          |j        d|j        d|j        d          |j        J |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        j        r@|j        D ]8}|j        j                            |          }|t          ||j
                   9|j        s|j        rTt!          j        |j
                  s;t          |j        d|j        d|j        dt          |j
                   d          |j        rB|j        r=t          |j        d|j        d|j        dt          |j
                   d	          d S d S )
NzPlugin z
hook z5
historic incompatible with yield/wrapper/hookwrapperz
 for hook z
hookimpl definition: z
Argument(s) zB are declared in the hookimpl but can not be found in the hookspeczV
Declared as wrapper=True or hookwrapper=True but function is not a generator functionzE
The wrapper=True and hookwrapper=True options are mutually exclusive)is_historichookwrapperwrapperr0   r1   r}   rF   specwarn_on_implr-   r   setargnames
_formatdefwarn_on_impl_argsr`   r   isgeneratorfunction)r8   r^   r   	notinspechookimpl_argnameargname_warnings         r,   rz   zPluginManager._verify_hookH  s    	8#7 	8;K 	'G(. G G G G G   y$$$9! 	Jty5x7HIII )**S1C-D-DD	 	'3(. 3 3DI 3 3(283D(E(E3 3(3 3 3   9& 	K$,$5 K K "&)"="A"ABR"S"S".&8IJJJ 		 ( 4		-h.?@@		 (;(. ; ;DI ; ;(283D(E(E; ; ;    	 4 	'W(. W WDI W W(283D(E(EW W W  	 	 	 	r.   c           	        | j         j        D ]v}|d         dk    rt          | j         |          }|                                s>|                                D ])}|j        s t          |j        d|d|j                  *wdS )zVerify that all hooks which have not been verified against a
        hook specification are optional, otherwise raise
        :exc:`PluginValidationError`.r   _zunknown hook z in plugin N)r^   __dict__rN   ry   r   optionalhookr0   r1   )r8   rF   r^   r   s       r,   check_pendingzPluginManager.check_pendingx  s     I& 
	 
	DAw#~~&ty$77D==??  $ 2 2 4 4  H#0 3$ORDRRxRR  
	 
	r.   groupintc                   ddl }d}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 group:
            Entry point group to load plugins.
        :param name:
            If given, loads only plugins with the given ``name``.

        :return:
            The number of plugins loaded by this call.
        r   Nr   r   )importlib.metadatalistrG   distributionsentry_pointsr   rF   r   r   loadr   r]   r   r@   )r8   r   rF   	importlibcountrA   epr1   s           r,   load_setuptools_entrypointsz)PluginManager.load_setuptools_entrypoints  s     	"!!!+99;;<< 	 	D'  H%%(RW__rw// .= rw// .=
 f27333%,,fj6F6F-GHHH
 r.    list[tuple[_Plugin, DistFacade]]c                *    t          | j                  S )zXReturn a list of (plugin, distinfo) pairs for all
        setuptools-registered plugins.)r   r]   rT   s    r,   list_plugin_distinfoz"PluginManager.list_plugin_distinfo  s     D)***r.   list[tuple[str, _Plugin]]c                N    t          | j                                                  S )zAReturn a list of (name, plugin) pairs for all registered plugins.)r   r\   r   rT   s    r,   list_name_pluginzPluginManager.list_name_plugin  s    D%++--...r.   list[HookCaller] | Nonec                    |                      |          dS g }| j        j                                        D ]7}|                                D ] }|j        |u r|                    |           !8|S )zGet all hook callers for the specified plugin.

        :returns:
            The hook callers, or ``None`` if ``plugin`` is not registered in
            this plugin manager.
        N)r   r^   r   rv   r   r1   r   )r8   r1   r   r   r   s        r,   r   zPluginManager.get_hookcallers  s     ==  (4),3355 	3 	3J&4466 3 3?f,,&&z2223 r.   before_BeforeTraceafter_AfterTraceCallable[[], None]c                H      j         dfd}| _         d fd}|S )a7  Add before/after tracing functions for all hooks.

        Returns an undo function which, when called, removes 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 :class:`~pluggy.Result` object
        which represents the result of the overall hook call.
        rc   r3   
hook_implsre   caller_kwargsrg   rh   ri   r   rj   c                                  t          j         fd          } |            |                                S )Nc                                  S r5   rW   )r   rh   r   rc   oldcalls   r,   <lambda>zPPluginManager.add_hookcall_monitoring.<locals>.traced_hookexec.<locals>.<lambda>  s    	:}kRR r.   )r   	from_call
get_result)rc   r   r   rh   outcomer   r   r   s   ```` r,   traced_hookexecz>PluginManager.add_hookcall_monitoring.<locals>.traced_hookexec  sq     F9j-888&RRRRRRRR G E'9j-@@@%%'''r.   r   c                      _         d S r5   rl   )r   r8   s   r,   undoz3PluginManager.add_hookcall_monitoring.<locals>.undo  s    #*D   r.   )
rc   r3   r   re   r   rg   rh   ri   r   rj   r   r   rl   )r8   r   r   r   r   r   s   ```  @r,   add_hookcall_monitoringz%PluginManager.add_hookcall_monitoring  sl     &	( 	( 	( 	( 	( 	( 	( 	(  /	+ 	+ 	+ 	+ 	+ 	+ 	+ r.   c                    | j         j                            d          dfd
}dfd}|                     ||          S )zwEnable tracing of hook calls.

        Returns an undo function which, when called, removes the added tracing.
        r^   rc   r3   rd   re   rf   rg   r   r   c                J    j         xj        dz  c_         | |           d S )Nr   )rootindent)rc   rd   rf   	hooktraces      r,   r   z,PluginManager.enable_tracing.<locals>.before  s3     N!!Q&!!Ii(((((r.   r   Result[object]c                    | j           d|d|                                            j        xj        dz  c_        d S )Nfinishz-->r   )	exceptionr   r   r   )r   rc   rd   rf   r   s       r,   r   z+PluginManager.enable_tracing.<locals>.after  sL      (	(Iug6H6H6J6JKKKN!!Q&!!!!r.   )rc   r3   rd   re   rf   rg   r   r   )
r   r   rc   r3   rd   re   rf   rg   r   r   )ra   r   r`   r   )r8   r   r   r   s      @r,   enable_tracingzPluginManager.enable_tracing  sp    
 JO''//		) 	) 	) 	) 	) 	)	' 	' 	' 	' 	' 	' ++FE:::r.   remove_pluginsIterable[_Plugin]c                r    t          | j                  }fd|D             }|rt          ||          S |S )zReturn a proxy :class:`~pluggy.HookCaller` instance for the named
        method which manages calls to all registered plugins except the ones
        from remove_plugins.c                4    h | ]}t          |          |S rW   )hasattr)r   plugrF   s     r,   r   z3PluginManager.subset_hook_caller.<locals>.<setcomp>  s(    TTTdd@S@STTTTTr.   )rN   r^   r   )r8   rF   r  origplugins_to_removes    `   r,   subset_hook_callerz PluginManager.subset_hook_caller  sN     #49d33TTTTnTTT 	>$T+<===r.   )rI   r3   r   r   )
rc   r3   rd   re   rf   rg   rh   ri   r   rj   r5   )r1   r   rF   rn   r   rn   )r1   r   rF   r3   r   r   )NN)r1   r   rF   rn   r   rL   )rF   r3   r   r   )rF   r3   r   ri   )r   r   r   r   )r   r   rF   r3   r   r   )r   r   )r1   r   r   ri   )r1   r   r   r3   )rF   r3   r   rL   )r1   r   r   rn   )r^   r   r   r   r   r   r   )r   r3   rF   rn   r   r   )r   r   )r   r   )r1   r   r   r   )r   r   r   r   r   r   )r   r   )rF   r3   r  r  r   r   )r:   r;   r<   r=   r7   rm   r   rw   r   r   r   r   r   r   r   r   rt   r   r   r   rz   r   r   r   r   r   r   r  r  rW   r.   r,   rY   rY   P   s<         * * * *	M 	M 	M 	M1 1 1 1 1f   4 AE    @' ' ' '
M M M M      4   $H H H HH H H H	' 	' 	' 	'+ + + +1 1 1 1   . . . .`        <+ + + +
/ / / /    # # # #J; ; ; ;2
 
 
 
 
 
r.   rY   r+   r3   c                <    | j          t          j        |            S r5   )r:   r   	signature)r+   s    r,   r   r   
  s     m6W.t44666r.   )r   r   r   r   r   r   )r+   r   r   r3   )+
__future__r   collections.abcr   r   r   r   r#   typingr   r   r	   r
   r   r%    r   _callersr   _hooksr   r   r   r   r   r   r   r   r   r   _resultr   r   r   r3   r   r   r-   r   r0   r@   rY   r   rW   r.   r,   <module>r     s   " " " " " " $ $ $ $ $ $ # # # # # # $ $ $ $ $ $                                                          % % % % % %             % % % % % %                                           + + + + + +         hx0'#s(2CDdJKsS(8*<gc3h>OPRVVW   
 
 
 
 
I 
 
 
C C C C C C C C$w w w w w w w wt7 7 7 7 7 7r.   