HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/pluggy/__pycache__/_manager.cpython-310.pyc
o

we=L�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
dd	lmZd
dlmZd
dlmZd
d
lmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZe	e eee
e efgdfZ!e	eee eee
e efgdfZ"d*dd�Z#Gd d!�d!e$�Z%Gd"d#�d#�Z&Gd$d%�d%�Z'd+d(d)�Z(dS),�)�annotationsN)�Any)�Callable)�cast)�Final)�Iterable)�Mapping)�Sequence�)�_tracing)�
_multicall)�_HookImplFunction)�
_Namespace)�_Plugin)�_SubsetHookCaller)�
HookCaller)�HookImpl)�HookimplOpts)�	HookRelay)�HookspecOpts)�normalize_hookimpl_opts)�Result�warning�Warning�function�Callable[..., object]�return�NonecCs.ttj|�}tj|t|�|jj|jjd�dS)N)�lineno�filename)	r�types�FunctionType�warnings�
warn_explicit�type�__code__�co_firstlineno�co_filename)rr�func�r)�H/home/arjun/projects/env/lib/python3.10/site-packages/pluggy/_manager.py�_warn_for_function"s
�r+cs"eZdZdZd
�fdd	�Z�ZS)�PluginValidationErrorzyPlugin failed validation.

    :param plugin: The plugin which failed validation.
    :param message: Error message.
    �pluginr�message�strrrcst��|�||_dS�N)�super�__init__r-)�selfr-r.��	__class__r)r*r23s
zPluginValidationError.__init__)r-rr.r/rr)�__name__�
__module__�__qualname__�__doc__r2�
__classcell__r)r)r4r*r,,sr,c@s>eZdZdZddd�Zedd	d
��Zddd
d�Zddd�ZdS)�
DistFacadez$Emulate a pkg_resources Distribution�dist�importlib.metadata.DistributionrrcCs
||_dSr0)�_dist)r3r<r)r)r*r2<�
zDistFacade.__init__r/cCs|jd}|S)N�name)�metadata�r3r@r)r)r*�project_name?s
zDistFacade.project_nameN�attrcCst|j||�Sr0)�getattrr>)r3rD�defaultr)r)r*�__getattr__DszDistFacade.__getattr__�	list[str]cCstt|j�ddg�S)Nr>rC)�sorted�dirr>�r3r)r)r*�__dir__GszDistFacade.__dir__)r<r=rr)rr/r0)rDr/)rrH)	r6r7r8r9r2�propertyrCrGrLr)r)r)r*r;9s
r;c@seZdZdZdZdd�Zd[dd�Zd\d]dd�Zd^dd�Z	d_d`dd�Zdad d!�Z	dbd"d#�Z
dcd&d'�Zddd)d*�Zded,d-�Z
dfd.d/�Zdgd0d1�Zdhd2d3�Zdbd4d5�Zdid6d7�Zdjd<d=�Zdkd>d?�Zd\dldBdC�ZdmdEdF�ZdndHdI�ZdodKdL�ZdpdRdS�ZdqdTdU�ZdrdXdY�ZdS)s�
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)
    <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!
    rCr/rrcCs4||_i|_g|_t�|_t���d�|_t	|_
dS)N�pluginmanage)rC�_name2plugin�_plugin_distinfor�hookr�	TagTracer�get�tracer�_inner_hookexec)r3rCr)r)r*r2\s�
zPluginManager.__init__�	hook_name�methods�Sequence[HookImpl]�kwargs�Mapping[str, object]�firstresult�bool�object | list[object]cCs|�||||�Sr0�rV)r3rWrXrZr\r)r)r*�	_hookexecjs	zPluginManager._hookexecNr-rr@�
str | NonecCs|p|�|�}||jvr!|j�|d�durdStd|||jf��||j��vr2td|||jf��||j|<t|�D]P}|�||�}|dur�t|�t||�}t	||||�}|�d�p]|}t|j
|d�}|durwt||j�}t
|j
||�n|��r�|�||�|�|�|�|�q;|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: %s=%s
%sz:Plugin already registered under a different name: %s=%s
%s�specname)�get_canonical_namerPrT�
ValueError�valuesrJ�parse_hookimpl_optsrrErrRrr`�setattr�has_spec�_verify_hook�_maybe_apply_history�
_add_hookimpl)r3r-r@�plugin_name�
hookimpl_opts�method�hookimplrRr)r)r*�registerusB

��
��



�zPluginManager.register�HookimplOpts | NonecCs`t||�}t�|�sdSzt||jdd�}Wnty"i}Ynw|dur.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)rE�inspect�	isroutinerC�	Exception�
isinstance�dict)r3r-r@ro�resr)r)r*rg�s

��z!PluginManager.parse_hookimpl_opts�_Plugin | None�
Any | NonecCs�|dur|dusJd��|�|�}|dusJd��|dur(|�|�}|dur(dS|�|�}|r9|D]}|�|�q1|j�|�rI|dusEJ�|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_plugin�get_hookcallers�_remove_pluginrPrT)r3r-r@�hookcallers�
hookcallerr)r)r*�
unregister�s 



zPluginManager.unregistercCs|j|d�d|j|<dS)zHBlock registrations of the given name, unregister if already registered.�r@N)r�rPrBr)r)r*�set_blocked�szPluginManager.set_blockedcCs||jvo|j|duS)z0Return whether the given plugin name is blocked.N)rPrBr)r)r*�
is_blocked�szPluginManager.is_blocked�module_or_classrcCs�g}t|�D]?}|�||�}|durEt|j|d�}|dur-t||j||�}t|j||�n|�||�|��D]}|�	||�q7|�
|�q|sStd|j�d|����dS)z�Add 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 )
rJ�parse_hookspec_optsrErRrr`rh�set_specification�
get_hookimplsrj�appendrerC)r3r��namesr@�	spec_opts�hc�hookfunctionr)r)r*�
add_hookspecs�s$
���zPluginManager.add_hookspecs�HookspecOpts | NonecCs t||�}t||jdd�}|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)rErC)r3r�r@ro�optsr)r)r*r�s
z!PluginManager.parse_hookspec_opts�set[Any]cC�t|j���S)z.Return a set of all registered plugin objects.)�setrPrfrKr)r)r*�get_plugins�zPluginManager.get_pluginscst�fdd�|j��D��S)z0Return whether the plugin is already registered.c3s�|]}�|kVqdSr0r))�.0�val�r-r)r*�	<genexpr>s�z.PluginManager.is_registered.<locals>.<genexpr>)�anyrPrf)r3r-r)r�r*�
is_registeredszPluginManager.is_registeredcCst|dd�}|p
tt|��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) <register>`.
        To obtain the name of a registered plugin use :meth:`get_name(plugin)
        <get_name>` instead.
        r6N)rEr/�id)r3r-r@r)r)r*rdsz PluginManager.get_canonical_namecCs|j�|�S)z:Return the plugin registered under the given name, if any.)rPrTrBr)r)r*r})szPluginManager.get_plugincCs|�|�duS)z:Return whether a plugin with the given name is registered.N)r}rBr)r)r*�
has_plugin-r�zPluginManager.has_plugincCs(|j��D]\}}||kr|SqdS)zPReturn the name the plugin is registered under, or ``None`` if
        is isn't.N)rP�items)r3r-r@r�r)r)r*r|1s
�zPluginManager.get_namerRrrprcCs�|��r|js
|jrt|jd|j|jf��|jdusJ�|jjr)t	|jj|j
�t|j�t|jj�}|rGt|jd|j|jt
|j
�|f��|jsM|jrct�|j
�sct|jd|j|jt
|j
�f��|jry|jr{t|jd|j|jt
|j
�f��dSdS)NzFPlugin %r
hook %r
historic incompatible with yield/wrapper/hookwrapperz~Plugin %r for hook %r
hookimpl definition: %s
Argument(s) %s are declared in the hookimpl but can not be found in the hookspecz�Plugin %r for hook %r
hookimpl definition: %s
Declared as wrapper=True or hookwrapper=True but function is not a generator functionzrPlugin %r for hook %r
hookimpl definition: %s
The wrapper=True and hookwrapper=True options are mutually exclusive)�is_historic�hookwrapper�wrapperr,r-rmr@�spec�warn_on_implr+rr��argnames�
_formatdefrt�isgeneratorfunction)r3rRrp�	notinspecr)r)r*rj9sT
�������
������zPluginManager._verify_hookcCs\|jjD]'}|ddkr+t|j|�}|��s+|��D]}|js*t|jd||jf��qqdS)z�Verify that all hooks which have not been verified against a
        hook specification are optional, otherwise raise
        :exc:`PluginValidationError`.r�_zunknown hook %r in plugin %rN)rR�__dict__rErir��optionalhookr,r-)r3r@rRrpr)r)r*�
check_pendinghs�����zPluginManager.check_pending�group�intcCs�d}ttj���D]=}|jD]7}|j|ks*|dur|j|ks*|�|j�s*|�|j�r+q|�	�}|j
||jd�|j�|t
|�f�|d7}qq	|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.
        rNr�r
)�list�	importlibrA�
distributions�entry_pointsr�r@r}r��loadrqrQr�r;)r3r�r@�countr<�epr-r)r)r*�load_setuptools_entrypointsxs 


�
�
�
z)PluginManager.load_setuptools_entrypoints� list[tuple[_Plugin, DistFacade]]cCs
t|j�S)zXReturn a list of (plugin, distinfo) pairs for all
        setuptools-registered plugins.)r�rQrKr)r)r*�list_plugin_distinfo�s
z"PluginManager.list_plugin_distinfo�list[tuple[str, _Plugin]]cCr�)zAReturn a list of (name, plugin) pairs for all registered plugins.)r�rPr�rKr)r)r*�list_name_plugin�r�zPluginManager.list_name_plugin�list[HookCaller] | NonecCsN|�|�dur	dSg}|jj��D]}|��D]}|j|ur#|�|�qq|S)z�Get all hook callers for the specified plugin.

        :returns:
            The hook callers, or ``None`` if ``plugin`` is not registered in
            this plugin manager.
        N)r|rRr�rfr�r-r�)r3r-r�r�rpr)r)r*r~�s

��zPluginManager.get_hookcallers�before�_BeforeTrace�after�_AfterTrace�Callable[[], None]cs2�j�d���fdd�}|�_d��fdd�}|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.
        rWr/�
hook_implsrY�
caller_kwargsr[r\r]rr^cs<�����t������fdd��}�|����|��S)Ncs������Sr0r)r))r�r\r�rW�oldcallr)r*�<lambda>�szPPluginManager.add_hookcall_monitoring.<locals>.traced_hookexec.<locals>.<lambda>)r�	from_call�
get_result)rWr�r�r\�outcome)r�r�r�)r�r\r�rWr*�traced_hookexec�s�z>PluginManager.add_hookcall_monitoring.<locals>.traced_hookexecrcs
��_dSr0r_r))r�r3r)r*�undo�r?z3PluginManager.add_hookcall_monitoring.<locals>.undoN)
rWr/r�rYr�r[r\r]rr^�rrr_)r3r�r�r�r�r))r�r�r�r3r*�add_hookcall_monitoring�s

z%PluginManager.add_hookcall_monitoringcs6|jj�d��d�fd
d�}d�fdd�}|�||�S)zwEnable tracing of hook calls.

        Returns an undo function which, when called, removes the added tracing.
        rRrWr/rXrYrZr[rrcs�jjd7_�||�dS)Nr
)�root�indent)rWrXrZ��	hooktracer)r*r��sz,PluginManager.enable_tracing.<locals>.beforer��Result[object]cs0|jdur�d|d|����jjd8_dS)N�finishz-->r
)�	exceptionr�r�r�)r�rWrXrZr�r)r*r��s
z+PluginManager.enable_tracing.<locals>.afterN)rWr/rXrYrZr[rr)
r�r�rWr/rXrYrZr[rr)rUr�rTr�)r3r�r�r)r�r*�enable_tracing�s
zPluginManager.enable_tracing�remove_plugins�Iterable[_Plugin]cs0t|j��}�fdd�|D�}|rt||�S|S)z�Return a proxy :class:`~pluggy.HookCaller` instance for the named
        method which manages calls to all registered plugins except the ones
        from remove_plugins.csh|]	}t|��r|�qSr))�hasattr)r��plugr�r)r*�	<setcomp>�sz3PluginManager.subset_hook_caller.<locals>.<setcomp>)rErRr)r3r@r��orig�plugins_to_remover)r�r*�subset_hook_caller�s

z PluginManager.subset_hook_caller)rCr/rr)
rWr/rXrYrZr[r\r]rr^r0)r-rr@rarra)r-rr@r/rrr)NN)r-rzr@rarr{)r@r/rr)r@r/rr])r�rrr)r�rr@r/rr�)rr�)r-rrr])r-rrr/)r@r/rr{)r-rrra)rRrrprrrr�)r�r/r@rarr�)rr�)rr�)r-rrr�)r�r�r�r�rr�)rr�)r@r/r�r�rr)r6r7r8r9r2r`rqrgr�r�r�r�r�r�r�rdr}r�r|rjr�r�r�r�r~r�r�r�r)r)r)r*rNKs6


3�
 










/




%rNr(r/cCs|j�t�|���Sr0)r6rt�	signature)r(r)r)r*r��sr�)rrrrrr)r(rrr/))�
__future__r�importlib.metadatar�rtr r"�typingrrrrrrr	�r�_callersr�_hooksr
rrrrrrrrr�_resultrr/r�r�r+rvr,r;rNr�r)r)r)r*�<module>sF$


0