
    RiJ                       U d Z ddlmZ ddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlZddlmZmZmZmZmZ dd	lmZ erPdd
lmZmZmZmZm Z  ddlm!Z!m"Z"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.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5  ejl                  dejn                        Z8 e9 e:ejv                   e<e      j{                                     Z>de?d<   d)dZ@d*dZA G d deB      ZC G d d      ZD G d de      ZE G d  d!e      ZFd+d"ZGd,d#ZH	 	 	 	 	 	 d-d$ZI	 	 	 	 	 	 d.d%ZJ	 	 	 	 	 	 d/d&ZKd0d'ZLd1d(ZMy)2aQ  Defines a docutils directive for inserting inheritance diagrams.

Provide the directive with one or more classes or modules (separated
by whitespace).  For modules, all of the classes in that module will
be used.

Example::

   Given the following classes:

   class A: pass
   class B(A): pass
   class C(A): pass
   class D(B, C): pass
   class E(B): pass

   .. inheritance-diagram: D E

   Produces a graph like the following:

               A
              / \
             B   C
            / \ /
           E   D

The graph is inserted as a PNG+image map into HTML and a PDF in
LaTeX.
    )annotationsN)import_module)TYPE_CHECKINGcast)nodes)
directives)figure_wrappergraphvizrender_dot_htmlrender_dot_latexrender_dot_texinfo)SphinxDirective)
CollectionIterableIteratorSequenceSet)AnyClassVarFinal)Node)addnodes)Sphinx)Config)BuildEnvironment)ExtensionMetadata
OptionSpec)HTML5Translator)LaTeXTranslator)TexinfoTranslatorzY^
    (?:([\w.]*)\.)?  # module names
    (\w+)  \s* $     # class/final module name
    r   PY_BUILTINSc                    	 t        |       S # t        $ r Y yt        $ r\ t        j	                  |       }|sY y|j                         \  }}|Y y	 t        |      }t        ||d      cY S # t        $ r Y Y yw xY ww xY w)zImport a object or module using *name* and *currentmodule*.
    *name* should be a relative name from *currentmodule* or
    a fully-qualified name.

    Returns imported object or module.  If failed, returns None value.
    N)r   	TypeErrorImportErrormodule_sig_rematchgroupsgetattr)objnamematchedmodnameattrnamemodules        V/home/agent/.friday_env/lib/python3.12/site-packages/sphinx/ext/inheritance_diagram.py
try_importr/   Q   s    W%%  %%g.#NN,?	"7+F68T22 		s7   
 	A<A<A<A+(A<+	A84A<7A88A<c                   d}|rt        |dz   | z         }|t        |       }|t        d| z        t        j                  |      r|gS t        j                  |      rV|j
                  j                         D cg c]2  }t        j                  |      r|j                  |j                  k(  r|4 c}S | d}t        |      c c}w )z0Import a class using its fully-qualified *name*.N.zECould not import class or module %r specified for inheritance diagramz; specified for inheritance diagram is not a class or module)	r/   InheritanceExceptioninspectisclassismodule__dict__values
__module____name__)name
currmoduletargetclsmsgs        r.   import_classesr?   n   s    F J,t34 ~D!~""$()
 	

 vx			&	! --/
s#&//(I 
 	

 HO
PC
s
##
s   <7Cc                      e Zd Zy)r2   N)r9   r8   __qualname__     r.   r2   r2      s    rC   r2   c                  `   e Zd ZU dZdddd e       df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZ	 	 	 	 	 	 d!dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ	 d#	 	 	 	 	 	 	 d$dZd%d	Z	d
dddZ
ded<   dddddddZded<   dddZded<   d&dZd&dZ	 	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZ	 	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 d)dZy)*InheritanceGraphzGiven a list of classes, determines the set of classes that they inherit
    from all the way to the root "object", and then is able to generate a
    graphviz dot graph from them.
    Fr   Nc	                   || _         | j                  ||      }	|r0h |	}
t        |
      D ]  }|
j                  t	        |              |
}	| j                  |	|||||      | _        | j                  sd}t        |      y)z*class_names* is a list of child classes to show bases from.

        If *show_builtins* is True, then Python builtins will be shown
        in the graph.
        z(No classes found for inheritance diagramN)class_names_import_classestupleupdate_subclasses_class_info
class_infor2   )selfrG   r;   show_builtinsprivate_basespartsaliasestop_classesinclude_subclassesclassesclasses_setr=   r>   s                r.   __init__zInheritanceGraph.__init__   s      ')-)=)=k:)V$G*K[) 5"";s#345!G**]M5';
 <C&s++ rC   c                N    g }|D ]  }|j                  t        ||              |S )zImport a list of classes.)extendr?   )rN   rG   r;   rU   r:   s        r.   rH   z InheritanceGraph._import_classes   s0     $& 	=DNN>$
;<	=rC   c                     i d fd|D ]
  } |        j                         D 	
cg c]  \  }}	}
}||	t        |
      |f c}}
}	}S c c}}
}	}w )a  Return name and bases for all classes that are ancestors of
        *classes*.

        *parts* gives the number of dotted name parts to include in the
        displayed node names, from right to left. If given as a negative, the
        number of parts to drop from the left. A value of 0 displays the full
        dotted name. E.g. ``sphinx.ext.inheritance_diagram.InheritanceGraph``
        with ``parts=2`` or ``parts=-2`` gets displayed as
        ``inheritance_diagram.InheritanceGraph``, and as
        ``ext.inheritance_diagram.InheritanceGraph`` with ``parts=3`` or
        ``parts=-1``.

        *top_classes* gives the name(s) of the top most ancestor class to
        traverse to. Multiple names can be specified separated by comma.
        c                X   s	| t         v ry 
s| j                  j                  d      ry j                  | 	      }j                  | d      }d }	 | j                  rC| j                  j                         j                  d      d   }|rd|j                  dd      z  }g }||||f| <   |v ry | j                  D ]Z  }s	|t         v r
s|j                  j                  d      r,|j                  j                  |	             |vsS |       \ y # t        $ r Y w xY w)N_r   
z"%s""z\")r!   r9   
startswith
class_name__doc__stripsplitreplace	Exception	__bases__append)r=   nodenamefullnametooltipdocbaselistbaserR   all_classesrQ   rP   recurserN   rO   rS   s          r.   ro   z-InheritanceGraph._class_info.<locals>.recurse   s0    SK%7 S\\%<%<S%AsE7;HsAw7H G;;++++-33D9!<C"(3;;sE+B"B #%H ((HgFK;& "$)<$)A)A#)FeW EF{*DM"  s   AD 	D)(D))r=   	type[Any]returnNone)r7   rI   )rN   rU   rO   rP   rQ   rR   rS   r=   cls_nameri   basesrj   rn   ro   s   ` `````     @@r.   rL   zInheritanceGraph._class_info   ss    0  	"  	"D  	CCL	
 9D8J8J8L
 
48UG xuw7
 	
 
s   A
c                    |j                   }|dv r|j                  }n| d|j                   }|dk(  r|}n&|j                  d      }dj	                  || d       }|	||v r||   S |S )zGiven a class object, return a fully-qualified name.

        This works for things I've tested in matplotlib so far, but may not be
        completely general.
        >   builtins__builtin__r1   r   N)r8   r9   rA   rc   join)rN   r=   rQ   rR   r-   ri   result
name_partss           r.   r`   zInheritanceGraph.class_name  s     00||H 3#3#3"45HA:F!,JXXj%12F6W#46?"rC   c                P    | j                   D cg c]	  \  }}}}| c}}S c c}}w )z1Get all of the class names involved in the graph.)rM   )rN   r\   ri   s      r.   get_all_class_namesz$InheritanceGraph.get_all_class_names  s#    48OOD0a1aDDDs   "LRz"8.0, 12.0"transparent)rankdirsizebgcolordict[str, float | int | str]default_graph_attrsbox
   g      ?zA"Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans"z"setlinewidth(0.5),filled"white)shapefontsizeheightfontnamestyle	fillcolordefault_node_attrsg      ?z"setlinewidth(0.5)")	arrowsizer   default_edge_attrsc                `    dj                  d t        |j                               D              S )N,c              3  0   K   | ]  \  }}| d |   yw)=NrB   .0kvs      r.   	<genexpr>z6InheritanceGraph._format_node_attrs.<locals>.<genexpr>1  s     Etq!1#Qqc
Es   rx   sorteditemsrN   attrss     r.   _format_node_attrsz#InheritanceGraph._format_node_attrs0  s"    xxEvekkm/DEEErC   c                `    dj                  d t        |j                               D              S )N c              3  2   K   | ]  \  }}| d | d  yw)r   z;
NrB   r   s      r.   r   z7InheritanceGraph._format_graph_attrs.<locals>.<genexpr>4  s      GA!AaS}Gs   r   r   s     r.   _format_graph_attrsz$InheritanceGraph._format_graph_attrs3  s"    wwG1FGGGrC   c                N    ||j                   nd }| j                  ||||||      S N)config_generate_dot)rN   r:   urlsenvgraph_attrs
node_attrs
edge_attrsr   s           r.   generate_dotzInheritanceGraph.generate_dot6  s3      #D!!$Z
 	
rC   c           	     R    |i } j                   j                         } j                  j                         } j                  j                         ||j	                  |       ||j	                  |       |j	                  |       |rQ|j	                  |j
                         |j	                  |j                         j	                  |j                         d| d j                  |      g}	t         j                        D ]v  \  }
}}|j                         }|
|v rd||
    d|d<   d|d<   |r||d<   |	j                  d d	 j                  |       d
       |	j                   fd|D               x |	j                  d       dj                  |	      S )aV  Generate a graphviz dot graph from the classes that were passed in
        to __init__.

        *name* is the name of the graph.

        *urls* is a dictionary mapping class names to HTTP URLs.

        *graph_attrs*, *node_attrs*, *edge_attrs* are dictionaries containing
        key/value pairs to pass on as graphviz properties.
        zdigraph z {
r^   URLz"_top"r<   rj     "" [];
c           	   3  T   K   | ]  }d | d dj                         d ! yw)r   z" -> "r   r   N)r   )r   	base_namers   e_attrsrN   s     r.   r   z1InheritanceGraph._generate_dot.<locals>.<genexpr>y  s;       i[xjD4K4KG4T3UUYZs   %(z}
r   )r   copyr   r   rJ   inheritance_graph_attrsinheritance_node_attrsinheritance_edge_attrsr   r   rM   rg   r   rY   rx   )rN   r:   r   r   r   r   r   g_attrsn_attrsresri   rt   rj   this_node_attrsrs   r   s   `             @@r.   r   zInheritanceGraph._generate_dotD  s   & <D**//1))..0))..0"NN;'!NN:&!NN:&NN699:NN6889NN6889 tfE"$$W-

 392I 	.Hhw%llnO4+,T(^,<A)>&,4)-4	*JJhZs4#:#:?#K"LDQ
 JJ !& 	" 	

5wws|rC   )rG   	list[str]r;   strrO   boolrP   r   rQ   intrR   dict[str, str] | NonerS   Set[str]rT   r   rq   rr   )rG   r   r;   r   rq   zSequence[type[Any]])rU   zCollection[type[Any]]rO   r   rP   r   rQ   r   rR   r   rS   r   rq   z0list[tuple[str, str, Sequence[str], str | None]])r   N)r=   rp   rQ   r   rR   r   rq   r   )rq   r   )r   r   rq   r   )NNNNN)r:   r   r   r   r   zBuildEnvironment | Noner   #dict[str, float | int | str] | Noner   r   r   r   rq   r   )r:   r   r   r   r   zConfig | Noner   r   r   r   r   r   rq   r   )r9   r8   rA   ra   	frozensetrW   rH   rL   r`   r|   r   __annotations__r   r   r   r   r   r   rB   rC   r.   rE   rE      s2    $#)- )#(,, , 	,
 , , ', , !, 
,<$25	B
&B
 B
 	B

 B
 'B
 B
 
:B
J PT%(7L	,E  95  W-84  &84 
FH '+'+;?:>:>

 $
 %	

 9
 8
 8
 

" '+ $;?:>:>:: $: 	:
 9: 8: 8: 
:rC   rE   c                      e Zd ZdZy)inheritance_diagramzDA docutils node to use as a placeholder for the inheritance diagram.N)r9   r8   rA   ra   rB   rC   r.   r   r     s    NrC   r   c                      e Zd ZU dZdZdZdZdZee	j                  e	j                  e	j                  e	j                  dZded<   dd	Zy
)InheritanceDiagramz@Run when the inheritance_diagram directive is first encountered.F   r   T)rQ   private-basescaptiontop-classesinclude-subclasseszClassVar[OptionSpec]option_specc           
        t               }| j                  j                  |_        | j                  d   j	                         }| j
                  j                  j                  j                  d      }| j                  j                  dd      |d<   dj                  |      |d<   t        | j                  j                  dd      j	                  d      D ch c]  }|j                         x}r| c}      |d<   	 t        || j
                  j                  j                  d	      |d   d
| j                  v | j                   j"                  |d   d| j                  v       }|j-                         D ]:  } |dd| d|d| j                  j.                        \  }	}
|j1                  |	       < ||d<   d| j                  vr| j3                  |       |gS t5        | || j                  d         }| j3                  |       |gS c c}w # t$        $ rJ}|j                  J |j                  j&                  j)                  || j*                        gcY d }~S d }~ww xY w)Nr   classrQ   z, contentr   r   r   z	py:moduler   r   )rQ   rP   rR   rS   rT   )linez:class:``graphr   )r   statedocument	argumentsrc   r   domainspython_domainroleoptionsgetrx   r   rb   rE   ref_contextr   inheritance_aliasr2   reporterwarninglinenor|   inlinerrY   add_namer	   )rN   noderG   
class_roler=   cls_strippedr   errr:   refnodes_xfigures               r.   runzInheritanceDiagram.run  s(   "$

++nnQ'--/XX%%3388A
((!4W))K0Y'||''r:@@E)
 #		++ )
 ]	K$$$((57m-=55 /#74<<#GE" --/ 	"D%8D6+T1djj6H6HLHb KK!		" WDLL(MM$6M#D$Y0GHFMM&!8OQ)
" $ 	K==,,,MM**223T[[2IJJ	Ks%   H=A'H 	I?IIIN)rq   z
list[Node])r9   r8   rA   ra   has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   r   flag	unchangedunchanged_requiredr   r   r   rB   rC   r.   r   r     sS    JK $#''!44(oo)K% 0rC   r   c              #  h   K   |  | j                         D ]  }t        |      E d {     y 7 wr   )__subclasses__rK   )r=   sub_clss     r.   rK   rK     s4     
I%%' (w'''('s   &202c                    | d   t        | d         z   j                         }t        j                  |d      j	                         dd  S )Nr   rQ   F)usedforsecurityi)r   encodehashlibmd5	hexdigest)r   encodeds     r.   get_graph_hashr     sC    IT']!33;;=G;;w6@@B34HHrC   c                   |d   }t        |      }d|z  }| j                  j                  j                         }t        j
                  j                  | j                  j                  | j                  j                  z         }i }t        d|      }|D ]  }	|	j                  d      E|	j                  dd      s|	d   j                  dd      d	   }
n|	d
   }
|	j                  d      ||
<   Y|	j                  d      k|dk(  r|dz   |	j                  d      z   ||	d
   <   d|	j                  d      z   ||	d
   <    |j                  ||| j                        }t        | ||i ddd|d   z          t        j                   )zUOutput the graph for HTML.  This will insert a PNG with clickable
    image map.
    r   inheritance%szIterable[addnodes.pending_xref]refuriinternalT#r   reftitlerefidSVG)r   inheritancezInheritance diagram of r   )alt)r   r   graphviz_output_formatupperospathbasenamebuildercurrent_docname
out_suffixr   r   rsplitr   r   r   SkipNode)rN   r   r   
graph_hashr:   r
  current_filenamer   pending_xrefschildrefnamedotcodes               r.   html_visit_inheritance_diagramr    s    ME%JZ'D "[[??EEGww''$$t||'>'>> D:DAM C99X*99Z./00a8<
+!IIh/DMYYw+%.*:S*@599WCU*UU:&'*-		'0B*BU:&'C !!$T[[!AG
%Y7 ..rC   c                    |d   }t        |      }d|z  }|j                  || j                  ddi      }t        | ||i d       t        j
                  )z4Output the graph for LaTeX.  This will insert a PDF.r   r   r   	"6.0,6.0"r   r   r  )r   r   r   r   r   r  rN   r   r   r  r:   r  s         r.   latex_visit_inheritance_diagramr    sb     ME%JZ'D!!T[[v{.C " G T4"m<
..rC   c                    |d   }t        |      }d|z  }|j                  || j                  ddi      }t        | ||i d       t        j
                  )z6Output the graph for Texinfo.  This will insert a PNG.r   r   r   r  r  r  )r   r   r   r   r   r  r  s         r.   !texinfo_visit_inheritance_diagramr!    sb    
 ME%JZ'D!!T[[v{.C " G tT7B>
..rC   c                "    t         j                  r   )r   r  )rN   r   s     r.   skipr#  #  s    
..rC   c           	         | j                  d       | j                  t        t        d ft        d ft
        d ft
        d ft        d f       | j                  dt               | j                  di dt        t        h             | j                  di dt        t        h             | j                  di dt        t        h             | j                  d	i dt        t        h             t        j                  d
dS )Nzsphinx.ext.graphviz)latexhtmltextmantexinfozinheritance-diagramr   r   )typesr   r   r   T)versionparallel_read_safe)setup_extensionadd_noder   r  r  r#  r!  add_directiver   add_config_valuer   dictsphinx__display_version__)apps    r.   setupr5  '  s    -.LL.5,d3D\4L2D9   +-?@2B)TFBST12rD6ARS12rD6ARS,b"Itf<MN--" rC   )r)   r   rq   r   )r:   r   r;   r   rq   zlist[type[Any]])r=   rp   rq   zIterator[type[Any]])r   r   rq   r   )rN   r   r   r   rq   rr   )rN   r   r   r   rq   rr   )rN   r    r   r   rq   rr   )rN   znodes.NodeVisitorr   r   rq   rr   )r4  r   rq   r   )Nra   
__future__r   rv   r   r3   os.pathr  re	importlibr   typingr   r   docutilsr   docutils.parsers.rstr   r2  sphinx.ext.graphvizr	   r
   r   r   r   sphinx.util.docutilsr   collections.abcr   r   r   r   r   r   r   r   docutils.nodesr   r   sphinx.applicationr   sphinx.configr   sphinx.environmentr   sphinx.util.typingr   r   sphinx.writers.html5r   sphinx.writers.latexr   sphinx.writers.texinfor    compileVERBOSEr%   r   filterr4   varsr7   r!   r   r/   r?   re   r2   rE   r   r   rK   r   r  r  r!  r#  r5  rB   rC   r.   <module>rL     sY  < #     	 # &  +   1MM++#)$3@448

 JJ vgootH~7L7L7NOPU P:$@	9 	l l^	( 	? ?D(I
+
+!4+	+\
!4	 

 
"rC   