
    h(                     "   S SK r S SKrS SKrS SKrS SKrS SKJrJrJrJ	r	J
r
JrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJ r J!r!  S SK"r" S SK#J$r$J%r%J&r&J'r'  S SK(J)r)  S S	K*J+r+  SSK0J1r1J2r2  Sr3Sr4SS0r5Sr6Sr7\Rp                  " S5      r9 " S S\5      r:S6S\;4S jjr< " S S\=5      r>S\?S\\\?      4S jr@S\?S\4S jrAS7S\S\ \\?\=4   \>\?4   S\?4S  jjrBS!S".S#\ \\?\4   \>4   S$\ \\?\4   \>4   S%\;S\ \\?\4   \>4   4S& jjrC " S' S(\D5      rES\?S\?4S) jrFS*\)S+\S\)4S, jrG " S- S.\$5      rH " S/ S05      rI\ " S1 S25      5       rJ " S3 S45      rK/ S5QrLg! \, a    S S
K-J$r$J'r'J&r&J%r%  S S	K.J+r+  S SK/J)r)   GNf = f)8    N)	MAX_INTERPOLATION_DEPTHConfigParserExtendedInterpolationInterpolationDepthErrorInterpolationMissingOptionErrorInterpolationSyntaxErrorNoOptionErrorNoSectionErrorParsingError)	dataclass)Path)GeneratorType)AnyCallableDictIterableListMappingOptionalSequenceTupleTypeUnioncast)	BaseModelExtraValidationErrorcreate_model)
ModelField)ModelMetaclass)r   r   r   r      )SimpleFrozenDictSimpleFrozenList*VARIABLE_POSITIONAL_ARGSvalidatez	validate z__SECTION__:)truefalsenullz\$\{[\w\.:]+\}c                   F   ^  \ rS rSrU 4S jrS rS rS\S\4S jrSr	U =r
$ )	CustomInterpolation@   c                 :  >  [         R                  " U5      n[        U[        5      (       a  U[        ;  a  Un[        TU ])  XX45      $ ! [
         a;    U(       a1  US   US   s=:X  a  S:X  a  O   N8[        R                  " SU S35         NT[         a     N_f = f)Nr   'zThe value [zZ] seems to be single-quoted, but values use JSON formatting, which requires double quotes.)srsly
json_loads
isinstancestrJSON_EXCEPTIONS
ValueErrorwarningswarn	Exceptionsuperbefore_read)selfparsersectionoptionvalue
json_value	__class__s         M/home/james-whalen/.local/lib/python3.13/site-packages/confection/__init__.pyr:   CustomInterpolation.before_readA   s    	))%0J*c**z/P" w"6FBB  	qU2Y5#5!% )I I  		s   7A
 
&B2B	BBc           	      P    / nU R                  XXdX%S5        SR                  U5      $ )Nr!    )interpolatejoin)r;   r<   r=   r>   r?   defaultsLs          rB   
before_getCustomInterpolation.before_getR   s)    7aHwwqz    c           
         UR                  XRSUS9nU[        :  a  [        X%U5      eU(       Ga*  UR                  S5      n	U	S:  a  UR	                  U5        g U	S:  a  UR	                  US U	 5        XIS  nUSS n
U
S:X  a  UR	                  S5        USS  nGOU
S:X  Ga  U R
                  R                  U5      nUc  SU 3n[        X%U5      eUR                  S5      nUR                  S	S
5      R                  S
S5      nXKR                  5       S  nUnUn [        U5      S:X  aR  UR                  US   5      nUU;   a  UU   nOXR                  US   5         R                  nU R                  U5      nOv[        U5      S:X  aV  US   nUR                  US   5      nSnUR                  UUSUS9nUU:X  a"  U R                  X S
U 3   R                  5      nOSU 3n[        X%U5      eSU;   a4  [)        UR+                  USS95      nU R-                  UUUUUUUS-   5        O$UR	                  U5        OSU< 3n[        X%U5      eU(       a  GM)  g g ! [         ["        [$        4 a    ['        X%X5      S ef = f)NT)rawfallback$r   r!      {z%bad interpolation variable reference :.__FALLBACK__zMore than one ':' found: )rN   z+'$' must be followed by '$' or '{', found: )getr   r   findappend_KEYCREmatchr   groupreplacersplitendlenoptionxform_name_get_section_nameKeyErrorr
   r	   r   dictitemsrF   )r;   r<   r>   accumrestr=   mapdepthrawvalpcmerrorig_varpathsectoptvsection_namerO   new_maps                        rB   rF   CustomInterpolation.interpolateX   s    GE**)&6BB		#A1uT"1uT"1X&BxQq	ACxS!ABxcLL&&t,9A$HC26CHH771:''S188a@EEGI 4yA~$00a9#: #CA ,22D2DT!W2M+N+T+TL $ 6 6| DATa#Aw$00a9#1"JJtSdXJN = $ 6 6vauo7N7T7T UA 9$@6vLL
 !8"6<<$<#?@G$$VS%D'5ST9ULLOQ T JNO.vDDq dZ !.-@  9  s   .I 	1I ;A$I  I #I>namereturnc                     S[          U S3$ )a$  Generate the name of a section. Note that we use a quoted string here
so we can use section references within lists and load the list as
JSON. Since section references can't be used within strings, we don't
need the quoted vs. unquoted distinction like we do for variables.

Examples (assuming section = {"foo": 1}):
    - value: ${section.foo} -> value: 1
    - value: "hello ${section.foo}" -> value: "hello 1"
    - value: ${section} -> value: {"foo": 1}
    - value: "${section}" -> value: {"foo": 1}
    - value: "hello ${section}" -> invalid
")SECTION_PREFIX)r;   rw   s     rB   rb   %CustomInterpolation._get_section_name   s     >"4&**rL    )__name__
__module____qualname____firstlineno__r:   rJ   rF   r3   rb   __static_attributes____classcell__)rA   s   @rB   r+   r+   @   s.    C"BEH+c +c + +rL   r+   rF   c                 P    [        U (       a
  [        5       OS S9n[        Ul        U$ )N)interpolation)r   r+   r3   r`   )rF   configs     rB   get_configparserr      s"    (;(=RVWFFMrL   c            
       x   \ rS rSr% Sr\\S'    S)SSS.S\\\	\
\4   SS 4      S\\   S\\\
      S	S4S
 jjjrS*S jrS+S jr S,S\\	\
\4   S 4   S\
S	S4S jjrS\S	\4S jr/ S.S\S\\
   S	\4S jjrS*S jr S-S\\	\
\4   S 4   S\S	S 4S jjrS\S S\	\
\4   4   S	\	\
\4   4S jrSSS\	\
\4   S	S4S jrS+S jrS0 S.S\
S\S\	\
\4   S	S 4S  jjrSS!.S\S	\
4S" jjrSS!.S\S	\4S# jjrS0 S.S$\S\S\	\
\4   S	S 4S% jjrSS!.S&\\
\4   S\4S' jjrS0 S.S&\\
\4   S\S\	\
\4   S	S 4S( jjrSr g).Config   zThis class holds the model and training configuration and can load and
save the TOML-style configuration format from/to a string, file or bytes.
The Config class is a subclass of dict and uses Python's ConfigParser
under the hood.
is_interpolatedNr   section_orderdatar   r   rx   c                   [         R                  U 5        Uc  0 n[        U[         [        [        45      (       d  [        S[        U5       35      eUb  X l        O.[        U[        5      (       a  UR                  U l        OSU l        Ub  X0l        O.[        U[        5      (       a  UR                  U l        O/ U l        U R                  U R                  U5      5        g)z2Initialize a new Config object with optional data.NzRCan't initialize Config with data. Expected dict, Config or ConfigParser but got: T)rd   __init__r2   r   r   r5   typer   r   update_sort)r;   r   r   r   s       rB   r   Config.__init__   s     	d<D$v| <==))-d6  &#2 f%%#'#7#7D #'D $!.f%%!%!3!3D!#DDJJt$%rL   c                 P    [        5       R                  U R                  5       5      $ )z3Interpolate a config. Returns a copy of the object.)r   from_strto_str)r;   s    rB   rF   Config.interpolate   s     x  //rL   r   c                 "   U R                  U5        S n[        UR                  5       US9 GH0  u  p4US:X  a  M  UR                  S5      nU nUSS  H<  nUS:X  a  UR	                  U0 5      nM  Xv;  a  SnUS	U S
3S./n	[        X	US9eXg   nM>     [        U[        5      (       d!  USS./n	U  SW[        U5      0 3n
[        XS9eUR	                  US   0 5      n[        U[        5      (       d!  USS./n	U  SW[        U5      0 3n
[        XS9e [        UR                  5       5      nU H)  u  pUR                  X=5      nU R                  U5      Xm'   M+     GM3     U R                  U 5        g! [         a  n[        U S9SeSnAff = f)zInterpret a config, parse nested sections and parse the values
as JSON. Mostly used internally and modifies the config in place.
c                 <    [        U S   R                  S5      5      $ Nr   rT   )r_   split)items    rB   <lambda>)Config.interpret_config.<locals>.<lambda>   s    T!W]]3%7!8rL   keyDEFAULTrT   Nr.   r$   z>Error parsing config section. Perhaps a section name is wrong?	Section '' is not definedlocmsgr   errorstitlezfound conflicting values
r   r   desc)_validate_sectionssortedre   r   
setdefaultConfigValidationErrorr2   rd   listr   rV   _interpret_valuereplace_section_refs)r;   r   	get_depthr=   valuespartsnodepart	err_titlern   err_cfgkeys_valueser   r?   config_vs                   rB   interpret_configConfig.interpret_config   s    	' 9	%flln)DOG)#MM#&EDcr
3;??44D%X  $)9TFBR1STUC/#y   :D # dD))$-GHI!F"tT&\&:$<=+7GG??59b1DdD))$-GHI!F"tT&\&:$<=+7GGC"6<<>2 *
!::g3 11(;	 *G  EL 	!!$' 3 C+A38dBCs   E44
F>F		Fparentc           	      R   UR                  5        H  u  p4U SU 3R                  S5      n[        U[        5      (       a  U R	                  XES9  MA  [        U[
        5      (       a%  U Vs/ s H  o`R                  XbU/S9PM     snX'   M{  U R                  XBU/S9X'   M     gs  snf )z9Replace references to section blocks in the final config.rT   r   N)re   stripr2   rd   r   r   _get_section_ref)r;   r   r   r   r?   
key_parentrs   s          rB   r   Config.replace_section_refs  s     !,,.JC"81SE*005J%&&))%)CE4((LQLQq))!SM)BE #33E3-3P )
s   +B$r?   c                 ~    [        U5      n[        U[        5      (       a  [        R	                  U5      (       a  UnU$ )z Interpret a single config value.)try_load_jsonr2   r3   VARIABLE_REsearch)r;   r?   results      rB   r   Config._interpret_value%  s5    u% fc""{'9'9%'@'@FrL   r   c                "   [        U[        5      (       a(  UR                  S[         35      (       a  [	        U5      n[        U[        5      (       aQ  UR                  [        5      (       a7  UR                  [        S5      R                  S5      nU nU H  n XE   nM
     U$ [        U[        5      (       a  [        U;   a  S
n	USS./n[        XS9eU$ ! [        [        4 a(    SnSSR                  U5       S3nX7S./n[        XUS9S	ef = f)zGet a single section reference.rz   rE   rT   z)Error parsing reference to config sectionr   r   r   r   Nab  Can't reference whole sections or return values of function blocks inside a string or list

You can change your variable to reference a value instead. Keep in mind that it's not possible to interpolate the return value of a registered function, since variables are interpolated when the config is loaded, and registered functions are resolved afterwards.z'uses section variable in string or list)r   r   )r2   r3   
startswithr{   r   r\   r   rc   	TypeErrorrG   r   )
r;   r?   r   r   r   r   r   err_msgrn   err_descs
             rB   r   Config._get_section_ref1  s   eS!!e&6&6>:J7K&L&L!%(EeS!!e&6&6~&F&FMM."5;;C@EF #\F  Ms##%(?
O  "*STUC'sBB- !),   KI )#((5/)::JKG#(9:C/#y 	 s   C8Dc                      [         R                  " U 5      n[	        UU R
                  U R                  S9$ ! [         a  n[        SU 35      UeSnAff = f)zDeepcopy the config.zCouldn't deep-copy config: Nr   )copydeepcopyr8   r5   r   r   r   )r;   r   r   s      rB   r   Config.copyS  sc    	G]]4(F  00,,
 	
  	G:1#>?QF	Gs   7 
AAAupdatesremove_extrac                     U R                  5       n[        U5      R                  5       n[        XUS9n[        UUR                  =(       a    UR                  UR                  S9$ )z>Deep merge the config with updates, using current as defaults.r   r   )r   r   deep_merge_configsr   r   )r;   r   r   rH   mergeds        rB   mergeConfig.merge_  sZ     99;/&&(#GLQ$44P9P9P"00
 	
rL   c                    ^ [        U R                  5       VVs0 s H  u  p#X2_M	     snnmU4S jn[        [        UR	                  5       US95      $ s  snnf )zSort sections using the currently defined sort order. Sort
sections by index on section order, if available, then alphabetic, and
account for subsections, which should always follow their parent.
c                    > TR                  U S   R                  S5      S   [        T5      5      [        U S   5      4$ r   )rV   r   r_   _mask_positional_args)xsort_maps    rB   r   Config._sort.<locals>.<lambda>t  s7    LL1C+S];!!A$'
rL   r   )	enumerater   rd   r   re   )r;   r   ir=   sort_keyr   s        @rB   r   Config._sortl  sQ     2;4;M;M1NO1N:1GJ1NO
 F4::<X677 Ps   A	overridesc           	          SnUR                  5        Hh  u  pESnUR                  S5      US./nSU;  a	  [        XsS9eUR                  SS5      u  pX;  a	  [        XsS9eUR	                  X[        XR5      5        Mj     g)z?Set overrides in the ConfigParser before config is interpreted.zError parsing config overridesz*not a section value that can be overriddenrT   r   r   r   r!   N)re   r   r   r]   settry_dump_json)
r;   r   r   r   r   r?   r   rn   r=   r>   s
             rB   _set_overridesConfig._set_overridesz  s|    4	#//+JCBG99S>':;C#~+3HH!jja0OG$+3HHJJwe(GH ,rL   c                     UR                  5       nU(       a"  SnSnU Vs/ s H  oU/US.PM
     nn[        XcS9eg s  snf )Nz/Found config values without a top-level sectionznot part of a sectionr   r   )rH   r   )r;   r   default_sectionr   r   krn   s          rB   r   Config._validate_sections  sL    
 !//+II-G9HIA3w/CI'sDD	  Js   ;TrF   r   textrF   c                   [        US9nU(       a	  [        SS9n UR                  U5        U R	                  UR
                  5      Ul        U R                  XC5        U R                  5         U R                  U5        U(       a  U(       a  U R                  5       n X l
        U $ ! [         a  nSU 3n[        US9SeSnAff = f)zLoad the config from a string.rF   Fz<Make sure the sections and values are formatted correctly.

r   N)r   read_stringr   r   r   	_sectionsr   clearr   rF   r   )r;   r   rF   r   r   r   r   s          rB   r   Config.from_str  s     "k:%%8F	=t$  ::f&6&67F.

f%##%D*  	=STUSVWD'T2<	=s   B$ $
C.B==Cr   c          
      &   [        US9n[        5       U 4/nU GH   u  pESR                  U5      nU=(       a    US   S:g  nU(       a'  UR                  U5      (       d  UR	                  U5        UR                  5        H  u  p[        U	S5      (       ae  [        R                  U	5      (       a3  [        U	5      S:X  a$  U(       a  UR                  Xh[        X5      5        Mc  UR                  XH4-   U	45        M{  UR                  Xh[        X5      5        M     GM     U R                  UR                  5      Ul        U R                  U5        [         R"                  " 5       n
UR%                  U
5        U
R'                  5       R)                  5       $ )zWrite the config to a string.r   rT   r.   r$   re   r!   )r   tuplerG   has_sectionadd_sectionre   hasattrregistry
is_promiser_   r   r   rX   r   r   r   ioStringIOwritegetvaluer   )r;   rF   	flattenedqueuerp   r   rt   is_kwargr   r?   	string_ios              rB   r   Config.to_str  s7   $=	05.?JD88D>L/RCH	 5 5l C C %%l3"jjl
5'**  **511c%jAo(!lu9STdVmU%;<MM,]55OP +  & #jj)<)<=		*KKM		"!!#))++rL   c                >    U R                  US9R                  S5      $ )z&Serialize the config to a byte string.r   utf8)r   encode)r;   rF   s     rB   to_bytesConfig.to_bytes  s    {{{{3::6BBrL   
bytes_datac                @    U R                  UR                  S5      X#S9$ )z#Load the config from a byte string.r  r   )r   decode)r;   r  rF   r   s       rB   
from_bytesConfig.from_bytes  s*     }}f%;  
 	
rL   rp   c                    [        U[        5      (       a  [        U5      OUnUR                  SSS9 nUR	                  U R                  US95        SSS5        g! , (       d  f       g= f)zSerialize the config to a file.wr  encodingr   N)r2   r3   r   openr  r   )r;   rp   rF   file_s       rB   to_diskConfig.to_disk  sN    'c22tDzYYsVY,KK<= -,,s   A
A)c                    [        U[        5      (       a  [        U5      OUnUR                  SSS9 nUR	                  5       nSSS5        U R                  WX#S9$ ! , (       d  f       N= f)zLoad config from a file.rr  r  Nr   )r2   r3   r   r  readr   )r;   rp   rF   r   r  r   s         rB   	from_diskConfig.from_disk  sY     (c22tDzYYsVY,::<D -}}T{}PP -,s   A
A*)N)rx   r   )r   r   rx   NrE   )F)!r~   r   r   r   __doc__bool__annotations__r   r   r   r3   r   r   r   rF   r   r   r   r   r   r   r   r   r   r   r   bytesr  r  r   r  r#  r   r}   rL   rB   r   r      s     KO & +/-1 &uT#s(^^XEFG & "$	 &
  S	* & 
 &D0.(b FHQDcNH45Q?BQ	Q
c 
c 
 CE  c  d3i    D

 NS
T#s(^X56
FJ
	
8(NDcNBC8	c3h8I^ IS#X ISW I
E 15RT)-AEc3h	, -1 ,T ,S ,: /3 Ct Cu C !$&



 	


 S>

 


 FJ >E#t), >d > !$&QCIQ 	Q
 S>Q 
Q QrL   r   rw   rx   c                     [        [        [        [              U R	                  S5      5      n[        S[        U5      5       H  nXS-
     S:X  d  M  SX'   M     U$ )zmCreate a section name representation that masks names
of positional arguments to retain their order in sorts.rT   r!   r$   N)r   r   r   r3   r   ranger_   )rw   stable_namer   s      rB   r   r     sW     tHSM*DJJsO<K 1c+&'1u$!KN ( rL   r?   c                 T     [         R                  " U 5      $ ! [         a    U s $ f = f)zDLoad a JSON string if possible, otherwise default to original value.)r0   r1   r8   )r?   s    rB   r   r     s,    && s    ''r   c                    [        U [        5      (       a  [        R                  U 5      (       a  U $ [        U [        5      (       a,  U R	                  SSS5      R                  5       (       a  SU  S3n  [        R                  " U 5      n [        R                  " SSU 5      n [        R                  " SSU 5      n U $ ! [         a!  nS	[        U 5       S
U S3n[        XS9UeSnAff = f)zGDump a config value as JSON and output user-friendly error if it fails.rT   rE   r!   rz   z\$([^{])z$$z\$$z$$z(Couldn't serialize config value of type z: z. Make sure all values in your config are JSON-serializable. If you want to include Python objects, use a registered function that returns the object instead.)r   r   N)r2   r3   r   r   r\   isdigitr0   
json_dumpsresubr8   r   r   )r?   r   r   r   s       rB   r   r     s     %+"4"4U";";%%--R";"C"C"E"EE7!F  '{FE2vtU+ F6tE{m2aS I" # 	 $4>AEFs   4AB< <
C'C""C'Fr   r   rH   r   c                   U(       a+  [        U R                  5       5      nU H  nXA;  d  M
  X	 M     UR                  5        GH  u  pE[        U[        5      (       a  U R                  U0 5      n[        U[        5      (       d  MD  U Vs/ s H  owR                  S5      (       d  M  UPM     nnU(       a  US   OSn	U(       a*  U Vs/ s H  owR                  S5      (       d  M  UPM     snO/ n
U
(       a  U
S   OSnU	(       a  U(       a  X;   a  Xi   XY   :w  a  M  U(       a  X;  d
  Xk   X[   :w  a  M  [        XeUS9nM  X@;  d  GM  XPU'   GM     U $ s  snf s  snf )zDeep merge two configs.@r   Nr   )r   keysre   r2   rd   r   r   r   )r   rH   r   r5  r   r?   r   r   value_promisesvalue_promisenode_promisesnode_promises               rB   r   r     s.    FKKM"C"K  nn&
eT""$$S"-DdD))).DA,,s2CaND1?N1-TMFJB1S0AQBPRM/<=+$L  !)+u/CC )T-?5CV-V)$LQH3K5 '6 M- EBs   E(E	E&Ec                      \ rS rSrS\" 5       SSSSS.S\\\\\	\\	\
4   4   \	4      S\\\\	\
4      \\\	\
4      4   S\\	   S	\\	   S
\\	   S\SS4S jjr\    SSS S\\	   S	\\	   S
\\	   S\\   SS 4S jj5       rS\	4S jrSrg)r   iD  NzConfig validation errorTr   r   r   r   r   show_configr   r   r   r   r   r<  rx   c                b   Xl         X l        X0l        X@l        XPl        X`l        [        5       U l        U R                   H8  nUR                  S5      nU(       d  M  U R                  R                  U5        M:     U R                  5       U l        [        R                  X R                  5        g)a  Custom error for validating configs.

config (Union[Config, Dict[str, Dict[str, Any]], str]): The
    config the validation error refers to.
errors (Union[Sequence[Mapping[str, Any]], Iterable[Dict[str, Any]]]):
    A list of errors as dicts with keys "loc" (list of strings
    describing the path of the value), "msg" (validation message
    to show) and optional "type" (mostly internals).
    Same format as produced by pydantic's validation error (e.errors()).
title (str): The error title.
desc (str): Optional error description, displayed below the title.
parent (str): Optional parent to use as prefix for all error locations.
    For example, parent "element" will result in "element -> a -> b".
show_config (bool): Whether to print the whole config with the error.

ATTRIBUTES:
config (Union[Config, Dict[str, Dict[str, Any]], str]): The config.
errors (Iterable[Dict[str, Any]]): The errors.
error_types (Set[str]): All "type" values defined in the errors, if
    available. This is most relevant for the pydantic errors that define
    types like "type_error.integer". This attribute makes it easy to
    check if a config validation error includes errors of a certain
    type, e.g. to log additional information or custom help messages.
title (str): The title.
desc (str): The description.
parent (str): The parent.
show_config (bool): Whether to show the config.
text (str): The formatted error text.
r   N)r   r   r   r   r   r<  r   error_typesrV   add_formatr   r5   r   )	r;   r   r   r   r   r   r<  errorerr_types	            rB   r   ConfigValidationError.__init__E  s    N 
	&5[[Eyy(Hx  $$X. ! LLN	D)),rL   rn   c           	          U " UR                   UR                  Ub  UOUR                  Ub  UOUR                  Ub  UOUR                  Ub  US9$ UR
                  S9$ )a  Create a new ConfigValidationError based on an existing error, e.g.
to re-raise it with different settings. If no overrides are provided,
the values from the original error are used.

err (ConfigValidationError): The original error.
title (str): Overwrite error title.
desc (str): Overwrite error description.
parent (str): Overwrite error parent.
show_config (bool): Overwrite whether to show config.
RETURNS (ConfigValidationError): The new error.
r;  r;  )clsrn   r   r   r   r<  s         rB   
from_error ConfigValidationError.from_errorz  sf    ( :::: ,%#)))sxx#/6SZZ'2'>
 	
 EHOO
 	
rL   c                 *   Sn/ nU R                    H  nSU S3R                  UR                  S/ 5       Vs/ s H  n[        U5      PM     sn5      nU R                  (       a  U R                   SU SU 3nUR                  XSR                  S5      45        M     / nU R                  (       a  UR                  U R                  5        U R                  (       a  UR                  U R                  5        U(       a;  UR                  SR                  U Vs/ s H  owS    SUS    3PM     sn5      5        U R                  (       a-  U R                  (       a  UR                  U R                   5        S	SR                  U5      -   $ s  snf s  snf )
zFormat the error message.z-> r   r   r   r   	r!   z

)
r   rG   rV   r3   r   rX   r   r   r   r<  )r;   loc_dividerr   rA  rk   err_locr   entrys           rB   r@  ConfigValidationError._format  s;   [[E+a(--uyyPR?S.T?S!s1v?S.TUG{{![[M;-q	BKK))E"234	 !
 ::MM$**%99MM$))$MM$))D$QD5azE!H:%>D$QRS;;4++MMT[[M+		&))) /U %Rs   F
F)r   r   r>  r   r   r<  r   r   )NNNN)r~   r   r   r   r   r   r   r   r   r3   r   r   r   r   r'  r   classmethodrF  r@  r   r}   rL   rB   r   r   D  s2    KOOTw8" $ 3- vtCc3h,?'@#EFG3- hwsCx018DcN3KKL	3-
 }3- sm3- 3- 3- 
3-j   $" $&*
$
 }
 sm	

 
 d^
 
!
 
8* *rL   r   c                 L    U [         :X  a  [        $ U [        ;   a	  [        U    $ U $ )z)Generate field aliases in promise schema.)ARGS_FIELD_ALIAS
ARGS_FIELDRESERVED_FIELDS)rw   s    rB   alias_generatorrT    s+     t$$KrL   fieldtype_c                     [        U R                  UU R                  U R                  U R                  U R
                  U R                  U R                  S9$ )zzCopy a model field and assign a new type, e.g. to accept an Any type
even though the original value is typed differently.
)rw   rV  class_validatorsmodel_configdefaultdefault_factoryrequiredalias)r   rw   rX  rY  rZ  r[  r\  r]  )rU  rV  s     rB   copy_model_fieldr^    sK     ZZ//''--kk	 	rL   c                   (    \ rS rSr " S S5      rSrg)EmptySchemai  c                       \ rS rSrSrSrSrg)EmptySchema.Configi  allowTr}   N)r~   r   r   r   extraarbitrary_types_allowedr   r}   rL   rB   r   rb    s    "&rL   r   r}   N)r~   r   r   r   r   r   r}   rL   rB   r`  r`    s    ' 'rL   r`  c                        \ rS rSrSrSr\rSrg)_PromiseSchemaConfigi  forbidTr}   N)r~   r   r   r   rd  re  rT  r   r}   rL   rB   rg  rg    s    E"%OrL   rg  c                   N    \ rS rSr% \\S'   \\S'   \\   \S'   \\\4   \S'   Sr	g)Promisei  r  rw   argskwargsr}   N)
r~   r   r   r   r3   r(  r   r   r   r   r}   rL   rB   rj  rj    s#    M
I
s)OcNrL   rj  c                      \ rS rSr\S\S\S\4S j5       r\S\S\S\4S j5       r	\\
0 SS.S	\\\\\\\4   4   4   S
\\   S\\\4   S\S\\\4   4
S jj5       r\\
0 SS.S	\\\\\\\4   4   4   S
\\   S\\\4   S\4S jj5       r\\
0 SSS.S	\\\\\\\4   4   4   S
\\   S\\\4   S\S\S\\\\4   \4   4S jj5       r\\
4SSS0 S.S	\\\\\\\4   4   4   S
\\   S\S\S\S\\\\\4   4   S\\\\\4   \4   \\\\4   \4   \\\4   4   4S jjj5       r\S\\\4   S\\\4   S\\\4   4S j5       r\S\S\\\4   4S j5       r\S\S	\\\\4   \4   4S j5       r\S\S\4S j5       r\S\\\4   S\\\4   4S j5       r\S\\\4   S\\\   \\\4   4   4S  j5       r\SS!.S\\\4   S\S\\   4S" jj5       rS#rg$)%r  i  registry_name	func_namerx   c                 B    [        X5      (       d  g[        X5      nX#;   $ )z4Check whether a function is available in a registry.F)r  getattr)rE  rn  ro  regs       rB   hasregistry.has  s%     s**c)rL   c                     [        X5      (       d  [        SU S35      e[        X5      nUR                  U5      nUc  [        SU SU S35      eU$ )z0Get a registered function from a given registry.zUnknown registry: 'r/   zCould not find 'z' in ')r  r5   rq  rV   )rE  rn  ro  rr  funcs        rB   rV   registry.get  sa     s**2=/CDDc)wwy!</	{&qQRRrL   T)schemar   r&   r   rx  r   r&   c                ,    U R                  XX4SS9u  pVU$ )NTrx  r   r&   resolve_make)rE  r   rx  r   r&   resolved_s          rB   r{  registry.resolve  s(     iiYSW   
 rL   c                ,    U R                  XX4SS9u  pVU$ )NFrz  r|  )rE  r   rx  r   r&   r  filleds          rB   fillregistry.fill  s(     IIYSX  
	 rL   )rx  r   r{  r&   r{  c                   U R                  U5      (       a  Sn[        USU0/S9e[        U[        5      (       + =(       d    UR                  n[        U[        5      (       a  UR
                  OSnUn	U(       d  [        U	5      R                  5       nU R                  XXSUS9u  pn[        XS9n
U(       a  U R                  X5        U(       d  U
R                  [        U	SS9S	S
9n
[        U5      U
4$ )a  Unpack a config dictionary and create two versions of the config:
a resolved version with objects from the registry created recursively,
and a filled version with all references to registry functions left
intact, but filled with all values and defaults based on the type
annotations. If validate=True, the config will be validated against the
type annotations of the registered functions referenced in the config
(if available) and/or the schema (if available).
zJThe top-level config object can't be a reference to a registered function.r   r   N)r&   r   r{  )r   F)r   Tr   )r  r   r2   r   r   r   rF   _fill_validate_overridesr   rd   )rE  r   rx  r   r{  r&   r   r   r   orig_configr  r  r~  s                rB   r}  registry._make  s    ( >>&!!bG'vw?O>PQQ )88RF<R<R0:660J0J,,PTK(446F!iiXG ( 
8 <##F6
 \\{E: " F H~v%%rL   rE   r&   r{  r   r   r   c          
      x	   0 n0 n0 n	UR                  5        GH  u  p[        R                  X5      nU SU
 3R                  S5      nX;   a  Xm   nXU
'   U R	                  U5      (       a  XR
                  ;   a3  U(       d,  UR
                  U
   n[        U[        5      UR
                  U
'   U R                  XS9nU R                  UUUUUUS9u  Xz'   X'   X'   U R                  X   5      u  nnU R                  X   5      u  nnU(       a  U R                  UU5      nU" U0 UD6nO[        UUUUS9nUX'   UX'   [        X   [        5      (       a  / X'   GMC  GMF  [        US5      (       Ga,  [         nXR
                  ;   a@  UR
                  U
   nUR"                  n[        UR"                  [$        5      (       d  [         nU R                  UUUUUUS9u  Xz'   X'   X'   U
[&        :X  a  [        X   [(        5      (       a  [+        X   R-                  5       5      X'   [+        X   R-                  5       5      X'   [.        UR
                  ;   aA  U(       d7  UR
                  [.           n[        U[        5      UR
                  [.        '   GMx  GM{  GM~  GM  GM  XU
'   [        U[        5      (       d  UO/ X'   XU
'   GM     / nU(       a   UR1                  U5      nOUR8                  " S	0 UD6nUR:                  R<                  [>        R@                  [>        RB                  4;   a`  UR
                  RE                  5       nURF                   Vs/ s H  nU[&        :w  a  UO[.        PM     nnU Vs/ s H  nUU;  d  M  UPM     nn[I        [.        /[        RE                  5       Q5      nURK                  UR)                  US95        U RM                  XU	5      u  pyU(       a  UR                  5        VVs0 s H  u  nnUU;  d  M  UU_M     nnnUR                  5        VVs0 s H  u  nnUU;  d  M  UU_M     nnnU	R                  5        VVs0 s H  u  nnUU;  d  M  UU_M     n	nnXxU	4$ ! [2         a  n[5        UUR7                  5       US9SeSnAff = fs  snf s  snf s  snnf s  snnf s  snnf )
ap  Build three representations of the config:
1. All promises are preserved (just like config user would provide).
2. Promises are replaced by their return values. This is the validation
   copy and will be parsed by pydantic. It lets us include hacks to
   work around problems (e.g. handling of generators).
3. Final copy with promises replaced by their return values.
rT   r{  r  )r  rw   rk  rl  re   )r   r   r   N)excluder}   )'re   rS  rV   r   r  
__fields__r^  r   make_promise_schemar  get_constructor
parse_argsrj  r2   r   r  r`  rV  r    rR  rd   r   r   rQ  	parse_objr   r   r   	constructr   rd  r   rh  ignorer5  __fields_set__r   r   _update_from_parsed)rE  r   rx  r&   r{  r   r   r  
validationfinalr   r?   v_keyr   rU  promise_schemareg_namero  rk  rl  gettergetter_result
field_typer  r   r   fieldsr   	field_setexclude_validationrs   s                                  rB   r  registry._fill:  s   ( "$%'
 " ,,.JC#''1E"81SE*005J&!-#s~~e$$+++G #--c2E-=eS-IF%%c*!$!8!8!8!P=@YY"%#%' >G >:Z.
 '*&9&9%*&E#)"~~ej9f !WWXy9F %+D$;F$;M %,!)	V%M %2
!*
j/?? )+J%	 @
 (((
+++"--c2E!&J%ekk>BB%0
=@YY%#%' >G >:Z.
 *$J4Et)L)L )-Z->-E-E-G(HJ%!%ej&7&7&9!:EJ'6+<+<<W !' 1 12B C>N!3?))*:; FM< *M$ $s ",E=!A!AEr ! #c
e )j ))*5 %%3
3F }}""u||U\\&BB**//1 $222 jA.>>2   '0Ci1F?1iC "2!L_5I5I5K!LM&++.@+AB//
EJ'-||~J~tq!'9Idad~FJ+5+;+;+=R+=41a'AQ$!Q$+=JR&+kkmHmdaq7GTQTmEH5((1 # +!!((*V D
 KRHsN   Q4 R 3
R%R%9R*
R*'R08R0R6&R64
R>RRr  r  r  c                    UR                  5        H  u  pEU[        R                  5       ;   a  M  XB;  a  XRU'   XC;  a  XSU'   [        U[        5      (       a   U R                  XRU   X4   5      u  X$'   X4'   Mf  U[        :X  a  Mr  [        [        U5      5      S:X  a  XSU'   M  XSU   :w  d'  [        [        U5      [        X4   5      5      (       a  M  [        X4   [        5      (       a  M  XSU'   M     X#4$ )zRUpdate the final result with the parsed config like converted
values recursively.
z<class 'numpy.ndarray'>)
re   rS  r   r2   rd   r  rR  r3   r   r   )rE  r  r  r  r   r?   s         rB   r  registry._update_from_parsed  s     %**,JCo,,.. #s"c
%&&*-*A*A#;
+'UZ 
"T%[!%>>"c
s#:d5k4
CS+T+T ];;"c
- -. }rL   c                     Sn/ nUR                  5        H/  nU R                  XQ5      (       a  M  UR                  X5/S.5        M1     U(       a	  [        XS9eg)zValidate overrides against a filled config to make sure there are
no references to properties that don't exist and weren't used.z,Invalid override: config value doesn't exist)r   r   r   N)r5  _is_in_configrX   r   )rE  r  r   	error_msgr   override_keys         rB   r  registry._validate_overrides  sW     C	%NN,L$$\::iGH - 'vEE rL   propc                     UR                  S5      n[        U5      nU(       a:  UR                  S5      n[        U[        5      (       a
  XT;   a  XE   nOgU(       a  M:  g)zZCheck whether a nested config property like "section.subsection.key"
is in a given config.rT   r   FT)r   rd   popr2   )rE  r  r   treeobjr   s         rB   r  registry._is_in_config  sQ     zz#6l((1+C#t$$h d rL   r  c                     [        US5      (       d  gUR                  5        Vs/ s H  o"R                  S5      (       d  M  UPM     nn[        U5      (       a  ggs  snf )z{Check whether an object is a "promise", i.e. contains a reference
to a registered function (via a key starting with `"@"`.
r5  Fr4  T)r  r5  r   r_   )rE  r  r   id_keyss       rB   r  registry.is_promise  sK    
 sF##!hhj>jLL,=1j>w<< ?s   AAc                     UR                  5        Vs/ s H  o"R                  S5      (       d  M  UPM     nn[        U5      S:w  a  SU 3n[        USU0/S9eUS   nX   nUSS  U4$ s  snf )Nr4  r!   z?A block can only contain one function registry reference. Got: r   r   r   )r5  r   r_   r   )rE  r  r   r  r   r   r?   s          rB   r  registry.get_constructor
  sz    !hhj>jLL,=1j>w<1WX_W`aG'sUG<L;MNN!*CHEGU## ?s
   A)A)c                     / n0 nUR                  5        HI  u  pEUR                  S5      (       a  M  U[        :X  a  UnM+  U[        R	                  5       ;   a  ME  XSU'   MK     X#4$ )Nr4  )re   r   rR  rS  r   )rE  r  rk  rl  r   r?   s         rB   r  registry.parse_args  s_    ))+JC>>#&&*$ DO2244"'3K & |rL   r  c                   U R                  U5      u  p4U(       d  U R                  X45      (       d  [        $ U R                  X45      nUR	                  5        Vs/ s H  ofR                  S5      (       d  M  UPM     nnUS   [        S40n[        R                  " U5      R                  R                  5        H  n	U	R                  U	R                  :w  a  U	R                  O[        n
U	R                  U	R                  :w  a  U	R                  OSnU	R                  U	R                   :X  a  ["        U
   nX4U[$        '   M  [&        R                  U	R(                  U	R(                  5      nX4X'   M     [*        US'   [-        S0 UD6$ s  snf )zkCreate a schema for a promise dict (referencing a registry function)
by inspecting the function signature.
r4  r   .
__config__)ArgModel)r  rs  r`  rV   r5  r   r3   inspect	signature
parametersr   
annotationemptyr   rZ  kindVAR_POSITIONALr   rQ  rS  rw   rg  r   )rE  r  r{  r  ro  rv  r   r  sig_argsparamr  rZ  spread_annotrw   s                 rB   r  registry.make_promise_schema#  s<    "11#6swwx;;wwx+!hhj>jLL,=1j>$+AJc
#;&&t,77>>@E-2-=-=-L))RUJ',}}'CemmGzzU111'
3.:-D)*&**5::uzzB",!6 A "63(33 ?s   F7Fr}   N)r~   r   r   r   rO  r3   r'  rs  r   rV   r`  r   r   r   r   r   r   r{  r  r   r}  r  r  r  r  r  r  r   r  r  r   r}   rL   rB   r  r    s4                  
 #.$&fd3S#X#6778 Y	
 S>  
c3h  
 #.$&fd3S#X#6778 Y	
 S>   
 #.$&,&fd3S#X#6778,& Y	,&
 S>,& ,& ,& 
tCH~v%	&,& ,&\  #.G)
 /1G)fd3S#X#6778G) YG)
 G) G) G) T#s(^+,G) 
d38nf$%uT#s(^V-C'Dd3PS8nT
G) G)R c3h15c3hHLSRUX > 	F 	FDcN 	F 	F  eDcNF4J.K   	S 	T 	 	 $$sCx. $U38_ $ $ T#s(^ d3ic3h6O0P   594sCx.4.24	i4 4rL   r  )r   r  r   r"   r#   )Tr%  )Mr   r  r  r1  r6   configparserr   r   r   r   r   r   r	   r
   r   dataclassesr   pathlibr   typesr   typingr   r   r   r   r   r   r   r   r   r   r   r   r0   pydantic.v1r   r   r   r   pydantic.v1.fieldsr   pydantic.v1.mainr    ImportErrorpydanticpydantic.mainpydantic.fieldsutilr"   r#   rR  rQ  rS  r{   r4   compiler   r+   r'  r   rd   r   r3   r   r   r   r   r5   r   rT  r^  r`  rg  rj  r  __all__r}   rL   rB   <module>r     s&     	 	 
 
 
 "      +KK-/ 5 
-  /0 ,jj*+i+/ i+X$ uQT uQp	 Xc](;   F FE$sDy/63*F$G FQT F8 	($sCx.&()(DcNF*+( 	(
 4S>6!"(Ve*J e*P# # J s z  ') '& &   c4 c4Lq   +HH,**+s   E, ,FF