
    g9                    l   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mZ d dlmZmZ d dlmZ d d	lmZ er2d 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'  G d d      Z(ee)e*e)ef   e(e+e(   f   Z,	  G d d      Z-dhZ.de/d<   	 ddZ0	 	 	 	 ddZ1ddZ2y)    )annotationsN)module_from_specspec_from_file_location)isclass)Path)TYPE_CHECKINGAnyUnion)ast_childrenast_kind)ExtensionNotLoadedError)dynamic_import)
ModuleType)	Inspector)
ObjectNode)Visitor)GriffeLoader)Alias	AttributeClassFunctionModuleObjectc                  `   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ddZ	 	 	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZd dZ	 	 	 	 	 	 	 	 d!dZy)"	Extensionz!Base class for Griffe extensions.c                D     t        | dt        |       d       |       y)zPVisit a node.

        Parameters:
            node: The node to visit.
        visit_c                     y N _s    L/var/www/openai/venv/lib/python3.12/site-packages/_griffe/extensions/base.py<lambda>z!Extension.visit.<locals>.<lambda>%   s    4    N)getattrr   selfnodes     r#   visitzExtension.visit   s$     	Ax~./@Fr%   c                F    t        |      D ]  }| j                  |        y)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%   c                F     t        | d|j                   d       |       y)zTInspect a node.

        Parameters:
            node: The node to inspect.
        inspect_c                     y r   r    r!   s    r#   r$   z#Extension.inspect.<locals>.<lambda>6   s    r%   N)r&   kindr'   s     r#   inspectzExtension.inspect0   s"     	>,n=dCr%   c                b    |j                   D ]   }|j                  r| j                  |       " y)zxExtend the base generic inspection with extensions.

        Parameters:
            node: The node to inspect.
        N)childrenalias_target_pathr3   r,   s      r#   generic_inspectzExtension.generic_inspect8   s'     ]]E**U# #r%   c                    y)zRun when visiting a new node during static/dynamic analysis.

        Parameters:
            node: The currently visited node.
        Nr    r(   r)   agentkwargss       r#   on_nodezExtension.on_nodeB       r%   c                    y)a   Run when an Object has been created.

        Parameters:
            node: The currently visited node.
            obj: The object instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    r(   r)   objr:   r;   s        r#   on_instancezExtension.on_instanceI   r=   r%   c                    y)a  Run when members of an Object have been loaded.

        Parameters:
            node: The currently visited node.
            obj: The object instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    r?   s        r#   
on_memberszExtension.on_membersZ   r=   r%   c                    y)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    r9   s       r#   on_module_nodezExtension.on_module_noded   r=   r%   c                    y)zRun when a Module has been created.

        Parameters:
            node: The currently visited node.
            mod: The module instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    r(   r)   modr:   r;   s        r#   on_module_instancezExtension.on_module_instancem   r=   r%   c                    y)a
  Run when members of a Module have been loaded.

        Parameters:
            node: The currently visited node.
            mod: The module instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    rG   s        r#   on_module_memberszExtension.on_module_members~   r=   r%   c                    y)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    r9   s       r#   on_class_nodezExtension.on_class_node   r=   r%   c                    y)zRun when a Class has been created.

        Parameters:
            node: The currently visited node.
            cls: The class instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    r(   r)   clsr:   r;   s        r#   on_class_instancezExtension.on_class_instance   r=   r%   c                    y)a  Run when members of a Class have been loaded.

        Parameters:
            node: The currently visited node.
            cls: The class instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    rO   s        r#   on_class_memberszExtension.on_class_members   r=   r%   c                    y)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    r9   s       r#   on_function_nodezExtension.on_function_node   r=   r%   c                    y)a  Run when a Function has been created.

        Parameters:
            node: The currently visited node.
            func: The function instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    )r(   r)   funcr:   r;   s        r#   on_function_instancezExtension.on_function_instance   r=   r%   c                    y)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    r9   s       r#   on_attribute_nodezExtension.on_attribute_node   r=   r%   c                    y)a  Run when an Attribute has been created.

        Parameters:
            node: The currently visited node.
            attr: The attribute instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    )r(   r)   attrr:   r;   s        r#   on_attribute_instancezExtension.on_attribute_instance   r=   r%   c                    y)a   Run when an Alias has been created.

        Parameters:
            node: The currently visited node.
            alias: The alias instance.
            agent: The analysis agent currently running.
            **kwargs: For forward-compatibility.
        Nr    )r(   r)   aliasr:   r;   s        r#   on_aliaszExtension.on_alias   r=   r%   c                    y)zRun when a package has been completely loaded.

        Parameters:
            pkg: The package (Module) instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr    )r(   pkgloaderr;   s       r#   on_package_loadedzExtension.on_package_loaded   r=   r%   c                    y)zRun when wildcard imports are expanded into aliases.

        Parameters:
            alias: The alias instance.
            loader: The loader currently in use.
            **kwargs: For forward-compatibility.
        Nr    )r(   r_   rc   r;   s       r#   on_wildcard_expansionzExtension.on_wildcard_expansion  r=   r%   N)r)   zast.ASTreturnNone)r)   r   rg   rh   )r)   ast.AST | ObjectNoder:   Visitor | Inspectorr;   r	   rg   rh   )
r)   ri   r@   r   r:   rj   r;   r	   rg   rh   )
r)   ri   rH   r   r:   rj   r;   r	   rg   rh   )
r)   ri   rP   r   r:   rj   r;   r	   rg   rh   )
r)   ri   rW   r   r:   rj   r;   r	   rg   rh   )
r)   ri   r\   r   r:   rj   r;   r	   rg   rh   )
r)   ri   r_   r   r:   rj   r;   r	   rg   rh   )rb   r   rc   r   r;   r	   rg   rh   )r_   r   rc   r   r;   r	   rg   rh   )__name__
__module____qualname____doc__r*   r.   r3   r7   r<   rA   rC   rE   rI   rK   rM   rQ   rS   rU   rX   rZ   r]   r`   rd   rf   r    r%   r#   r   r      s#   +GD$ # 	
 #  
" # 	
 #  
" # 	
 #  
" # 	
 #  
" # 	
 #  
" # 	
 #  
" # 	
 #  
" # 	
 #  
"  	
  
r%   r   c                  (    e Zd ZdZddZddZddZy)
ExtensionszLThis class helps iterating on extensions that should run at different times.c                0    g | _          | j                  |  y)zrInitialize the extensions container.

        Parameters:
            *extensions: The extensions to add.
        N)_extensionsadd)r(   
extensionss     r#   __init__zExtensions.__init__  s     -/*r%   c                H    |D ]  }| j                   j                  |        y)zoAdd extensions to this container.

        Parameters:
            *extensions: The extensions to add.
        N)rr   append)r(   rt   	extensions      r#   rs   zExtensions.add(  s"     $I##I. $r%   c                J    | j                   D ]  } t        ||      di |  y)zCall the extension hook for the given event.

        Parameters:
            event: The triggered event.
            **kwargs: Arguments passed to the hook.
        Nr    )rr   r&   )r(   eventr;   rx   s       r#   callzExtensions.call1  s(     ))I%GIu%// *r%   N)rt   r   rg   rh   )rz   strr;   r	   rg   rh   )rk   rl   rm   rn   ru   rs   r{   r    r%   r#   rp   rp     s    V/0r%   rp   dataclasseszset[str]builtin_extensionsc                   t         j                  j                  |       j                  dd      d   }t	        ||       }|st        d|  d      t        |      }|t        j                  |<   |j                  j                  |       |S )N.   r   z#Could not import module from path '')ospathbasenamersplitr   r   r   sysmodulesrc   exec_module)r   module_namespecmodules       r#   _load_extension_pathr   B  s|    ''""4(//Q7:K";5D%(KD6QR&STTd#F%CKKKKF#Mr%   c                v   d}t        | t              r| S t        |       rt        | t              r |        S t        | t              r1t        t        | j                                     \  }}t        |      }nt        |       }i }|j                  d      }|dkD  s|r-dt        |      j                  vr|j                  dd      \  }}nd}|t        v rd| }n+t        j                  j!                  |      r	 t#        |      }|s	 t)        |      }t        |      rt        |t              r |di |S |r	  t-        ||      di |S t1        |      j3                         D cg c]*  }t        |      st        |t              s |t        us)|, }}|D 	cg c]
  }	 |	di | c}	S # t$        $ r}t'        d| d      |d}~ww xY w# t*        $ r}t'        d| d      |d}~wt$        $ r}t'        d| d|       |d}~ww xY w# t.        $ r}t'        d| d	| d
      |d}~ww xY wc c}w c c}	w )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.extensions.zExtension module 'z' could not be foundz!Error while importing extension 'z': z
' has no 'z' attributer    )
isinstancer   r   
issubclassdictnextiteritemsr|   countr   driver   r~   r   r   existsr   ImportErrorr   r   ModuleNotFoundErrorr&   AttributeErrorvarsvalues)
rx   
ext_objectimport_pathoptionscolonsextension_nameerrorr@   rt   exts
             r#   _load_extensionr   M  st   " J )Y' yjI>{ )T"#D):$;<W +& )n s#FzfD,=,C,C!C&1&8&8a&@#^ ((+K=9		$	m-k:J 	r'4J zz*i@$G$$ 	67:~6AAA J'..00GCLZPSU^E_dgoxdx0   '11jsCN'Nj11A  	m),>{mK_*`agll	m # 	m),>{mK_*`agll 	r),Mk]Z]^c]d*eflqq	r  	)$[MN;K;W	 2sr   :F- G 9H &H17H1H1H1H6-	G6GG	H
G''H
3HH
	H.H))H.c                    t               }| D ]>  }t        |      }t        |t              r |j                  |  .|j	                  |       @ ddlm} |j                  D ]  }t        |      |u s |S   |j                  t        d        |S )zLoad configured extensions.

    Parameters:
        exts: Extensions with potential configuration options.

    Returns:
        An extensions container.
    r   )DataclassesExtensionr}   )	rp   r   r   listrs   _griffe.extensions.dataclassesr   rr   type)extsrt   rx   r   r   s        r#   load_extensionsr     s     J	i(c4 JNNC NN3  D%%9,,  & 	
67r%   )r   r|   rg   r   )rx   z2str | dict[str, Any] | Extension | type[Extension]rg   zExtension | list[Extension])r   LoadableExtensionTyperg   rp   )3
__future__r   r   r   importlib.utilr   r   r3   r   pathlibr   typingr   r	   r
   _griffe.agents.nodes.astr   r   _griffe.exceptionsr   _griffe.importerr   asttypesr   _griffe.agents.inspectorr   _griffe.agents.nodes.runtimer   _griffe.agents.visitorr   _griffe.loaderr   _griffe.modelsr   r   r   r   r   r   r   r|   r   r   r   rp   r~   __annotations__r   r   r   r    r%   r#   <module>r      s    # 	 
 D   , , ; 6 + 27.+PPy yx c4S>9d9oMN  <0 0B   H  /X2AX2 X2vr%   