Ë
    GêñiM  ã                   ó’  — 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mZm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mZmZmZ d dlZ ed	e«      Z ed
e«      Zd„ Zdede
egef   fd„Zdde j@                  e j@                  ddœdeee   z  dz  dedz  dede
g ef   de!dz  de jD                  fd„Z# G d„ de«      Z$y)é    N)ÚArgumentDefaultsHelpFormatterÚArgumentParserÚArgumentTypeError)ÚCallableÚIterable)Úcopy)ÚEnum)Úisclass)ÚPath)ÚAnyÚLiteralÚNewTypeÚUnionÚget_type_hintsÚ	DataClassÚDataClassTypec                 ó�   — t        | t        «      r| S | j                  «       dv ry| j                  «       dv ryt        d| › d�«      ‚)N)ÚyesÚtrueÚtÚyÚ1T)ÚnoÚfalseÚfÚnÚ0FzTruthy value expected: got zJ but expected one of yes/no, true/false, t/f, y/n, 1/0 (case insensitive).)Ú
isinstanceÚboolÚlowerr   )Úvs    ú[/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/transformers/hf_argparser.pyÚstring_to_boolr#   $   sO   € Ü�!”TÔØˆØ‡w�wƒyÐ2Ñ2ØØ	
�‰‹Ð4Ñ	4ØäØ)¨!¨Ð,vÐwó
ð 	
ó    ÚchoicesÚreturnc                 óL   ‡— | D �ci c]  }t        |«      |“Œ c}Šˆfd„S c c}w )aN  
    Creates a mapping function from each choices string representation to the actual value. Used to support multiple
    value types for a single argument.

    Args:
        choices (list): List of choices.

    Returns:
        Callable[[str], Any]: Mapping function from string representation to actual value for each choice.
    c                 ó(   •— ‰j                  | | «      S ©N)Úget)ÚargÚstr_to_choices    €r"   ú<lambda>z+make_choice_type_function.<locals>.<lambda>=   s   ø€ �}×(Ñ(¨¨cÓ2€ r$   )Ústr)r%   Úchoicer,   s     @r"   Úmake_choice_type_functionr0   1   s*   ø€ ð 8?Ö?¨V”S˜“[ &Ñ(Ò?€MÛ2Ð2ùò @s   †!)ÚaliasesÚhelpÚdefaultÚdefault_factoryÚmetadatar1   r2   r3   r4   r5   c                 óX   — |€i }| �| |d<   |�||d<   t        j                  d|||dœ|¤ŽS )a÷  Argument helper enabling a concise syntax to create dataclass fields for parsing with `HfArgumentParser`.

    Example comparing the use of `HfArg` and `dataclasses.field`:
    ```
    @dataclass
    class Args:
        regular_arg: str = dataclasses.field(default="Huggingface", metadata={"aliases": ["--example", "-e"], "help": "This syntax could be better!"})
        hf_arg: str = HfArg(default="Huggingface", aliases=["--example", "-e"], help="What a nice syntax!")
    ```

    Args:
        aliases (Union[str, list[str]], optional):
            Single string or list of strings of aliases to pass on to argparse, e.g. `aliases=["--example", "-e"]`.
            Defaults to None.
        help (str, optional): Help string to pass on to argparse that can be displayed with --help. Defaults to None.
        default (Any, optional):
            Default value for the argument. If not default or default_factory is specified, the argument is required.
            Defaults to dataclasses.MISSING.
        default_factory (Callable[[], Any], optional):
            The default_factory is a 0-argument function called to initialize a field's value. It is useful to provide
            default values for mutable types, e.g. lists: `default_factory=list`. Mutually exclusive with `default=`.
            Defaults to dataclasses.MISSING.
        metadata (dict, optional): Further metadata to pass on to `dataclasses.field`. Defaults to None.

    Returns:
        Field: A `dataclasses.Field` with the desired properties.
    r1   r2   )r5   r3   r4   © )ÚdataclassesÚfield)r1   r2   r3   r4   r5   Úkwargss         r"   ÚHfArgr;   @   sO   € ðH ÐàˆØÐØ%ˆ�ÑØÐØˆ�Ñä×ÑÐk h¸ÐQ`ÑkÐdjÑkÐkr$   c            	       óH  ‡ — e Zd ZU dZee   ed<   ddeee   z  dz  fˆ fd„Zede	de
j                  fd„«       Zdefd	„Z	 	 	 	 	 dd
eedf   fd„Zddeeef   ded
eedf   fd„Zddeej.                  z  ded
eedf   fd„Zddeej.                  z  ded
eedf   fd„Zˆ xZS )ÚHfArgumentParsera  
    This subclass of `argparse.ArgumentParser` uses type hints on dataclasses to generate arguments.

    The class is designed to play well with the native argparse. In particular, you can add more (non-dataclass backed)
    arguments to the parser after initialization and you'll get the output back after parsing as an additional
    namespace. Optional: To create sub argument groups use the `_argument_group_name` attribute in the dataclass.

    Args:
        dataclass_types (`DataClassType` or `Iterable[DataClassType]`, *optional*):
            Dataclass type, or list of dataclass types for which we will "fill" instances with the parsed args.
        kwargs (`dict[str, Any]`, *optional*):
            Passed to `argparse.ArgumentParser()` in the regular way.
    Údataclass_typesNc                 ó  •— |€g }nt        |t        «      s|g}d|vr	t        |d<   t        ‰| �  di |¤Ž t        j                  |«      r|g}t        |«      | _        | j                  D ]  }| j                  |«       Œ y )NÚformatter_classr7   )
r   r   r   ÚsuperÚ__init__r8   Úis_dataclassÚlistr>   Ú_add_dataclass_arguments)Úselfr>   r:   ÚdtypeÚ	__class__s       €r"   rB   zHfArgumentParser.__init__€   s‹   ø€ àÐ"Ø ‰OÜ˜O¬XÔ6Ø.Ð/ˆOð  FÑ*Ü(EˆFÐ$Ñ%Ü‰ÑÑ"˜6Ò"Ü×#Ñ# OÔ4Ø.Ð/ˆOÜ# OÓ4ˆÔØ×)Ñ)ò 	1ˆEØ×)Ñ)¨%Õ0ñ	1r$   Úparserr9   c                 óž  — d|j                   › �g}d|j                   v r.|j                  d|j                   j                  dd«      › �«       |j                  j	                  «       }t        |j                  t        «      rt        d«      ‚|j                  dg «      }t        |t        «      r|g}t        |j                  d|j                  «      }|t        u s,t        t        d«      �rÃt        |t        j                  «      �r¨t        |j                  j                  vr\t!        |j                  j                  «      dk7  s!t        d «      |j                  j                  vrt#        d	|j                   › d
�«      ‚t        d «      |j                  j                  vrx|j                  j                  d   t        u r|j                  j                  d   n|j                  j                  d   |_        t        |j                  d|j                  «      }n—t$        |j                  j                  vr{t        d |j                  j                  d   «      r|j                  j                  d   n|j                  j                  d   |_        t        |j                  d|j                  «      }i }|t&        u s4t        |j                  t        «      r¨t)        |j                  t*        «      rŽ|t&        u r|j                  j                  |d<   n'|j                  D �cg c]  }|j,                  ‘Œ c}|d<   t/        |d   «      |d<   |j0                  t2        j4                  ur|j0                  |d<   �n·d|d<   �n°|j                  t$        u s|j                  t$        d z  k(  rŠt	        |«      }t6        |d<   |j                  t$        u s*|j0                  ��U|j0                  t2        j4                  u�r8|j0                  t2        j4                  u rdn|j0                  }||d<   d|d<   d|d<   nþt9        |«      rƒt)        |t:        «      rs|j                  j                  d   |d<   d|d<   |j<                  t2        j4                  ur|j=                  «       |d<   n’|j0                  t2        j4                  u rvd|d<   np|j                  |d<   |j0                  t2        j4                  ur|j0                  |d<   n5|j<                  t2        j4                  ur|j=                  «       |d<   nd|d<    | j>                  g |¢|¢­i |¤Ž |j0                  du rz|j                  t$        u s|j                  t$        d z  k(  rQd|d<    | j>                  d|j                   › �d|j                   j                  dd«      › �fd|j                   dœ|¤Ž y y y c c}w )Nz--Ú_ú-zpUnresolved type detected, which should have been done with the help of `typing.get_type_hints` method by defaultr1   Ú
__origin__Ú	UnionTypeé   z¦Only `Union[X, NoneType]` (i.e., `Optional[X]`) is allowed for `Union` because the argument parser only supports one type per argument. Problem encountered in field 'z'.é   r   r%   Útyper3   TÚrequiredFú?ÚnargsÚconstú+z--no_z--no-Ústore_false)ÚactionÚdest) ÚnameÚappendÚreplacer5   r   r   rQ   r.   ÚRuntimeErrorÚpopÚgetattrr   ÚhasattrÚtypesrN   Ú__args__ÚlenÚ
ValueErrorr   r   Ú
issubclassr	   Úvaluer0   r3   r8   ÚMISSINGr#   r
   rD   r4   Úadd_argument)	rI   r9   Úlong_optionsr:   r1   Úorigin_typeÚbool_kwargsÚxr3   s	            r"   Ú_parse_dataclass_fieldz'HfArgumentParser._parse_dataclass_field‘   s×  € ð ˜UŸZ™Z˜LÐ)Ð*ˆØ�%—*‘*ÑØ×Ñ " U§Z¡Z×%7Ñ%7¸¸SÓ%AÐ$BÐ CÔDà—‘×$Ñ$Ó&ˆô �e—j‘j¤#Ô&Üð<óð ð
 —*‘*˜Y¨Ó+ˆÜ�gœsÔ#Ø�iˆGä˜eŸj™j¨,¸¿
¹
ÓCˆØœ%Ñ¤G¬E°;Õ$?ÄJÈ{Ô\a×\kÑ\kÕDlÜ˜%Ÿ*™*×-Ñ-Ñ-Ü�E—J‘J×'Ñ'Ó(¨AÒ-´°d³À5Ç:Á:×CVÑCVÑ1Vä ð6à6;·j±j°\ÀðEóð ô
 �D‹z §¡×!4Ñ!4Ñ4à7<·z±z×7JÑ7JÈ1Ñ7MÔQTÑ7T˜UŸZ™Z×0Ñ0°Ò3ÐZ_×ZdÑZd×ZmÑZmÐnoÑZp�”
Ü% e§j¡j°,ÀÇ
Á
ÓK‘Ü˜UŸZ™Z×0Ñ0Ñ0ô /9¸¸u¿z¹z×?RÑ?RÐSTÑ?UÔ.V�E—J‘J×'Ñ'¨Ò*Ð\a×\fÑ\f×\oÑ\oÐpqÑ\rð ”
ô & e§j¡j°,ÀÇ
Á
ÓK�ð ˆØœ'Ñ!¤j°·±¼TÔ&BÄzÐRW×R\ÑR\Ô^bÔGcØœgÑ%Ø$)§J¡J×$7Ñ$7��yÒ!à6;·j±jÖ$A° Q§W£WÒ$A��yÑ!ä6°v¸iÑ7HÓIˆF�6‰Nà�}‰}¤K×$7Ñ$7Ñ7Ø$)§M¡M��yÓ!à%)��zÓ"Ø�Z‰Zœ4Ñ 5§:¡:´¸±Ò#<ô ˜v›,ˆKô ,ˆF�6‰NØ�z‰zœTÑ! e§m¡mÑ&?ÀEÇMÁMÔYd×YlÑYlÒDlà#(§=¡=´K×4GÑ4GÑ#G™%ÈUÏ]É]�à$+��yÑ!à"%��w‘à"&��w’Ü�[Ô!¤j°¼dÔ&CØ"ŸZ™Z×0Ñ0°Ñ3ˆF�6‰NØ!ˆF�7‰OØ×$Ñ$¬K×,?Ñ,?Ñ?Ø$)×$9Ñ$9Ó$;��yÒ!Ø—‘¤+×"5Ñ"5Ñ5Ø%)��zÒ"à"ŸZ™ZˆF�6‰NØ�}‰}¤K×$7Ñ$7Ñ7Ø$)§M¡M��yÒ!Ø×&Ñ&¬k×.AÑ.AÑAØ$)×$9Ñ$9Ó$;��yÒ!à%)��zÑ"Øˆ×ÑÐ>˜\Ð>¨GÒ>°vÒ>ð �=‰=˜DÑ  e§j¡j´DÑ&8¸E¿J¹JÌ$ÐQUÉ+Ò<UØ%*ˆK˜	Ñ"ØˆF×ÑØ˜Ÿ
™
�|Ð$Ø˜Ÿ
™
×*Ñ*¨3°Ó4Ð5Ð6ðð %Ø—Z‘Zñ	ð
 óð =VÐ ùò[ %Bs   ÌW
rG   c                 óB  — t        |d«      r| j                  |j                  «      }n| }	 t        |«      }t        j                  |«      D ]5  }|j                  sŒ||j                     |_
        | j                  ||«       Œ7 y # t        $ r t        d|› d�«      ‚w xY w)NÚ_argument_group_namezType resolution failed for zž. Try declaring the class in global scope or removing line of `from __future__ import annotations` which opts in Postponed Evaluation of Annotations (PEP 563))r`   Úadd_argument_groupro   r   Ú	NameErrorr]   r8   ÚfieldsÚinitrZ   rQ   rm   )rF   rG   rI   Ú
type_hintsr9   s        r"   rE   z)HfArgumentParser._add_dataclass_argumentsû   s¬   € Ü�5Ð0Ô1Ø×,Ñ,¨U×-GÑ-GÓH‰FàˆFð	Ü*8¸Ó*?ˆJô !×'Ñ'¨Ó.ò 	7ˆEØ—:’:ØØ# E§J¡JÑ/ˆEŒJØ×'Ñ'¨°Õ6ñ		7øô ò 	ÜØ-¨e¨Wð 56ð 6óð ð	ús   ¬B ÂBr&   .c                 ó   — |s|s|�rst        t        j                  «      �rYg }|r|j                  t	        |«      «       nU|rSt        t        j                  «      r:|j                  t	        t        j                  d   «      j                  d«      «       |r‹t        «       }|j                  |t        d¬«       |j                  |¬«      \  }}t        |«      j                  |j                  d«      d«      }	|	r(|j                  |	D �
cg c]  }
t	        |
«      ‘Œ c}
«       g }|D ]4  }|j                  «       sŒ||j                  «       j!                  «       z  }Œ6 |�||z   n|t        j                  dd z   }| j                  |¬«      \  }}g }| j"                  D ]˜  }t%        j&                  |«      D �ch c]  }|j(                  sŒ|j*                  ’Œ }}t        |«      j-                  «       D ��ci c]  \  }}||v sŒ||“Œ }}}|D ]  }t/        ||«       Œ  |d
i |¤Ž}|j                  |«       Œš t        |j0                  «      dkD  r|j                  |«       |rg |¢|‘­S |rt3        d	|› �«      ‚g |¢­S c c}
w c c}w c c}}w )a%  
        Parse command-line args into instances of the specified dataclass types.

        This relies on argparse's `ArgumentParser.parse_known_args`. See the doc at:
        docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args

        Args:
            args:
                List of strings to parse. The default is taken from sys.argv. (same as argparse.ArgumentParser)
            return_remaining_strings:
                If true, also return a list of remaining argument strings.
            look_for_args_file:
                If true, will look for a ".args" file with the same base name as the entry point script for this
                process, and will append its potential content to the command line args.
            args_filename:
                If not None, will uses this file instead of the ".args" file specified in the previous argument.
            args_file_flag:
                If not None, will look for a file in the command-line args specified with this flag. The flag can be
                specified multiple times and precedence is determined by the order (last one wins).

        Returns:
            Tuple consisting of:

                - the dataclass instances in the same order as they were passed to the initializer.abspath
                - if applicable, an additional namespace for more (non-dataclass backed) arguments added to the parser
                  after initialization.
                - The potential list of remaining argument strings. (same as argparse.ArgumentParser.parse_known_args)
        r   z.argsr[   )rQ   rX   )ÚargsrL   NrP   z?Some specified arguments are not used by the HfArgumentParser: r7   )rc   ÚsysÚargvr[   r   Úwith_suffixr   rh   r.   Úparse_known_argsÚvarsr*   ÚlstripÚextendÚexistsÚ	read_textÚsplitr>   r8   rr   rs   rZ   ÚitemsÚdelattrÚ__dict__rd   )rF   rv   Úreturn_remaining_stringsÚlook_for_args_fileÚargs_filenameÚargs_file_flagÚ
args_filesÚargs_file_parserÚcfgÚcmd_args_file_pathsÚpÚ	file_argsÚ	args_fileÚ	namespaceÚremaining_argsÚoutputsrG   r   ÚkeysÚkr!   ÚinputsÚobjs                          r"   Úparse_args_into_dataclassesz,HfArgumentParser.parse_args_into_dataclasses  s`  € ñJ ™]Ò/AÄcÌ#Ï(É(ÅmØˆJáØ×!Ñ!¤$ }Ó"5Õ6Ù#¬¬C¯H©H¬Ø×!Ñ!¤$¤s§x¡x°¡{Ó"3×"?Ñ"?ÀÓ"HÔIñ ä#1Ó#3Ð Ø ×-Ñ-¨nÄ3ÈxÐ-ÔXð -×=Ñ=À4Ð=ÓH‘	��TÜ&*¨3£i§m¡m°N×4IÑ4IÈ#Ó4NÐPTÓ&UÐ#á&Ø×%Ñ%Ð8KÖ&L°1¤t¨A¥wÒ&LÔMàˆIØ'ò ?�	Ø×#Ñ#Õ%Ø ×!4Ñ!4Ó!6×!<Ñ!<Ó!>Ñ>‘Ið?ð (,Ð'7�9˜tÒ#¸YÌÏÉÐRSÐRTÈÑ=UˆDØ$(×$9Ñ$9¸tÐ$9Ó$DÑ!ˆ	�>ØˆØ×)Ñ)ò 	 ˆEÜ$/×$6Ñ$6°uÓ$=ÖH˜qÀÇÃ�A—F“FÐHˆDÐHÜ'+¨I£×'<Ñ'<Ó'>×L™t˜q !À!ÀtÂ)�a˜‘dÐLˆFÑLØò &�Ü˜	 1Õ%ð&á‘/˜&‘/ˆCØ�N‰N˜3Õð	 ô ˆy×!Ñ!Ó" QÒ&à�N‰N˜9Ô%Ù#Ø-�WÐ-˜nÑ-Ð-áÜ Ð#bÐcqÐbrÐ!sÓtÐtà�W‘;Ðùò9 'Mùò IùÛLs   Ä
J Æ8JÇ
JÇ6J
ÈJ
rv   Úallow_extra_keysc                 óî  — t        |j                  «       «      }g }| j                  D ]›  }t        j                  |«      D �ch c]  }|j
                  sŒ|j                  ’Œ }}|j                  «       D ��	ci c]  \  }}	||v sŒ||	“Œ }
}}	|j                  |
j                  «       «        |di |
¤Ž}|j                  |«       Œ� |s|rt        dt        |«      › �«      ‚t        |«      S c c}w c c}	}w )a<  
        Alternative helper method that does not use `argparse` at all, instead uses a dict and populating the dataclass
        types.

        Args:
            args (`dict`):
                dict containing config values
            allow_extra_keys (`bool`, *optional*, defaults to `False`):
                Defaults to False. If False, will raise an exception if the dict contains keys that are not parsed.

        Returns:
            Tuple consisting of:

                - the dataclass instances in the same order as they were passed to the initializer.
        z0Some keys are not used by the HfArgumentParser: r7   )Úsetr’   r>   r8   rr   rs   rZ   r�   Údifference_updater[   rd   ÚsortedÚtuple)rF   rv   r—   Úunused_keysr‘   rG   r   r’   r“   r!   r”   r•   s               r"   Ú
parse_dictzHfArgumentParser.parse_dictf  sÝ   € ô  ˜$Ÿ)™)›+Ó&ˆØˆØ×)Ñ)ò 	 ˆEÜ$/×$6Ñ$6°uÓ$=ÖH˜qÀÇÃ�A—F“FÐHˆDÐHØ'+§z¡z£|×A™t˜q !°q¸D²y�a˜‘dÐAˆFÑAØ×)Ñ)¨&¯+©+«-Ô8Ù‘/˜&‘/ˆCØ�N‰N˜3Õð	 ñ  ¡KÜÐOÔPVÐWbÓPcÐOdÐeÓfÐfÜ�W‹~Ðùò IùÛAs   ÁC,ÁC,Á7C1ÂC1Ú	json_filec                 óÚ   — t        t        |«      d¬«      5 }t        j                  |j	                  «       «      }ddd«       | j                  |¬«      }t        |«      S # 1 sw Y   Œ'xY w)at  
        Alternative helper method that does not use `argparse` at all, instead loading a json file and populating the
        dataclass types.

        Args:
            json_file (`str` or `os.PathLike`):
                File name of the json file to parse
            allow_extra_keys (`bool`, *optional*, defaults to `False`):
                Defaults to False. If False, will raise an exception if the json file contains keys that are not
                parsed.

        Returns:
            Tuple consisting of:

                - the dataclass instances in the same order as they were passed to the initializer.
        zutf-8)ÚencodingN©r—   )Úopenr   ÚjsonÚloadsÚreadrž   rœ   )rF   rŸ   r—   Úopen_json_fileÚdatar‘   s         r"   Úparse_json_filez HfArgumentParser.parse_json_file‚  s]   € ô" ”$�y“/¨GÔ4ð 	5¸Ü—:‘:˜n×1Ñ1Ó3Ó4ˆD÷	5à—/‘/ $Ð9I�/ÓJˆÜ�W‹~Ð÷	5ð 	5ús   —$A!Á!A*Ú	yaml_filec                 ó’   — | j                  t        j                  t        |«      j	                  «       «      |¬«      }t        |«      S )at  
        Alternative helper method that does not use `argparse` at all, instead loading a yaml file and populating the
        dataclass types.

        Args:
            yaml_file (`str` or `os.PathLike`):
                File name of the yaml file to parse
            allow_extra_keys (`bool`, *optional*, defaults to `False`):
                Defaults to False. If False, will raise an exception if the json file contains keys that are not
                parsed.

        Returns:
            Tuple consisting of:

                - the dataclass instances in the same order as they were passed to the initializer.
        r¢   )rž   ÚyamlÚ	safe_loadr   r   rœ   )rF   rª   r—   r‘   s       r"   Úparse_yaml_filez HfArgumentParser.parse_yaml_file˜  s7   € ð" —/‘/¤$§.¡.´°i³×1JÑ1JÓ1LÓ"MÐ`p�/ÓqˆÜ�W‹~Ðr$   r)   )NFTNN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__rB   Ústaticmethodr   r8   ÚFieldrm   rE   rœ   r   r–   Údictr.   r   r   rž   ÚosÚPathLiker©   r®   Ú__classcell__)rH   s   @r"   r=   r=   o   s%  ø… ñð ˜mÑ,Ó,ñ1¨¸ÀÑ8OÑ(OÐRVÑ(Võ 1ð" ðg ~ð g¸k×>OÑ>Oò gó ðgðR7¨mó 7ð. Ø!&ØØØñTð 
ˆy˜#ˆ~Ñ	óTñl˜t C¨ H™~ð Àð ÐRWÐXaÐcfÐXfÑRgó ñ8¨¨r¯{©{Ñ):ð Èdð Ð_dÐenÐpsÐesÑ_tó ñ,¨¨r¯{©{Ñ):ð Èdð Ð_dÐenÐpsÐesÑ_t÷ r$   r=   )%r8   r¤   r·   rw   ra   Úargparser   r   r   Úcollections.abcr   r   r   Úenumr	   Úinspectr
   Úpathlibr   Útypingr   r   r   r   r   r¬   r   r   r#   rD   r.   r0   rg   r¶   rµ   r;   r=   r7   r$   r"   ú<module>rÀ      s  ðó Û Û 	Û 
Û ß UÑ Uß .Ý Ý Ý Ý ß ?Õ ?ã ñ �K Ó%€	Ù˜¨Ó-€ò

ð3 tð 3°¸#¸À¸Ñ0Dó 3ð" '+ØØ×&Ñ&Ø)4×)<Ñ)<Ø ò,là�4˜‘9‰_˜tÑ#ð,lð �‰*ð,lð ð	,lð
 ˜b #˜gÑ&ð,lð �T‰kð,lð ×Ñó,lô^{�~õ {r$   