o
    0i6                     @   sb   d dl Z G dd de jZG dd deZG dd deZG dd	 d	e jZG d
d de jZdS )    Nc                       s*   e Zd ZdZ fddZdddZ  ZS )_StoreActionzS
    Custom action that allows for `-` or `_` to be passed in for an argument.
    c                    sX   t  j|i | g }| jD ]}|| d|dd  v r&||dd q|| _d S )N_   -)super__init__option_stringsappendreplace)selfargskwargsnew_option_stringsoption_string	__class__ [/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/accelerate/commands/utils.pyr      s   


z_StoreAction.__init__Nc                 C   s2   t || j| t|dst |_|j| j d S )N
nondefault)setattrdesthasattrsetr   addr   parser	namespacevaluesr   r   r   r   __call__!   s   
z_StoreAction.__call__N__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s    
r   c                       s0   e Zd ZdZd fdd	Zd	 fdd	Z  ZS )
_StoreConstActionzR
    Same as `argparse._StoreConstAction` but uses the custom `_StoreAction`.
    NFc              	      s   t  j||d||||d d S )Nr   )r   r   nargsconstdefaultrequiredhelpr   r   )r   r   r   r(   r)   r*   r+   r   r   r   r   -   s   
z_StoreConstAction.__init__c                    s   t  ||| j| d S r   )r   r   r(   r   r   r   r   r   8   s   z_StoreConstAction.__call__NFNr   r    r   r   r   r   r&   (   s    r&   c                       s(   e Zd ZdZ			d fdd	Z  ZS )_StoreTrueActionzV
    Same as `argparse._StoreTrueAction` but uses the custom `_StoreConstAction`.
    NFc                    s   t  j||d|||d d S )NT)r   r   r(   r)   r*   r+   r,   )r   r   r   r)   r*   r+   r   r   r   r   A   s   
z_StoreTrueAction.__init__r-   )r!   r"   r#   r$   r   r%   r   r   r   r   r.   <   s    r.   c                       s    e Zd ZdZ fddZ  ZS )CustomArgumentGroupz
    Custom argument group that allows for the use of `-` or `_` in arguments passed and overrides the help for each
    when applicable.
    c                    s   t |}t|tjrt|d |d |d |d |d }n)t|tjr9t|d |d |d |d |d |d }nt|tjrFtdi |}t |}|S )Nr   r   r)   r*   r+   r(   r   )vars
isinstanceargparser.   r&   r   r   _add_action)r   actionr   r   r   r   r3   T   s$   zCustomArgumentGroup._add_action)r!   r"   r#   r$   r3   r%   r   r   r   r   r/   N   s    r/   c                       s(   e Zd ZdZ fddZdd Z  ZS )CustomArgumentParserz
    Custom argument parser that allows for the use of `-` or `_` in arguments passed and overrides the help for each
    when applicable.
    c                    s<   d|v r|d dkrt |d< nt|d< t j|i | d S )Nr4   
store_true)r.   r   r   add_argument)r   r   r   r   r   r   r7   o   s   z!CustomArgumentParser.add_argumentc                 O   s&   t | g|R i |}| j| |S r   )r/   _action_groupsr	   )r   r   r   groupr   r   r   add_argument_groupx   s   z'CustomArgumentParser.add_argument_group)r!   r"   r#   r$   r7   r:   r%   r   r   r   r   r5   i   s    	r5   )	r2   Actionr   r&   r.   _ArgumentGroupr/   ArgumentParserr5   r   r   r   r   <module>   s   