o
    Pεi                     @   s  U 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 d dlmZ	 d dlm
Z
mZmZmZmZ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mZmZmZmZ edZd	Zeed
< G dd dee Zeee ef Z e Z!e ed< dede"fddZ#dede"fddZ$dede"fddZ%dede"fddZ&de"fddZ'dedefddZ(de
fddZ)de"fd d!Z*d"d# Z+d$d% Z,dedefd&d'Z-ded(edefd)d*Z.ded(edefd+d,Z/dee0e1e2e"f d(edee0e1e2e"f fd-d.Z3ded(edefd/d0Z4d1d2 Z5d3d4 Z6d5d6 Z7d7d8 Z8eG d9d: d:Z9d;d< Z:	=	=	>dNd?d@Z;eG dAdB dBe9eZ<	>					>		CdOdDe"dEe2dFe=dGe1dHe1dIe"dJe2dKe"ddfdLdMZ>dS )P    N)MutableMapping)MISSING)Fieldasdict	dataclassfieldsis_dataclassreplace)Path)pprint)	AnyDictGenericListOptionalTypeTypeVarUnionget_type_hintsT???r   c                   @   s   e Zd ZdS )
_NoDefaultN)__name__
__module____qualname__ r   r   A/home/ubuntu/.local/lib/python3.10/site-packages/coqpit/coqpit.pyr      s    r   
no_defaultarg_typereturnc              	   C   s0   zt |  ttttfW S  ttfy   Y dS w )zCheck if the input type is one of `int, float, str, bool`.

    Args:
        arg_type (typing.Any): input type to check.

    Returns:
        bool: True if input type is one of `int, float, str, bool`.
    F)
isinstanceintfloatstrboolAttributeError	TypeErrorr   r   r   r   is_primitive_type   s
   	r(   c                 C   s<   z| t u p| tu p| jt u p| jtu W S  ty   Y dS w )zCheck if the input type is `list`

    Args:
        arg_type (typing.Any): input type.

    Returns:
        bool: True if input type is `list`
    F)listr   
__origin__r%   r'   r   r   r   is_list(   s
   	&r+   c                 C   s2   z| t u p| tu p| jt u W S  ty   Y dS w )zCheck if the input type is `dict`

    Args:
        arg_type (typing.Any): input type.

    Returns:
        bool: True if input type is `dict`
    F)dictr   r*   r%   r'   r   r   r   is_dict7   s
   	r-   c                 C   s$   zt | jtW S  ty   Y dS w )zCheck if the input type is `Union`.

    Args:
        arg_type (typing.Any): input type.

    Returns:
        bool: True if input type is `Union`
    F)safe_issubclassr*   r   r%   r'   r   r   r   is_unionF   s
   	r/   c                 C   s,   zt | |}W |S  ty   | |u  Y S w )zCheck if the input type is a subclass of the given class.

    Args:
        cls (type): input type.
        classinfo (type): parent class.

    Returns:
        bool: True if the input type is a subclass of the given class
    )
issubclass	Exception)cls	classinforr   r   r   r.   U   s   
r.   objc                 C   s&   t | tr	t| S tdt| j )NzCan't encode object of type )r    r
   r#   r&   typer   )r5   r   r   r   _coqpit_json_defaultg   s   
r7   xc                 C   s0   | j ttfvr
| j S | jttfvr|  S | j S )zReturn the default value of the input Field.

    Args:
        x (Field): input Field.

    Returns:
        object: default value of the input Field.
    )defaultr   _MISSINGdefault_factoryr8   r   r   r   _default_valuem   s
   	r=   c                 C   s   t dt| j dv S )zCheck if the input field is optional.

    Args:
        field (Field): input Field to check.

    Returns:
        bool: True if the input field is optional.
    N__args__)r6   getattr)fieldr   r   r   _is_optional_field}   s   
rA   c                 C   s>   i }| j jD ]}|tkr n|t| q|t|  |S )zCustom `get_type_hints` dealing with https://github.com/python/typing/issues/737

    Returns:
        [dataclass]: dataclass to get the type hints of its fields.
    )	__class__	__bases__objectupdatemy_get_type_hintsr   )r2   r_dictbaser   r   r   rF      s   rF   c                 C   s   t | tr	t| S t | trdd |  D S t | tr#dd | D S t | ts/tt| tr3| 	 S t | trBt| trB| 	| S | S )zPick the right serialization for the datatype of the given input.

    Args:
        x (object): input object.

    Returns:
        object: serialized object.
    c                 S   s   i | ]	\}}|t |qS r   
_serialize).0kvr   r   r   
<dictcomp>   s    z_serialize.<locals>.<dictcomp>c                 S   s   g | ]}t |qS r   rI   rK   xir   r   r   
<listcomp>   s    z_serialize.<locals>.<listcomp>)
r    r
   r#   r,   itemsr)   Serializabler0   r6   	serializer<   r   r   r   rJ      s   
	


rJ   c                 C   s>   i }|   D ]\}}|du rd||< qt|t|||< q|S )zDeserialize dict.

    Args:
        x (Dict): value to deserialized.

    Returns:
        Dict: deserialized dictionary.
    N)rR   _deserializer6   )r8   out_dictrL   rM   r   r   r   _deserialize_dict   s   	
rW   
field_typec                    sz   d}t |dr|jr|j}nt |dr|jr|j}|r;t|dkr%td|d  t tr2t|   fdd| D S | S )	a  Deserialize values for List typed fields.

    Args:
        x (List): value to be deserialized
        field_type (Type): field type.

    Raises:
        ValueError: Coqpit does not support multi type-hinted lists.

    Returns:
        [List]: deserialized list.
    Nr>   __parameters__   5 [!] Coqpit does not support multi-type hinted 'List'r   c                    s   g | ]}t | qS r   )rU   rO   	field_argr   r   rQ      s    z%_deserialize_list.<locals>.<listcomp>)hasattrr>   rY   len
ValueErrorr    r   r6   )r8   rX   
field_argsr   r\   r   _deserialize_list   s   
rb   c              	   C   s4   |j D ]}z	t| |} W  | S  ty   Y qw | S )zDeserialize values for Union typed fields

    Args:
        x (Any): value to be deserialized.
        field_type (Type): field type.

    Returns:
        [Any]: desrialized value.
    )r>   rU   r`   )r8   rX   argr   r   r   _deserialize_union   s   


rd   c                 C   sL   t | ttfr	| S t | ttfr$| tdks| tdkr| S || } | S dS )au  Deserialize python primitive types (float, int, str, bool).
    It handles `inf` values exclusively and keeps them float against int fields since int does not support inf values.

    Args:
        x (Union[int, float, str, bool]): value to be deserialized.
        field_type (Type): field type.

    Returns:
        Union[int, float, str, bool]: deserialized value.
    infz-infN)r    r#   r$   r!   r"   r8   rX   r   r   r   _deserialize_primitive_types   s   rg   c                 C   sz   t |rt| S t|rt| |S t|rt| |S t|tr$|| S t	|r-t
| |S tdt|  d|  d| d)a  Pick the right desrialization for the given object and the corresponding field type.

    Args:
        x (object): object to be deserialized.
        field_type (type): expected type after deserialization.

    Returns:
        object: deserialized object

     [!] 'z' value type of 'z' does not match 'z' field type.)r-   rW   r+   rb   r/   rd   r0   rS   deserialize_immutabler(   rg   r`   r6   rf   r   r   r   rU     s   




 rU   c                 C   sH   dd }| d\}}}| r|nt}||rt| |||S | ||S )Nc                 S   s   t | t||S N)operatorsetitemr!   )r5   attrvalr   r   r   _setitem(  s   zrsetattr.<locals>._setitem.)
rpartition	isnumericsetattrrgetattr)r5   rm   rn   ro   pre_postsetfuncr   r   r   rsetattr'  s    ry   c                    s2   fdd  fdd}t || g|d S )Nc                    s   t j| t|g R  S rj   )rk   getitemr!   r5   rm   argsr   r   _getitem3  s   zrgetattr.<locals>._getitemc                    s"   |  r nt}|| |gR  S rj   )rr   r?   )r5   rm   getfuncr~   r}   r   r   _getattr6  s   zrgetattr.<locals>._getattrrp   	functoolsreducesplit)r5   rm   r}   r   r   r   r   rt   2  s   rt   c                 C   s2   | d\}}}t|rt| |||S | ||S )Nrp   )rq   rk   rl   rgetitem)r5   rm   rn   ru   rv   rw   r   r   r   rsetitem>  s   "r   c                    s$    fdd}t || g|d S )Nc                    s$   t j| | rt|n|g R  S rj   )rk   rz   rr   r!   r{   r|   r   r   r~   E  s   $zrgetitem.<locals>._getitemrp   r   )r5   rm   r}   r~   r   r|   r   r   D  s   r   c                   @   sl   e Zd ZdZdd Zdd Zdd Zdefd	d
ZdefddZ	dedd fddZ
ededd fddZdS )rS   z8Gives serialization ability to any inheriting dataclass.c                 C   s8   |    | j D ]\}}|tu rtd| dq	d S )Nz'__init__ missing 1 required argument: '')_validate_contracts__dict__rR   r   r&   )selfkeyvaluer   r   r   __post_init__O  s   zSerializable.__post_init__c                 C   s   t | }|D ]8}t| |j}|d u rt|st|j d|jdd }|d ur>|d ur>||s>td|j d| jj	 qd S )Nz is not optionalcontractzbreak the contract for z, )
r   r?   namerA   r&   metadatagetr`   rB   r   )r   dataclass_fieldsr@   r   r   r   r   r   r   U  s   z Serializable._validate_contractsc              	   C   s4   |    | | jtt|  krtddS )z9validate if object can serialize / deserialize correctly.z)could not be deserialized with same valueN)r   rB   deserializejsonloadsdumpsrT   r`   r   r   r   r   validatef  s   zSerializable.validater   c                 C   s,   t | }i }|D ]}t| |j||j< q|S )z&Transform serializable object to dict.)r   r?   r   )r   
cls_fieldso	cls_fieldr   r   r   to_dictn  s
   zSerializable.to_dictc                 C   sH   t | stdt| }i }|D ]}t| |j}t|}|||j< q|S )z8Serialize object to be json serializable representation.z!need to be decorated as dataclass)r   r&   r   r?   r   rJ   )r   r   r   r@   r   r   r   r   rT   v  s   zSerializable.serializedatac                 C   s   t |tst | }i }t| D ]P}|j|vr4|jt| v r+t| |j ||j< qtd|j d||jt|}|du rG|||j< q|t	krWtd|j d| j
 t||j}|||j< q| D ]
\}}t| || qg| S )zParse input dictionary and desrialize its fields to a dataclass.

        Returns:
            self: deserialized `self`.
         [!] Missing required field ""Nz$deserialized with unknown value for  in )r    r,   r`   copyr   r   varsr   r=   r   r   rU   r6   rR   rs   )r   r   init_kwargsr@   r   rL   rM   r   r   r   r     s*   


zSerializable.deserializec                 C   s   t |tst | }i }t| D ]`}|j|vrD|jt| v r+t| |j ||j< qt|}|tt	fvr;|||j< qtd|j d|
|jt|}|du rW|||j< q|tkrgtd|j d| j t||j}|||j< q| di |S )zParse input dictionary and desrialize its fields to a dataclass.

        Returns:
            Newly created deserialized object.
        r   r   Nz$Deserialized with unknown value for r   r   )r    r,   r`   r   r   r   r   r=   r   r:   r   r   rU   r6   )r2   r   r   r@   default_valuer   r   r   r   ri     s.   



z"Serializable.deserialize_immutableN)r   r   r   __doc__r   r   r   r,   r   rT   r   classmethodri   r   r   r   r   rS   K  s    rS   c                 C   s*   z| j d }W |S  ty   d}Y |S w )Nhelp )r   KeyError)r@   
field_helpr   r   r   	_get_help  s   r   r   Fc	                 C   s,  d}	d }
|rd}	|}
n|d t fvrd}	| }
|	s"t|s"t|s"| S |dkr(|n| d| }|dkr5|n| d| }t|rV| jd| ||rNt|nd tjd | S t|rt|drrt	|j
d	krl|sltd
|j
d }ntdt|r~|r~| S |	r|tu rt|s|std| jd| d|d| d | S t|
D ]\}}t| t||||d| d| |d	} q| S t|r|std| S t|tr|
j| |||dS t| trdd }| jd| ||d| dd | S t|r	| jd| ||d| d | S |std| d| S )NFTr   rp   z - z--)destr9   r6   r>   rZ   r[   r   z- [!] Coqpit does not support un-hinted 'List'zI [!] Empty list with non primitive inner type is currently not supported.*zCoqpit Field: )nargsr6   r   )r   help_prefix
arg_prefixrelaxed_parserzX [!] Parsing `Union` field from argparse is not yet implemented. Please create an issue.)r   r   r   c                 S   s    | dvrt d|  d| dkS )N)truefalsezD [!] Value for boolean field must be either "true" or "false". Got "z".r   )r`   r<   r   r   r   
parse_bool%  s   z"_init_argparse.<locals>.parse_boolz
true/false)r6   r9   r   metavar)r9   r6   r   rh   z;' is not supported by arg_parser. Please file a bug report.)r:   r(   r+   r-   add_argumentr   r   r   r^   r_   r>   r`   r)   NotImplementedError	enumerate_init_argparser#   r/   r0   rS   init_argparser    r$   )parser
field_namerX   field_defaultfield_default_factoryr   r   r   r   has_defaultr9   list_field_typeidxfvr   r   r   r   r     s   O
7-

	r   c                       s$  e Zd ZdZdZdd Zdd Zdd Zd	d
 Zde	de
fddZde	fddZde	fddZdd Zde	f fddZde	fddZdKde	de
fddZdd Zd ed ed  f fd!d"Zd#d$ Zde	d%efd&d'Zd(d) ZdLd*ed%dfd+d,ZdMd-d.Zd%efd/d0Zd1ed%dfd2d3Zed4e d1ed%d fd5d6Z!d%e	fd7d8Z"d9e	d%dfd:d;Z#d9e	d%dfd<d=Z$e	>dNd?e%ee&j'ee	 f  d@e	d%d fdAdBZ(	>dNd?e%ee&j'ee	 f  d@e	d%dfdCdDZ)		>	dOd?e%ee&j'ee	 f  d@e	d%ee	 fdEdFZ*		>	G	dPdHe%e&j+ d%e&j+fdIdJZ,  Z-S )QCoqpita\  Coqpit base class to be inherited by any Coqpit dataclasses.
    It overrides Python `dict` interface and provides `dict` compatible API.
    It also enables serializing/deserializing a dataclass to/from a json file, plus some semi-dynamic type and value check.
    Note that it does not support all datatypes and likely to fail in some cases.
    Fc                 C   s   dt | v o| jS )zCheck if Coqpit is initialized. Useful to prevent running some aux functions
        at the initialization when no attribute has been defined._initialized)r   r   r   r   r   r   _is_initializedM  s   zCoqpit._is_initializedc                 C   s*   d| _ z|   W d S  ty   Y d S w )NT)r   check_valuesr%   r   r   r   r   r   R  s   zCoqpit.__post_init__c                 C      t t| S rj   )iterr   r   r   r   r   __iter__[     zCoqpit.__iter__c                 C   r   rj   )r_   r   r   r   r   r   __len__^  r   zCoqpit.__len__rc   r   c                 C   s   t | || d S rj   )rs   r   rc   r   r   r   r   __setitem__a  s   zCoqpit.__setitem__c                 C   s
   | j | S )z'Access class attributes with ``[arg]``.)r   r   rc   r   r   r   __getitem__d     
zCoqpit.__getitem__c                 C   s   t | | d S rj   )delattrr   r   r   r   __delitem__h     zCoqpit.__delitem__c                 C   s   |S rj   r   )r   r   r   r   r   _keytransformk     zCoqpit._keytransformc                    s2   t  |}t|tr|dkrtd| d|S )z:Check if the mandatory field is defined when accessing it.r   z [!] MISSING field z must be defined.)super__getattribute__r    r#   r%   r   rB   r   r   r   p  s   zCoqpit.__getattribute__c                 C   s   ||   v S rj   )r   r   r   r   r   __contains__w  r   zCoqpit.__contains__Nr   r9   c                 C   s   |  |rt| | S |S rj   )hasr   )r   r   r9   r   r   r   r   z  s   
z
Coqpit.getc                 C   s   t |  S rj   )r   rR   r   r   r   r   rR     r   zCoqpit.itemscoqpitsc                    s8    fdd}t |tr|D ]}|| qdS || dS )a  Merge a coqpit instance or a list of coqpit instances to self.
        Note that it does not pass the fields and overrides attributes with
        the last Coqpit instance in the given List.
        TODO: find a way to merge instances with all the class internals.

        Args:
            coqpits (Union[Coqpit, List[Coqpit]]): coqpit instance or list of instances to be merged.
        c                    s.    j | j   j| j  j| j d S rj   )r   rE   __annotations____dataclass_fields__)coqpitr   r   r   _merge  s   zCoqpit.merge.<locals>._mergeN)r    r)   )r   r   r   r   r   r   r   merge  s   


zCoqpit.mergec                 C   s   d S rj   r   r   r   r   r   r     r   zCoqpit.check_valuesr   c                 C   s   |t | v S rj   )r   r   r   r   r   r     r   z
Coqpit.hasc                 C   s   t | S rj   )r	   r   r   r   r   r     s   zCoqpit.copynewc                 C   sL   |  D ]\}}|rt| || qt| |rt| || qtd| dS )zUpdate Coqpit fields by the input ```dict```.

        Args:
            new (dict): dictionary with new values.
            allow_new (bool, optional): allow new fields to add. Defaults to False.
        z [!] No key - N)rR   rs   r^   r   )r   r   	allow_newr   r   r   r   r   rE     s   
zCoqpit.updatec                 C   s   t t|  dS )z Print Coqpit fields in a format.N)r   r   r   r   r   r   r     s   zCoqpit.pprintc                 C   s   |   S rj   )rT   r   r   r   r   r     s   zCoqpit.to_dictr   c                 C   s   |  |} d S rj   )r   )r   r   r   r   r   	from_dict  r   zCoqpit.from_dictr2   c                 C   s
   |  |S rj   )ri   )r2   r   r   r   r   new_from_dict  r   zCoqpit.new_from_dictc                 C   s   t jt| dtdS )z%Returns a JSON string representation.   )indentr9   )r   r   r   r7   r   r   r   r   to_json  s   zCoqpit.to_json	file_namec                 C   sH   t |ddd}tjt| |dd W d   dS 1 sw   Y  dS )znSave Coqpit to a json file.

        Args:
            file_name (str): path to the output json file.
        wutf8encodingr   )r   N)openr   dumpr   )r   r   fr   r   r   	save_json  s   "zCoqpit.save_jsonc                 C   sV   t |ddd}| }t|}W d   n1 sw   Y  | |} |   dS )a  Load a json file and update matching config fields with type checking.
        Non-matching parameters in the json file are ignored.

        Args:
            file_name (str): path to the json file.

        Returns:
            Coqpit: new Coqpit with updated config fields.
        r4   r   r   N)r   readr   r   r   r   )r   r   r   	input_str	dump_dictr   r   r   	load_json  s   

zCoqpit.load_jsonr   r}   r   c                 C   s  |s| j | |d}| }t|tr| j | |d}||}i }t| }|D ]9}d}d}|jtur4|jnd}	|jtur>|jnd}
|	rGd}|	}n|
rNd}|
 }|r_t|j	rZt
|j	r_|||j< q&t|}| D ]\}}|| dr|t| dd }t||| qh| di |S )a  Create a new Coqpit instance from argparse input.

        Args:
            args (namespace or list of str, optional): parsed argparse.Namespace or list of command line parameters. If unspecified will use a newly created parser with ```init_argparse()```.
            arg_prefix: prefix to add to CLI parameters. Gets forwarded to ```init_argparse``` when ```args``` is not passed.
        r   FNTrp   r   )r   
parse_argsr    r)   r   r9   r:   r;   r(   r6   r+   r   r   rR   
startswithr_   r   )r2   r}   r   r   args_with_lists_processedclass_fieldsr@   r   r9   r   r   	args_dictrL   rM   r   r   r   init_from_argparse  s8   



zCoqpit.init_from_argparsec                 C   s   |s| j |d}| }t|tr| j |d}||}t|}| D ]<\}}|| dr;|t| dd }zt| | W n t	t
fyY } z	td| d|d}~ww t| || q$|   dS )u  Update config values from argparse arguments with some meta-programming ✨.

        Args:
            args (namespace or list of str, optional): parsed argparse.Namespace or list of command line parameters. If unspecified will use a newly created parser with ```init_argparse()```.
            arg_prefix: prefix to add to CLI parameters. Gets forwarded to ```init_argparse``` when ```args``` is not passed.
        r   rp   Nrh   z&' not exist to override from argparse.)r   r   r    r)   r   rR   r   r_   rt   r&   r%   r1   ry   r   )r   r}   r   r   r   rL   rM   er   r   r   r     s$   	

zCoqpit.parse_argsc                 C   sR   |s| j ||d}| \}}t|tr"| j ||d}||\}}| | |S )a  Update config values from argparse arguments. Ignore unknown arguments.
           This is analog to argparse.ArgumentParser.parse_known_args (vs parse_args).

        Args:
            args (namespace or list of str, optional): parsed argparse.Namespace or list of command line parameters. If unspecified will use a newly created parser with ```init_argparse()```.
            arg_prefix: prefix to add to CLI parameters. Gets forwarded to ```init_argparse``` when ```args``` is not passed.
            relaxed_parser (bool, optional): If True, do not force all the fields to have compatible types with the argparser. Defaults to False.

        Returns:
            List of unknown parameters.
        )r   r   )r   parse_known_argsr    r)   r   )r   r}   r   r   r   unknownr   r   r   r   .  s   

zCoqpit.parse_known_argsr   r   c                 C   s   |st  }t| }|D ]2}|jt| v rt| |j }n
|jtur%|jnd}|j}|j}	t	|}
t
||j|||	|
|||	 q|S )a  Pass Coqpit fields as argparse arguments. This allows to edit values through command-line.

        Args:
            parser (argparse.ArgumentParser, optional): argparse.ArgumentParser instance. If unspecified a new one will be created.
            arg_prefix (str, optional): Prefix to be used for the argument name. Defaults to 'coqpit'.
            help_prefix (str, optional): Prefix to be used for the argument description. Defaults to ''.
            relaxed_parser (bool, optional): If True, do not force all the fields to have compatible types with the argparser. Defaults to False.

        Returns:
            argparse.ArgumentParser: parser instance with the new arguments.
        N)argparseArgumentParserr   r   r   r9   r:   r6   r;   r   r   )r   r   r   r   r   r   r@   r   rX   r   r   r   r   r   r   K  s,   zCoqpit.init_argparserj   )F)r   N)Nr   )Nr   F)Nr   r   F).r   r   r   r   r   r   r   r   r   r#   r   r   r   r   r   r   r   r   rR   r   r   r   r   r$   r   r   r,   rE   r   r   r   r   rS   r   r   r   r   r   r   	Namespacer   r   r   r  r   __classcell__r   r   r   r   r   C  s    	
	1
"
r   Tis_path
prerequest	enum_listmax_valmin_val
restrictedalternative
allow_nonec
           
         s  |	r
 |  du r
dS |	s |  dusJ d|  dt |tr/|r/|   v s/J d|  dt |trKt fdd|D sJJ d| d	|  d
n|du s`|  v s`J d| d	|  d
|rwtj |  swJ d|  d |   d|  v r | durdS |   v r|dur |  |ksJ d|  d| |dur |  |ksJ d|  d| |durɈ |   |v sJ d|  ddS dS dS )a'  Simple type and value checking for Coqpit.
    It is intended to be used under ```__post_init__()``` of config dataclasses.

    Args:
        name (str): name of the field to be checked.
        c (dict): config dictionary.
        is_path (bool, optional): if ```True``` check if the path is exist. Defaults to False.
        prerequest (list or str, optional): a list of field name that are prerequestedby the target field name.
            Defaults to ```[]```.
        enum_list (list, optional): list of possible values for the target field. Defaults to None.
        max_val (float, optional): maximum possible value for the target field. Defaults to None.
        min_val (float, optional): minimum possible value for the target field. Defaults to None.
        restricted (bool, optional): if ```True``` the target field has to be defined. Defaults to False.
        alternative (str, optional): a field name superceding the target field. Defaults to None.
        allow_none (bool, optional): if ```True``` allow the target field to be ```None```. Defaults to False.


    Example:
        >>> num_mels = 5
        >>> check_argument('num_mels', c, restricted=True, min_val=10, max_val=2056)
        >>> fft_size = 128
        >>> check_argument('fft_size', c, restricted=True, min_val=128, max_val=4058)
    Nz# [!] None value is not allowed for rp   z [!] z not defined in config.jsonc                 3   s    | ]	}|   vV  qd S rj   )keys)rK   r   cr   r   	<genexpr>  s    
z!check_argument.<locals>.<genexpr>z [!] prequested fields z for z are not defined.z [!] path for z ("z") does not exist.z is larger than max value z is smaller than min value z is not a valid value)	r    r$   r  r)   anyospathexistslower)
r   r  r  r  r  r  r  r	  r
  r  r   r  r   check_argumenty  s:   $

*   r  )r   r   F)FNNNNFNT)?r   r   r   rk   r  collections.abcr   dataclassesr   r:   r   r   r   r   r   r	   pathlibr
   r   typingr   r   r   r   r   r   r   r   r   r   r   r   NoDefaultVarr   r$   r(   r+   r-   r/   r.   r7   r=   rA   rF   rJ   rW   rb   rd   r!   r"   r#   rg   rU   ry   rt   r   r   rS   r   r   r   r)   r  r   r   r   r   <module>   s   
  ,.}
r  :	
