
    k7i;                     6   S r SSKrSSKJrJr  SSKr\(       a  SSKJr  SSKJ	r	  SSK
Jr  SSKJr   SSKJr  SSKJ	r	  SSKJr  SSK
Jr  \R                   " \5      rS	rS\SS4S jr\R0                  " S	S9 " S S5      5       rS\S\\   S\\   S-  S\\   S-  S\4
S jr S&S\S\\   S-  S\\   S-  S\\   S-  S\4
S jjrS'S\S\S\\   4S jjrS\\   S\S\S   4S  jr  " S! S"\5      r!S#S$S\\\4   4S% jr"g! \ a    S
r\(       d  \rSr Nf = f)(z:Sphinx extension for automatic Cyclopts CLI documentation.    N)TYPE_CHECKINGAnynodes)Sphinx)SphinxDirectiveApp)loggingTFmodule_pathreturnr
   c                 r   SSK Jn  SU ;   a  U R                  SS5      u  p#OU Sp2 [        R                  " U5      nU(       aN  [        XC5      (       d  [        SU S	U S
35      e[        XC5      n[        Xa5      (       d  [        S
U S35      eU$ S H#  n[        XGS5      n[        X5      (       d  M!  Us  $    [        U5       H:  nUR                  S5      (       a  M  [        XG5      n[        X5      (       d  M8  Us  $    [        SU SU S35      e! [
         a  n[        SU SU 35      UeSnAff = f)z)Import a Cyclopts App from a module path.r   r	   :   NzCannot import module 'z': zModule 'z' has no attribute ''z ' is not a Cyclopts App instance)appclimain_zNo Cyclopts App found in 'z'. Specify explicitly: 'z
:app_name')cycloptsr
   rsplit	importlibimport_moduleImportErrorhasattrAttributeErrorgetattr
isinstance	TypeErrordir
startswith)	r   r
   module_nameapp_namemoduleer   nameobjs	            M/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/sphinx_ext.py_import_appr)      sM   
k + 2 23 :X +TXO((5 v(( 8K=8LXJVW!XYYf'###az)IJKK
 'fD)cJ ' Fs##&'C###
	  5k]BZ[fZggqr
ss1  O2;-s1#FGQNOs   D 
D6D11D6)kw_onlyc                       \ rS rSr% SrSr\\S'   Sr\	\
   S-  \S'   Sr\	\
   S-  \S'   Sr\\S	'   Sr\\S
'   Sr\\S'   \S\SS 4S j5       r\S\\
\4   4S j5       rSrg)DirectiveOptionsD   z)Configuration for the Cyclopts directive.   heading_levelNcommandsexclude_commandsFno_recursiveinclude_hiddenflatten_commandsoptionsr   c                    0 n[         R                  " U 5       H  nUR                  R                  SS5      nUR                  [
        L a  XA;   a  SX#R                  '   MG  MI  XA;   d  MP  X   nUR                  S;   ak  U(       aT  UR                  S5       Vs/ s H)  ofR                  5       (       d  M  UR                  5       PM+     snX#R                  '   M  / X#R                  '   M  XRUR                  '   M     U " S0 UD6$ s  snf )z1Create options from directive options dictionary.r   -Tr0   r1   , )attrsfieldsr&   replacetypeboolsplitstrip)clsr5   kwargsfieldoption_namevaluecmds          r(   	from_dictDirectiveOptions.from_dictQ   s     \\#&E**,,S#6KzzT! ))-F::& * ',::!AAEJ[[QTEU-eEUcYbYbYdkciikEU-ezz* .0zz*).5::&+ '0 }V} .fs   D3Dc                     [         (       d  0 $ SSKJn   [        U R                  [
        U R                  [        U R                  0n0 n[        R                  " [        5       Hf  nUR                  R                  SS5      nUR                  S;   a  U R                  nO&UR                  UR                  U R                  5      nXRU'   Mh     U$ )z9Generate Sphinx option_spec from DirectiveOptions fields.r   )
directivesr   r7   r8   )SPHINX_AVAILABLEdocutils.parsers.rstrK   r?   flagintnonnegative_intstr	unchangedr;   r<   r,   r&   r=   getr>   )rK   type_mappingoption_specrD   rE   	validators         r(   specDirectiveOptions.speco   s      I3 *//++%%
 \\"23E**,,S#6Kzz==&00	(,,UZZ9M9MN	'0$ 4     r:   )__name__
__module____qualname____firstlineno____doc__r/   rO   __annotations__r0   listrQ   r1   r2   r?   r3   r4   classmethoddictrH   staticmethodr   rW   __static_attributes__r:   rY   r(   r,   r,   D   s    3M3!%Hd3i$%)-d3i$&- L$ ND "d" );  : $sCx.  rY   r,   command_namecommand_pathcommands_filterr1   c                 l   SR                  X/-   5      nU(       aD  X;   d  XC;   a  g[        [        U5      5       H!  nSR                  USUS-    5      nXc;   d  M!    g   UbR  X;   d  XB;   a  g[        [        U5      5       H!  nSR                  USUS-    5      nXb;   d  M!    g   U(       d  X;   a  ggg)a  Check if a command should be included in documentation.

Parameters
----------
command_name : str
    The name of the command.
command_path : list[str]
    The full path to the command (including parent commands).
commands_filter : list[str] | None
    If specified, only include commands in this list.
exclude_commands : list[str] | None
    If specified, exclude commands in this list.

Returns
-------
bool
    True if the command should be included.
.FNr   T)joinrangelen)re   rf   rg   r1   	full_pathiparent_paths          r(   _should_include_commandrp      s    2 67I +y/Ls<()A((<!a%#89K. * " *i.Js<()A((<!a%#89K- *
  ? rY   r0   ro   c                 t    Uc  / n0 nU R                  5        H  u  pV[        XSX5      (       d  M  XdU'   M     U$ )a  Filter commands based on inclusion/exclusion lists.

Parameters
----------
commands : dict
    Dictionary mapping command names to App instances.
commands_filter : Optional[List[str]]
    If specified, only include commands in this list.
exclude_commands : Optional[List[str]]
    If specified, exclude commands in this list.
parent_path : List[str]
    Path to the parent command for nested commands.

Returns
-------
dict
    Filtered commands dictionary.
)itemsrp   )r0   rg   r1   ro   filteredr&   r   s          r(   _filter_commandsrt      sB    0 H^^%	"4oXX TN & OrY   content
skip_titlec                    U R                  5       n/ nSnU[        U5      :  GaT  X$   nU(       aa  US:X  a[  UR                  5       (       aF  US-   [        U5      :  a4  X$S-      R                  5       nU(       a  [        U5      1 Sk::  a  US-  nM|  UR                  5       R	                  S5      (       a  US-  nU[        U5      :  aZ  X$   R                  5       (       aC  X$   S   S;   a8  US-  nU[        U5      :  a$  X$   R                  5       (       a  X$   S   S;   a  M8  U[        U5      :  a  X$   R                  5       (       d  US-  nGM<  UR                  U5        US-  nU[        U5      :  a  GMT  U$ )z3Process RST content to remove problematic elements.r   r   >   "r7   =^~r.   z.. contents::z 	)
splitlinesrl   rA   setr!   append)ru   rv   lines	processedrn   line	next_lines          r(   _process_rst_contentr      sI    EI	A
c%j.x !q&TZZ\\a!ec%j6H!e**,IS^/HHQ ::<""?33FAc%j.UX^^%5%5%(1+:NQ c%j.UX^^%5%5%(1+:N3u:~ehnn&6&6Q	Q) c%j., rY   r   state
nodes.Nodec                    [         (       d  / $ SSKJn  SSKJn  / nSnU[        U 5      :  Ga7  X   nUS-   [        U 5      :  GaW  XS-      R                  5       nU(       Ga:  [        S U 5       5      (       Ga"  UR                  " 5       nUR                  5       n	U	R                  5       R                  SS5      R                  SS	5      /US
'   XR                  " U	S9-  n/ n
US-  nU[        U 5      :  aq  US-   [        U 5      :  a  XS-      R                  5       OSnU(       a  [        S U 5       5      (       a  O)U
R                  X   5        US-  nU[        U 5      :  a  Mq  U
(       a  UR                  U" U
5      SU5        UR                  U5        GM~  UR                  5       S:X  Ga:  US-  nU[        U 5      :  a  X   R                  5       (       d  US-  n/ nU[        U 5      :  a\  X   R                  S5      (       aD  UR                  X   SS 5        US-  nU[        U 5      :  a  X   R                  S5      (       a  MD  U(       ah  UR                  " 5       nSR!                  U5      Ul        UR                  UR$                  " SR!                  U5      5      5        UR                  U5        U[        U 5      :  a  X   R                  5       (       d  US-  nGM  UR                  5       (       GaM  U/n
US-  nU[        U 5      :  a  US-   [        U 5      :  a  XS-      R                  5       OSnU(       a  [        S U 5       5      (       a  OX   R                  5       S:X  a  OX   R                  5       (       d@  U
R                  X   5        US-  nU[        U 5      :  d  X   R                  5       (       d  O*OU
R                  X   5        US-  nU[        U 5      :  a  M  UR&                  " 5       nUR                  U" U
5      SU5        UR(                  (       a  UR+                  UR(                  5        OUS-  nU[        U 5      :  a  GM7  U$ )z$Create section nodes from RST lines.r   r   )
StringListr   c              3   *   #    U  H	  oS :H  v   M     g7fr7   Nr:   .0cs     r(   	<genexpr>(_create_section_nodes.<locals>.<genexpr>  s      =9ac9    r7   z	cyclopts-zcli-cyclopts-idstextr.    c              3   *   #    U  H	  oS :H  v   M     g7fr   r:   r   s     r(   r   r   %  s     1WDVqs(DVr   z::z       N
c              3   *   #    U  H	  oS :H  v   M     g7fr   r:   r   s     r(   r   r   V  s     $Ay!#Xyr   )rL   docutilsr   docutils.statemachiner   rl   rA   allsectionlowerr=   titler~   nested_parser!   literal_blockrj   	rawsourceText	paragraphchildrenextend)r   r   r   r   resultrn   r   r   r   
title_textcontent_linesnext_line_strippedliteral_contentr   paras                  r(   _create_section_nodesr     s   	0F	A
c%j.x q53u:!e**,IS =9 ===--/!ZZ\
","2"2"4"<"<S#"F"N"N{\k"l!m;;J77 !#Q#e*nABQUAS1u););)=Y[&)c1WDV1W.W.W!((2FA #e*n !&&z-'@!WMg& ::<4FA 3u:~ehnn&6&6Q !Oc%j.UX%8%8%@%@&&ux|4Q c%j.UX%8%8%@%@  % 3 3 5*.))O*D'$$UZZ		/0J%KLm, 3u:~ehnn&6&6Q ::<<!FMFA c%j.45ECJ4FEa%L..0B	$Ay$A!A!A 8>>#t+ x~~''!((2FACJehnn.>.> /? "((2FA+ c%j.0 ??$Dz-8!TB}}dmm,FA c%j.B MrY   c                       \ rS rSrSrSrSrSrSr\	R                  5       rS\S   4S jrS	\S
\	S\4S jrS\S
\	S\S   4S jrS\S\S   4S jrSrg)CycloptsDirectiveiu  z;Sphinx directive for documenting Cyclopts CLI applications.Fr   r   r   r   c                 v   [         (       d  / $ U R                  S   n[        R                  U R                  5      n U R                  X5      nU R                  X25      $ ! [        [        [        4 a  nU R                  SU 35      s SnA$ SnAf[         a  nU R                  SU 35      s SnA$ SnAff = f)z2Generate documentation nodes for the Cyclopts app.r   z)Error generating Cyclopts documentation: NzUnexpected error: )rL   	argumentsr,   rH   r5   _generate_documentation_create_nodesr   r   r   _error_node	Exception)selfr   optsrst_contentr%   s        r(   runCycloptsDirective.run~  s    InnQ'))$,,7	>66{IK%%k88^Y7 	U##&OPQs$STT 	>##&8$<==	>s/   !A B84BB8B8B3-B83B8r   r   c                     SSK Jn  [        U5      nU" UUR                  (       + UR                  UR
                  UR                  UR                  UR                  SS9$ )z'Generate RST documentation for the app.r   )generate_rst_docsT)	recursiver3   r/   r4   rg   r1   no_root_title)	cyclopts.docs.rstr   r)   r2   r3   r/   r4   r0   r1   )r   r   r   r   r   s        r(   r   )CycloptsDirective._generate_documentation  s[    7+& !+++..,,!22 MM!22	
 		
rY   r   c                 Z    [         (       d  / $ [        USS9n[        X0R                  5      $ )z'Create docutils nodes from RST content.F)rv   )rL   r   r   r   )r   r   r   r   s       r(   r   CycloptsDirective._create_nodes  s*    I$[UC %UJJ77rY   messagec                     [         (       d  / $ SSKJn  [        (       a  [        R	                  U5        UR                  " SUR
                  " US95      /$ )z,Create an error node with the given message.r   r   r   r   )rL   r   r   loggererrorr   )r   r   r   s      r(   r   CycloptsDirective._error_node  s>    I"6LL!BW =>??rY   r:   N)rZ   r[   r\   r]   r^   has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer,   rW   rU   r`   r   rQ   r   r   r   rd   r:   rY   r(   r   r   u  s    EK %"'')K>T,' > 
3 
>N 
SV 
$8 84D 8lI[ 8	@3 	@4+= 	@rY   r   r   r   c                 P    [         (       a  U R                  S[        5        SSSS.$ )z(Setup function for the Sphinx extension.r   z1.0.0T)versionparallel_read_safeparallel_write_safe)rL   add_directiver   )r   s    r(   setupr     s,    *&78"# rY   )N)F)#r^   r   typingr   r   r;   r   r   sphinx.applicationr   sphinx.util.docutilsr   r   r
   sphinx.utilr   	getLoggerrZ   r   rL   r   objectrQ   r)   definer,   r`   r?   rp   rb   rt   r   r   r   r   r:   rY   r(   <module>r      s   @  % )4)#4x(F#tS #tU #tL dB B BJ77s)7 #Y%7 3i$&	7
 
7| %)	  #Y%  3i$&  cT!	 
 
 F# 4 DI >lc l3 l4;M l^>@ >@Bx DcN    	s   ,D DD