
    !<if                     `   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
 d dlmZ d dlmZ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rd dlmZ  ed           G d de                      Z G d d          Ze G d de                      Ze G d de                      ZdS )    N)ABCabstractmethod)Iterable)suppress)chain)Path)TYPE_CHECKINGAny)definefield)ArgumentCollectionupdate_argument_collection)CycloptsError)to_tuple_converter)AppT)kw_onlyc                   >   e Zd ZU dZ ede          Zee         e	d<    ed          Z
ee	d<    ed          Zee	d	<    ed
d          Zed
z  e	d<   eedeeef         fd                        Zeedefd                        Zdddeedf         defdZd
S )
ConfigBasezBase class for configuration sources.

    Handles the common logic of processing configuration dictionaries
    and updating ArgumentCollections.
     )default	converter	root_keysF)r   allow_unknownTuse_commands_as_keysNsource)r   alias_sourcereturnc                     t           )z$Return the configuration dictionary.NotImplementedErrorselfs    /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/config/_common.pyconfigzConfigBase.config!   
     "!    c                     t           HReturn a string identifying the configuration source for error messages.r    r"   s    r$   r   zConfigBase.source'   r&   r'   appr   commands.	argumentsc                    | j                                         }	 t          | j        | j        r|nd          D ]
}||         }n# t
          $ r Y d S w xY w| j        r|n$t          d |j        j        D             |          fd|	                                D             }t          || j        ||j        j        d         | j        | j                   d S )Nr   c              3   (   K   | ]}|j         	|V  d S N)_meta_parent).0as     r$   	<genexpr>z&ConfigBase.__call__.<locals>.<genexpr>>   s)      \\QQ^\q\\\\\\r'   c                 $    i | ]\  }}|v	||S r   r   )r2   kv
filter_apps      r$   
<dictcomp>z'ConfigBase.__call__.<locals>.<dictcomp>?   s)    III41aQj5H5H!Q5H5H5Hr'   )r   r   )r%   copyr   r   r   KeyErrornext	app_stackcurrent_frameitemsr   r   stackr   )r#   r+   r,   r-   r%   keyr8   s         @r$   __call__zConfigBase.__call__-   s    "&!1!1!3!3	T^9R-ZXXXZ[[ % %% 	 	 	FF	 $ 	cJJ\\#-*E\\\^abbJIIII6<<>>III"KM#n,	
 	
 	
 	
 	
 	
s   )A 
AA)__name__
__module____qualname____doc__r   r   r   r   str__annotations__r   boolr   r   propertyr   dictr
   r%   r   tupler   rC   r   r'   r$   r   r      sD           %uR;MNNNIx}NNN%...M4...!&t!4!4!4$444%H===GS4Z==="S#X " " " ^ X" " " " " ^ X"

 S/
 &	
 
 
 
 
 
r'   r   c                   *    e Zd ZdZdeez  fdZd ZdS )FileCacheKeyzAbstraction to quickly check if a file needs to be read again.

    If a newly instantiated ``CacheKey`` doesn't equal a previously instantiated ``CacheKey``,
    then the file needs to be re-read.
    pathc                    t          |                                          | _        | j                                        r3| j                                        }|j        | _        |j        | _        d S d | _        d | _        d S r0   )	r   absoluterP   existsstatst_mtime_mtimest_size_size)r#   rP   rT   s      r$   __init__zFileCacheKey.__init__R   sj    JJ''))	9 	9>>##D-DKDJJJDKDJJJr'   c                     t          |t          |                     sdS | j        |j        k    o| j        |j        k    o| j        |j        k    S )NF)
isinstancetyperV   rX   rP   )r#   others     r$   __eq__zFileCacheKey.__eq__\   sL    %d,, 	5{el*dtzU[/HdTYZ_ZdMddr'   N)rD   rE   rF   rG   rH   r   rY   r^   r   r'   r$   rO   rO   K   sQ         S4Z    e e e e er'   rO   c                      e Zd ZU dZ ee          Zeez  ed<    edd          Z	e
ed<    edd          Ze
ed<    ed	dd
          Zeeef         d	z  ed<   	  ed	dd
          Zed	z  ed<   	 ededeeef         fd            Zedeeef         fd            Zedefd            Zej        dedd	fd            Zd	S )ConfigFromFilezlConfiguration source that loads from a file.

    Supports file caching and parent directory searching.
    )r   rP   FT)r   r   
must_existsearch_parentsN)r   initrepr_config_config_cache_keyr   c                     t           )a>  Load the config dictionary from path.

        Do **not** do any downstream caching; ``ConfigFromFile`` handles caching.

        Parameters
        ----------
        path: Path
            Path to the file. Guaranteed to exist.

        Returns
        -------
        dict
            Loaded configuration.
        r    )r#   rP   s     r$   _load_configzConfigFromFile._load_configt   s
      "!r'   c                 >   t          | j        t                    sJ | j                                                                                                        j        D ]`}|| j        j        z  }|                                rt          |          }| j
        |k    r| j        pi c S 	 |                     |          | _        || _
        n# t          $ r  t          $ ry}t          t!          |          dd          }t#          t$                    5  |j        d         }|r|dz  }||z  }d d d            n# 1 swxY w Y   t          |          |d }~ww xY w| j        c S | j        r| j        rIt-          t.          j        t3          j        t.          j                  t7          | j                            b| j        rIt-          t.          j        t3          j        t.          j                  t7          | j                            i | _        | j        S )NrD    r   z: )msg)r[   rP   r   
expanduserresolverR   parentsnamerS   rO   rf   re   rh   r   	Exceptiongetattrr\   r   
IndexErrorargsrb   ra   FileNotFoundErrorerrnoENOENTosstrerrorrH   )r#   parent	candidate	cache_keyerk   exception_msgs          r$   r%   zConfigFromFile.config   sV   $)T*****i**,,4466??AAI 	a 	aF/I!! a(33	)Y66<-2---8#'#4#4Y#?#?DL-6D**$     8 8 8!$q'':r::C!*-- - -()q	 (4KC},	- - - - - - - - - - - - - - -
 (C000a78 |###$ a a'bk%,6O6OQTUYU^Q_Q_```a ? 	]#EL"+el2K2KSQUQZ^^\\\|s<   +!CE!2ED9-E9D==E D=EEc                     | j         | j         S t          | j        t                    sJ t	          | j                                                  S r)   )r   r[   rP   r   rH   rR   r"   s    r$   r   zConfigFromFile.source   sH     <#<$)T*****49%%''(((r'   valuec                     || _         d S r0   r   r#   r   s     r$   r   zConfigFromFile.source       r'   )rD   rE   rF   rG   r   r   rP   rH   rI   ra   rJ   rb   re   rL   r
   rf   rO   r   rh   rK   r%   r   setterr   r'   r$   r`   r`   c   s         
 ut,,,D#*,,,uUD999J999 5===ND===%*U4e%%P%P%PGT#s(^d"PPPZ-2U4eRW-X-X-X|d*XXX4" "$sCx. " " " ^"" "S#X " " " X"H ) ) ) ) X) ]C D    ]  r'   r`   c                       e Zd ZU dZeeef         ed<   edeeef         fd            Z	edefd            Z
e
j        deddfd            Z
dS )	DictzrConfiguration source from an in-memory dictionary.

    Useful for programmatically generated configurations.
    datar   c                     | j         S r0   )r   r"   s    r$   r%   zDict.config   s
    yr'   c                 "    | j         | j         S dS )r*   NrL   r   r"   s    r$   r   zDict.source   s     <#<vr'   r   Nc                     || _         d S r0   r   r   s     r$   r   zDict.source   r   r'   )rD   rE   rF   rG   rL   rH   r
   rI   rK   r%   r   r   r   r'   r$   r   r      s          
 sCx.S#X    X     X ]C D    ]  r'   r   ) ru   rw   abcr   r   collections.abcr   
contextlibr   	itertoolsr   pathlibr   typingr	   r
   attrsr   r   cyclopts.argumentr   r   cyclopts.exceptionsr   cyclopts.utilsr   cyclopts.corer   r   rO   r`   r   r   r'   r$   <module>r      s    				 # # # # # # # # $ $ $ $ $ $                   % % % % % % % %         L L L L L L L L - - - - - - - - - - - - "!!!!!! 3
 3
 3
 3
 3
 3
 3
 3
le e e e e e e e0 Q Q Q Q QZ Q Q Qh     :     r'   