K iNddlmZddlmZddlmZddlmZddlZddlZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z ddlZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZe rddl Z!e e"eeee"e fgdfZ#e ee e"eeee"e fgdfZ$d!dZ%Gdde&Z'GddZ(GddZ)d"d Z*y)#) annotations)Iterable)Mapping)SequenceN)Any)Callable)cast)Final) TYPE_CHECKING)_tracing) _multicall)_HookImplFunction) _Namespace)_Plugin)_SubsetHookCaller) HookCaller)HookImpl) HookimplOpts) HookRelay) HookspecOpts)normalize_hookimpl_opts)Resultcttj|}tj|t ||j j|j jy)N)linenofilename) r types FunctionTypewarnings warn_explicittype__code__co_firstlineno co_filename)warningfunctionfuncs U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pluggy/_manager.py_warn_for_functionr)'sF ""H -D  W }}++** c$eZdZdZdfd ZxZS)PluginValidationErrorzyPlugin failed validation. :param plugin: The plugin which failed validation. :param message: Error message. c2t||||_yN)super__init__plugin)selfr1message __class__s r(r0zPluginValidationError.__init__8s ! r*)r1rr3strreturnNone)__name__ __module__ __qualname____doc__r0 __classcell__)r4s@r(r,r,1s r*r,c<eZdZdZddZeddZd d dZd dZy) DistFacadez$Emulate a pkg_resources Distributionc||_yr.)_dist)r2dists r(r0zDistFacade.__init__As  r*c$|jd}|S)Nname)metadatar2rCs r( project_namezDistFacade.project_nameDsMM&) r*Nc0t|j||Sr.)getattrr@)r2attrdefaults r( __getattr__zDistFacade.__getattr__Istzz411r*cHtt|jddgzS)Nr@rF)sorteddirr@r2s r(__dir__zDistFacade.__dir__Lsc$**o.(AABBr*)rAzimportlib.metadata.Distributionr6r7)r6r5r.)rIr5rJ Any | Noner6r)r6z list[str]) r8r9r:r;r0propertyrFrKrPr*r(r>r>>s).2Cr*r>c"eZdZdZddZ ddZdddZd dZ d! d"dZd#dZ d$d Z d$d Z d%d Z d&d Z d'd Zd(dZd)dZd*dZd$dZd+dZd,dZd-dZdd.dZd/dZd0dZd1dZ d2dZd3dZ d4dZy)5 PluginManageraQCore 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) `. You can register plugin objects (which contain hook implementations) by calling :meth:`register(plugin) `. 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! c||_i|_g|_t|_t j jd|_t|_ y)N pluginmanage) rF _name2plugin_plugin_distinforhookr TagTracergettracer_inner_hookexec)r2rFs r(r0zPluginManager.__init__asM#/79IK%; 3;3E3E3G3K3K 4   *r*c*|j||||Sr.r^)r2 hook_namemethodskwargs firstresults r( _hookexeczPluginManager._hookexecos##Iw LLr*Nc(|xs|j|}||jvr;|jj|dytd|d|d|j||jj vrtd|d|d|j||j|<t |D]}|j ||}|t|t||}t||||}|jdxs|}t|j|d}|.t||j}t|j||n3|jr#|j|||j!||j#||S)aRegister 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_namerXr\ ValueErrorvaluesrNparse_hookimpl_optsrrHrrZrresetattrhas_spec _verify_hook_maybe_apply_history _add_hookimpl)r2r1rC plugin_name hookimpl_optsmethodhookimplrZs r(registerzPluginManager.registerzs=d55f= $++ +  $$["5=2-q4+<+<*=?  T&&--/ /D-q4+<+<*=? *0+&K -D 44VTBM(' 64;FD4I#FKO$((4<*1$))T4*H<%dDNN;DDIItT2]]_%%dH5--h7""8, -r*ct||}tj|sy t||jdzd}|t |t sd}|S#t$ri}Y#wxYw)aTry 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)rHinspect isroutinerF Exception isinstancedict)r2r1rCrvress r(rnz!PluginManager.parse_hookimpl_optssr!.  ( '.))G3T(C ?:c4#8C  C sA A"!A"c*|#|Jd|j|}|Jd||j|}|y|j|}|r|D]}|j||jj |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 specifiedzplugin is not registered)get_name get_pluginget_hookcallers_remove_pluginrXr\)r2r1rC hookcallers hookcallers r( unregisterzPluginManager.unregisters <% T'T T%==(D# ?%? ?# >__T*F~**62 ) 2 ))&1 2     &# ##!!$' r*cF|j|d|j|<y)zHBlock registrations of the given name, unregister if already registered.rCN)rrXrEs r( set_blockedzPluginManager.set_blockeds  T""&$r*cD||jvxr|j|duS)z0Return whether the given plugin name is blocked.N)rXrEs r( is_blockedzPluginManager.is_blockeds(t(((LT->->t-D-LLr*cX|jj|d|j|=yy)zQUnblocks a name. Returns whether the name was actually blocked. rgTFrXr\rEs r(unblockzPluginManager.unblocks1    r * 2!!$'r*cg}t|D]}|j||}|t|j|d}|0t ||j ||}t |j||n9|j|||jD]}|j|||j||std|jd|y)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`. Nzdid not find any z hooks in ) rNparse_hookspec_optsrHrZrreroset_specification get_hookimplsrqappendrlrF)r2module_or_classnamesrC spec_optshc hookfunctions r( add_hookspecszPluginManager.add_hookspecss ( #D00$GI$(/ 4(F:#D$../9UBDIItR0(()D(*(8(8(:< ))"l;< T" ##D$5$5#8 ?BUV r*cRt||}t||jdzd}|S)aTry 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)rHrF)r2rrCrvoptss r(rz!PluginManager.parse_hookspec_optss/$/$+FD4E4E4OQU$V r*cb|jjDchc]}|| c}Scc}w)z.Return a set of all registered plugin objects.)rXrm)r2xs r( get_pluginszPluginManager.get_plugins%s),,335GaGGGs,,c\tfd|jjDS)z0Return whether the plugin is already registered.c3(K|] }|k( ywr.rS).0valr1s r( z.PluginManager.is_registered..+sGS6S=Gs)anyrXrm)r2r1s `r( is_registeredzPluginManager.is_registered)s#GD,=,=,D,D,FGGGr*cLt|dd}|xstt|S)a3Return 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) `. To obtain the name of a registered plugin use :meth:`get_name(plugin) ` instead. r8N)rHr5id)r2r1rCs r(rkz PluginManager.get_canonical_name-s%#6:t<&s2f:&r*c8|jj|S)z:Return the plugin registered under the given name, if any.rrEs r(rzPluginManager.get_plugin8s  $$T**r*c(|j|duS)z:Return whether a plugin with the given name is registered.N)rrEs r( has_pluginzPluginManager.has_plugin<st$D00r*cZ|jjD]\}}||k(s |cSy)zPReturn the name the plugin is registered under, or ``None`` if is isn't.N)rXitems)r2r1rCrs r(rzPluginManager.get_name@s7**002 ID#}  r*c |jrI|js |jr1t|jd|j d|j d|jJ|jjr*t|jj|jt|jt|jjz }|rJt|jd|j d|j dt|jd|d |jjrO|jD]@}|jjj|}|+t||jB|js |jrft!j"|jsGt|jd|j d|j dt|jd|jrT|jrGt|jd|j d|j dt|jd yy) NzPlugin 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 hookwrapperwrapperr,r1rtrCspec warn_on_implr)r&setargnames _formatdefwarn_on_impl_argsr\r{isgeneratorfunction)r2rZrw notinspechookimpl_argnameargname_warnings r(rqzPluginManager._verify_hookHsI    8#7#78;K;K'(..1 FGG  yy$$$ 99 ! ! tyy55x7H7H I))*S1C1C-DD '(..1DII=I((283D3D(E'FG(k*33  99 & &$,$5$5 K "&))"="="A"ABR"S".&8I8IJ K    4 4--h.?.?@'(..1DII=I((283D3D(E'FG;;     4 4'(..1DII=I((283D3D(E'FGWW !5 r*c (|jjD]y}|ddk(r t|j|}|jr3|j D]4}|j rt |jd|d|j{y)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)rZ__dict__rHrpr optionalhookr,r1)r2rCrZrws r( check_pendingzPluginManager.check_pendingxsII&& DAw#~&tyy$7D==? $ 2 2 4H#003$OO+D8;x>QR r*cddl}d}t|jjD]}|jD]}|j |k7sG||j |k7s6|j|j s|j|j rZ|j}|j||j |jj|t|f|dz }|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. rNrr )importlib.metadatalistrD distributions entry_pointsgrouprCrrloadrxrYrr>)r2rrC importlibcountrAepr1s r(load_setuptools_entrypointsz)PluginManager.load_setuptools_entrypointss "++99;< D'' HH%(RWW_rww/rww/ f277 3%%,,fj6F-GH    r*c,t|jS)zXReturn a list of (plugin, distinfo) pairs for all setuptools-registered plugins.)rrYrOs r(list_plugin_distinfoz"PluginManager.list_plugin_distinfosD))**r*cHt|jjS)zAReturn a list of (name, plugin) pairs for all registered plugins.)rrXrrOs r(list_name_pluginzPluginManager.list_name_pluginsD%%++-..r*c|j|yg}|jjjD]7}|j D]"}|j |us|j |$9|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)rrZrrmrr1r)r2r1rrrws r(rzPluginManager.get_hookcallerssw == ( )),,335 3J&446 3??f,&&z2 3 3r*cfj dfd }|_dfd }|S)a7Add 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. ctjfd}||jS)NcSr.rS) caller_kwargsrd hook_implsraoldcallsr(zPPluginManager.add_hookcall_monitoring..traced_hookexec..s :}kRr*)r from_call get_result)rarrrdoutcomeafterbeforers```` r(traced_hookexecz>PluginManager.add_hookcall_monitoring..traced_hookexecsC 9j- 8&&RG '9j- @%%' 'r*c_yr.r`)rr2sr(undoz3PluginManager.add_hookcall_monitoring..undos #*D r*) rar5rSequence[HookImpl]rMapping[str, object]rdboolr6object | list[object]r6r7r`)r2rrrrrs``` @r(add_hookcall_monitoringz%PluginManager.add_hookcall_monitoringsY&& ( (* (0 ( ( # ( / + r*c|jjjd dfd } dfd }|j||S)zwEnable tracing of hook calls. Returns an undo function which, when called, removes the added tracing. rZcVjxjdz c_||y)Nr )rootindent)rarbrc hooktraces r(rz,PluginManager.enable_tracing..befores$ NN ! !Q & ! i (r*c|jd|d|jjxjdzc_y)Nfinishz-->r ) exceptionrrr)rrarbrcrs r(rz+PluginManager.enable_tracing..afters=   ((Iug6H6H6JK NN ! !Q & !r*)rar5rbrrcrr6r7) rzResult[object]rar5rbrrcrr6r7)r]rr\r)r2rrrs @r(enable_tracingzPluginManager.enable_tracings JJOO''/  ) )%7 )AU )  )  '# ' '( ')  '   '++FE::r*ct|j|}|Dchc]}t||s|}}|r t||S|Scc}w)zReturn a proxy :class:`~pluggy.HookCaller` instance for the named method which manages calls to all registered plugins except the ones from remove_plugins.)rHrZhasattrr)r2rCremove_pluginsorigplugplugins_to_removes r(subset_hook_callerz PluginManager.subset_hook_callersM #499d3.<Tdd@STTT $T+<= = Us AA)rFr5r6r7) rar5rbrrcrrdrr6rr.)r1rrC str | Noner6r)r1rrCr5r6zHookimplOpts | None)NN)r1z_Plugin | NonerCrr6rQ)rCr5r6r7)rCr5r6r)rrr6r7)rrrCr5r6zHookspecOpts | None)r6zset[Any])r1rr6r)r1rr6r5)rCr5r6rQ)r1rr6r)rZrrwrr6r7r)rr5rCrr6int)r6z list[tuple[_Plugin, DistFacade]])r6zlist[tuple[str, _Plugin]])r1rr6zlist[HookCaller] | None)r _BeforeTracer _AfterTracer6Callable[[], None])r6r)rCr5rzIterable[_Plugin]r6r)r8r9r:r;r0rerxrnrrrrrrrrrkrrrrqrrrrrrrrrSr*r(rUrUPs( * M M$ M% M  M  M1f4AE$3= @' M4)14 $HH '+1.` <+ / #"#+6# #J;2  ):   r*rUcH|jtj|Sr.)r8r{ signature)r's r(rr s!mm_W..t45 66r*)r%Warningr&Callable[..., object]r6r7)r'rr6r5)+ __future__rcollections.abcrrrr{rtypingrrr r r rr _callersr_hooksrrrrrrrrrr_resultrrrr5rrr)r}r,r>rUrrSr*r(rs"$#$   %%  +hx0'#s(2CDdJK s S(8*OPRVVW  I CC$wwt 7r*