
    !<i[                         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 d dlmZ d dlmZ erd dlmZ  e	d          Z G d	 d
          ZdS )    )Sequence)contextmanager)chain)TYPE_CHECKINGAnyTypeVarcastoverload)inverse_groups_from_app)	Parameter)AppVc            
          e Zd Zd Zedded         ee         z  deeef         dz  fd            Z	e
defd            Ze
defd	            Ze
ded         fd
            Zededefd            Zedededefd            Zedededz  dedefd            Zeddededz  dedefd            Zddededz  dedz  dedz  fdZe
defd            ZdS )AppStackc                 (    |gg| _         i g| _        d S N)stackoverrides_stack)selfapps     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/app_stack.py__init__zAppStack.__init__   s    (+ug
68T    Nappsr   	overridesc              #   *  K   | j         |pi z  }| j                            |pi            |s?	 d V  | j                                         n# | j                                         w xY wd S t	          |d         t
                    r\t          t          t
                   |          }| j        d         d         	                    |d          \  }}}t          |          }n(t          t          d         t          |                    }~|s?	 d V  | j                                         n# | j                                         w xY wd S g }d |D             }|D ]2}	|	j        2|r0|d         j        #|                                 |r|d         j        #|                    |	           |	j        j                            |                                           |	j        j                            |pi            |	}
|
j        x}
t          |
          |v r|                                }|                    |
           |
j        j                            |           |
j        j                            |pi            |
j        x}
4	 d V  |D ]}	|	j        j                                         |	j        j                                         |	}
|
j        x}
Wt          |
          |v r|
j        j                                         |
j        j                                         |
j        x}
W| j                                         d S # |D ]}	|	j        j                                         |	j        j                                         |	}
|
j        x}
Wt          |
          |v r|
j        j                                         |
j        j                                         |
j        x}
W| j                                         w xY w)Nr   T)include_parent_metar   c                 ,    h | ]}t          |          S  )id).0r   s     r   	<setcomp>z$AppStack.__call__.<locals>.<setcomp>6   s    444s2c77444r   )r   r   appendpop
isinstancestrr	   r   r   parse_commandslist_meta_parent	app_stackcopy_metar    )r   r   r   str_apps_
apps_tupleresolved_appsso_farapp_idsr   meta_appmeta_subappss               r   __call__zAppStack.__call__   s-      Nio26	##IO444 	+$((****$((****F d1gs## 	:HSM400H#z!}Q/>>x]a>bbAz1'+J'7'7MM ed4jj99M 	+$((****$((****F44m444  	K 	KC' !!8!DJJLLL  !!8!D MM#M&&v{{}}555M)00bAAA H'~-8:h<<7**%{{}}##H---"(//==="299)/rJJJ  (~-8:	'EEE$ 	= 	=#'')))-11333#+>1x>(||w.. &,00222&6::<<<	 $,>1x>  $$&&&&& % 	= 	=#'')))-11333#+>1x>(||w.. &,00222&6::<<<	 $,>1x>  $$&&&&s$   A A'D- -EM B>Preturnc                     i }t          | j                  D ]4}|                                D ]\  }}||                    ||           5|S r   )reversedr   items
setdefault)r   outoverrides_framekeyvalues        r   r   zAppStack.overrides]   sg    '(<== 	/ 	/O-3355 / /
U$NN3.../ 
r   c                     g }t          j        | j                  D ]M}|j        r
|                    d |j        j        D                        |                    |j                   Nt          j
        | S )zhdefault_parameter has special resolution since it needs to include the command groups in the derivation.c                     g | ]	}|j         
S r   )default_parameter)r!   groups     r   
<listcomp>z.AppStack.default_parameter.<locals>.<listcomp>m   s    dddE3dddr   )r   from_iterabler   r*   extendr+   command_groupsr$   rB   r   combine)r   cparams	child_apps      r   rB   zAppStack.default_parameterf   s     ,TZ88 	8 	8I% NNddATAcdddeeeNN967777 '**r   c                 8    | j         st          | j         d         S )Nr#   )r   
ValueError)r   s    r   current_framezAppStack.current_framer   s    z 	z"~r   	attributec                     d S r   r   )r   rN   s     r   resolvezAppStack.resolvey   s    .1cr   overridec                     d S r   r   )r   rN   rQ   s      r   rP   zAppStack.resolve|   s    9<r   fallbackc                     d S r   r   r   rN   rQ   rS   s       r   rP   zAppStack.resolve   s    MPSr   c                    d S r   r   rU   s       r   rP   zAppStack.resolve   s    WZWZr   c                 L   ||S t          | j                  D ]}||v r||         }||c S t          t          t          j        | j                                      D ]B}t          ||          }||c S |}|j        x}t          ||          }||c S |j        x}C|S )z,Resolve an attribute from the App hierarchy.)r9   r   r)   r   rE   r   getattrr*   )	r   rN   rQ   rS   r=   r?   r   resultr4   s	            r   rP   zAppStack.resolve   s    O  ((<== 	! 	!OO++'	2$ LLL D!4TZ!@!@AABB 
	" 
	"CS),,F! H'448A 955%!MMM  (448A
 r   c                     | j         d         	 | j         d         }n# t          $ r d }Y nw xY w|H	 t          fdt          |          D                       d         S # t          $ r
 |j        }Y nw xY w|Hg S )Nr#   c              3   0   K   | ]}|d          u |V  dS )r   Nr   )r!   xcommand_apps     r   	<genexpr>z*AppStack.command_groups.<locals>.<genexpr>   s3      cc!qQRtWbObObAObObObObccr      )rM   
IndexErrornextr   StopIterationr*   )r   current_appr^   s     @r   rG   zAppStack.command_groups   s    (,	&*&8&<KK 	 	 	KKK	 %7cccc'>{'K'Kcccccdeff  7 7 7)67 %
 	s    ---A! !A54A5r   )NN)__name__
__module____qualname__r   r   r   r'   dictr   r6   propertyr   r   rB   r)   rM   r
   rP   r   rG   r   r   r   r   r      s       : : : C' C'Xe_x}< C'cSVhZ^I^ C' C' C' ^C'J 4    X 	+9 	+ 	+ 	+ X	+ tE{    X 11111 X1<<<a<<< X<PPDPAP!PPP XPZZZDZaZTUZZZ XZ  D 1t8 _`cg_g    6     X  r   r   N)collections.abcr   
contextlibr   	itertoolsr   typingr   r   r   r	   r
   cyclopts.group_extractorsr   cyclopts.parameterr   cyclopts.corer   r   r   r   r   r   <module>rq      s    $ $ $ $ $ $ % % % % % %       > > > > > > > > > > > > > > = = = = = = ( ( ( ( ( ( "!!!!!! GCLL] ] ] ] ] ] ] ] ] ]r   