
    %jU                       U d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZmZ d dlmZ d d	lmZ er4d 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!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'  G d d          Z(e)e*e)ef         z  e(z  e+e(         z  Z,	  G d d          Z-ddhZ.de/d<   	 d$dZ0d%d Z1d&d#Z2dS )'    )annotationsN)module_from_specspec_from_file_location)isclass)Path)TYPE_CHECKINGAny)ast_childrenast_kind)ExtensionNotLoadedError)dynamic_import)
ModuleType)	Inspector)
ObjectNode)Visitor)GriffeLoader)Alias	AttributeClassFunctionModuleObject	TypeAliasc                      e Zd ZdZd:dZd:dZd;d	Zd;d
Zd<dZd=dZ	d>dZ
d=dZd<dZd?dZd@dZd?dZd<dZdAd!ZdBd"ZdAd#Zd<d$ZdCd'ZdDd(Zd<d)ZdEd,ZdFd-Zd<d.ZdGd1ZdHd2ZdId5ZdJd6ZdKd8Zd9S )L	Extensionz!Base class for Griffe extensions.nodeast.ASTreturnNonec                \     t          | dt          |           d           |           dS )zPVisit a node.

        Parameters:
            node: The node to visit.
        visit_c                    d S N _s    h/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/griffe/_internal/extensions/base.py<lambda>z!Extension.visit.<locals>.<lambda>%   s    4     N)getattrr   selfr   s     r'   visitzExtension.visit   s8     	A/x~~//@@FFFFFr)   c                T    t          |          D ]}|                     |           dS )zhVisit children nodes.

        Parameters:
            node: The node to visit the children of.
        N)r
   r-   r,   r   childs      r'   generic_visitzExtension.generic_visit'   s:     "$'' 	 	EJJu	 	r)   r   c                L     t          | d|j         d           |           dS )zTInspect a node.

        Parameters:
            node: The node to inspect.
        inspect_c                    d S r#   r$   r%   s    r'   r(   z#Extension.inspect.<locals>.<lambda>6   s     r)   N)r*   kindr+   s     r'   inspectzExtension.inspect0   s3     	>,,,nn==dCCCCCr)   c                R    |j         D ]}|j        s|                     |           dS )zxExtend the base generic inspection with extensions.

        Parameters:
            node: The node to inspect.
        N)childrenalias_target_pathr6   r/   s      r'   generic_inspectzExtension.generic_inspect8   s=     ] 	$ 	$E* $U###	$ 	$r)   ast.AST | ObjectNodeagentVisitor | Inspectorkwargsr	   c                   dS )zRun when visiting a new node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
        Nr$   r,   r   r<   r>   s       r'   on_nodezExtension.on_nodeB         r)   objr   c                   dS )a  Run when an Object has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            obj: The object instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r,   r   rC   r<   r>   s        r'   on_instancezExtension.on_instanceI   rB   r)   loaderr   c                   dS )a  Run on objects (every kind) once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            obj: The object instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   rC   rG   r>   s       r'   	on_objectzExtension.on_object_   rB   r)   c                   dS )a  Run when members of an Object have been loaded.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            obj: The object instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   rE   s        r'   
on_memberszExtension.on_membersl   rB   r)   c                   dS )zRun when visiting a new module node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r@   s       r'   on_module_nodezExtension.on_module_node{   rB   r)   modr   c                   dS )a  Run when a Module has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            mod: The module instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r,   r   rN   r<   r>   s        r'   on_module_instancezExtension.on_module_instance   rB   r)   c                   dS )a  Run on modules once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            mod: The module instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   rN   rG   r>   s       r'   	on_modulezExtension.on_module   rB   r)   c                   dS )a  Run when members of a Module have been loaded.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            mod: The module instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   rP   s        r'   on_module_memberszExtension.on_module_members   rB   r)   c                   dS )zRun when visiting a new class node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r@   s       r'   on_class_nodezExtension.on_class_node   rB   r)   clsr   c                   dS )a  Run when a Class has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            cls: The class instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r,   r   rX   r<   r>   s        r'   on_class_instancezExtension.on_class_instance   rB   r)   c                   dS )a  Run on classes once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            cls: The class instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   rX   rG   r>   s       r'   on_classzExtension.on_class   rB   r)   c                   dS )a   Run when members of a Class have been loaded.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            cls: The class instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   rZ   s        r'   on_class_memberszExtension.on_class_members   rB   r)   c                   dS )zRun when visiting a new function node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r@   s       r'   on_function_nodezExtension.on_function_node   rB   r)   funcr   c                   dS )a  Run when a Function has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            func: The function instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   )r,   r   rb   r<   r>   s        r'   on_function_instancezExtension.on_function_instance  rB   r)   c                   dS )a  Run on functions once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            func: The function instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   rb   rG   r>   s       r'   on_functionzExtension.on_function  rB   r)   c                   dS )zRun when visiting a new attribute node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r@   s       r'   on_attribute_nodezExtension.on_attribute_node+  rB   r)   attrr   c                   dS )a  Run when an Attribute has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            attr: The attribute instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   )r,   r   ri   r<   r>   s        r'   on_attribute_instancezExtension.on_attribute_instance4  rB   r)   c                   dS )a  Run on attributes once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            attr: The attribute instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   ri   rG   r>   s       r'   on_attributezExtension.on_attributeJ  rB   r)   c                   dS )zRun when visiting a new type alias node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   r@   s       r'   on_type_alias_nodezExtension.on_type_alias_nodeW  rB   r)   
type_aliasr   c                   dS )a  Run when a TypeAlias has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            type_alias: The type alias instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr$   )r,   r   rp   r<   r>   s        r'   on_type_alias_instancez Extension.on_type_alias_instance`  rB   r)   c                   dS )a  Run on type aliases once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            type_alias: The type alias instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   rp   rG   r>   s       r'   on_type_aliaszExtension.on_type_aliasv  rB   r)   aliasr   c               N    t          | dd          r | j        d|||d| dS dS )a  Run when an Alias has been created.

        Warning:
            This method runs while the object tree is still being constructed:
            data might be incomplete (class inheritance, alias resolution, etc.).
            Only hook onto this event if you know what you're doing.

        Parameters:
            node: The currently visited node.
            alias: The alias instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        __old_on_aliasF)r   ru   r<   Nr$   )r*   on_alias)r,   r   ru   r<   r>   s        r'   on_alias_instancezExtension.on_alias_instance  sM    * 4)511 	IDMHt5HHHHHHH	I 	Ir)   c                   dS )a  Run on aliases once the object tree has been fully constructed.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            alias: The alias instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   ru   rG   r>   s       r'   rx   zExtension.on_alias  rB   r)   pkgc                   dS )a  Run when a package has been completely loaded.

        Note:
            This method runs once the object tree has been fully constructed:
            data is therefore complete and you can safely hook onto this event.

        Parameters:
            pkg: The package (Module) instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr$   )r,   r{   rG   r>   s       r'   
on_packagezExtension.on_package  rB   r)   N)r   r   r   r   )r   r   r   r   )r   r;   r<   r=   r>   r	   r   r   )
r   r;   rC   r   r<   r=   r>   r	   r   r   )rC   r   rG   r   r>   r	   r   r   )
r   r;   rN   r   r<   r=   r>   r	   r   r   )rN   r   rG   r   r>   r	   r   r   )
r   r;   rX   r   r<   r=   r>   r	   r   r   )rX   r   rG   r   r>   r	   r   r   )
r   r;   rb   r   r<   r=   r>   r	   r   r   )rb   r   rG   r   r>   r	   r   r   )
r   r;   ri   r   r<   r=   r>   r	   r   r   )ri   r   rG   r   r>   r	   r   r   )
r   r;   rp   r   r<   r=   r>   r	   r   r   )rp   r   rG   r   r>   r	   r   r   )
r   r;   ru   r   r<   r=   r>   r	   r   r   )ru   r   rG   r   r>   r	   r   r   )r{   r   rG   r   r>   r	   r   r   ) __name__
__module____qualname____doc__r-   r1   r6   r:   rA   rF   rI   rK   rM   rQ   rS   rU   rW   r[   r]   r_   ra   rd   rf   rh   rk   rm   ro   rr   rt   ry   rx   r}   r$   r)   r'   r   r      sV       ++G G G G   D D D D$ $ $ $      ,            ,      ,      ,      ,      ,         ,         ,   I I I I0        r)   r   c                  2    e Zd ZdZddZddZdd
ZddZdS )
ExtensionszLThis class helps iterating on extensions that should run at different times.
extensionsr   r   r   c                (    g | _          | j        |  dS )zrInitialize the extensions container.

        Parameters:
            *extensions: The extensions to add.
        N)_extensionsadd)r,   r   s     r'   __init__zExtensions.__init__  s!     -/*r)   c                D    |D ]}| j                             |           dS )zoAdd extensions to this container.

        Parameters:
            *extensions: The extensions to add.
        N)r   append)r,   r   	extensions      r'   r   zExtensions.add  s7     $ 	/ 	/I##I....	/ 	/r)   r>   r	   c                    dS )z!No-op method for extension hooks.Nr$   )r,   r>   s     r'   _noopzExtensions._noop  rB   r)   eventstrc                R    | j         D ]} t          ||| j                  di | dS )zCall the extension hook for the given event.

        Parameters:
            event: The triggered event.
            **kwargs: Arguments passed to the hook.
        Nr$   )r   r*   r   )r,   r   r>   r   s       r'   callzExtensions.call  sG     ) 	< 	<I1GIudj11;;F;;;;	< 	<r)   N)r   r   r   r   )r>   r	   r   r   )r   r   r>   r	   r   r   )r~   r   r   r   r   r   r   r   r$   r)   r'   r   r     sj        VV   / / / /0 0 0 0< < < < < <r)   r   dataclassesunpack_typeddictzset[str]builtin_extensionspathr   r   r   c                2   t           j                            |                               dd          d         }t	          ||           }|st          d|  d          t          |          }|t          j        |<   |j	        
                    |           |S )N.   r   z#Could not import module from path '')osr   basenamersplitr   r   r   sysmodulesrG   exec_module)r   module_namespecmodules       r'   _load_extension_pathr     s    '""4((//Q77:K";55D U%&SD&S&S&STTTd##F%CKKF###Mr)   r   2str | dict[str, Any] | Extension | type[Extension]Extension | list[Extension]c                   d}t          | t                    r| S t          |           rt          | t                    r
 |             S t          | t                    rAt          t          |                                                     \  }t          |          }nt          |           }i |	                    d          }|dk    s|r0dt          |          j        vr|                    dd          \  }}nd}|t          v rd| }nVt          j                            |          r7	 t#          |          }n&# t$          $ r}t'          d| d          |d}~ww xY w|sZ	 t)          |          }nI# t*          $ r}t'          d| d          |d}~wt$          $ r}t'          d| d|           |d}~ww xY wt          |          rt          |t                    r |di S |r@	  t-          ||          di S # t.          $ r}t'          d| d	| d
          |d}~ww xY wd t1          |                                          D             }fd|D             S )a  Load a configured extension.

    Parameters:
        extension: An extension, with potential configuration options.

    Raises:
        ExtensionNotLoadedError: When the extension cannot be loaded,
            either because the module is not found, or because it does not expose
            the Extension attribute. ImportError will bubble up so users can see
            the traceback.

    Returns:
        An extension instance.
    N:r   zgriffe._internal.extensions.zExtension module 'z' could not be foundz!Error while importing extension 'z': z
' has no 'z' attributec                l    g | ]1}t          |          r t          |t                    r|t          u/|2S r$   )r   
issubclassr   ).0rC   s     r'   
<listcomp>z#_load_extension.<locals>.<listcomp>D  sL       GCLLEOPSU^E_E_dgoxdxdxdxdxdxr)   c                     g | ]
} |d i S )r$   r$   )r   extoptionss     r'   r   z#_load_extension.<locals>.<listcomp>G  s%    111sCCNN'NN111r)   r$   )
isinstancer   r   r   dictnextiteritemsr   countr   driver   r   r   r   existsr   ImportErrorr   r   ModuleNotFoundErrorr*   AttributeErrorvarsvalues)r   
ext_objectimport_pathcolonsextension_nameerrorr   r   s          @r'   _load_extensionr     s+   " J )Y''  y jI>> y{{ )T"" 
#D):):$;$;<<W +&& )nn s##FzzfzD,=,=,C!C!C&1&8&8a&@&@#^^ (((B[BB		$	$ m	m-k::JJ 	m 	m 	m)*`{*`*`*`aagll	m
  r	r'44JJ" 	m 	m 	m)*`{*`*`*`aagll 	r 	r 	r)*ek*e*e^c*e*efflqq	r z %z*i@@ %z$$G$$$  	67:~66AAAAA 	 	 	)W[WWNWWW 	 J''..00  J 2111j1111sT   .D> >
E!EE!'E7 7
F=FF="F88F=/H 
H+H&&H+extsLoadableExtensionTypec                 (   t                      }| D ]F}t          |          }t          |t                    r |j        |  1|                    |           Gddlm} |j        D ]}t          |          |u r n |j        t          d            |S )zLoad configured extensions.

    Parameters:
        exts: Extensions with potential configuration options.

    Returns:
        An extensions container.
    r   )DataclassesExtensionr   )	r   r   r   listr   'griffe._internal.extensions.dataclassesr   r   type)r   r   r   r   r   s        r'   load_extensionsr   J  s     J    	i((c4   	 JNC   NN3 MLLLLL% 8 899,,,E - 	
6677r)   )r   r   r   r   )r   r   r   r   )r   r   r   r   )3
__future__r   r   r   importlib.utilr   r   r6   r   pathlibr   typingr   r	   !griffe._internal.agents.nodes.astr
   r   griffe._internal.exceptionsr   griffe._internal.importerr   asttypesr   !griffe._internal.agents.inspectorr   %griffe._internal.agents.nodes.runtimer   griffe._internal.agents.visitorr   griffe._internal.loaderr   griffe._internal.modelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   __annotations__r   r   r   r$   r)   r'   <module>r      sT   # " " " " " " 				 



 D D D D D D D D             % % % % % % % % D D D D D D D D ? ? ? ? ? ? 4 4 4 4 4 4 eJJJ      ;;;;;;@@@@@@777777444444ddddddddddddddddddW W W W W W W Wt d38n,y84	?J  < <  <  <  <  <  <  <  <H        /   X2 X2 X2 X2v     r)   