o
    i                     @   s2   d dl Z d dlmZ d dlZG dd de jZdS )    N)Pathc                       s.   e Zd ZdZ fddZd fdd	Z  ZS )ArgumentParseray  Simple implementation of ArgumentParser supporting config file

    This class is originated from https://github.com/bw2/ConfigArgParse,
    but this class is lack of some features that it has.

    - Not supporting multiple config files
    - Automatically adding "--config" as an option.
    - Not supporting any formats other than yaml
    - Not checking argument type

    c                    s$   t  j|i | | jddd d S )Nz--configzGive config file in yaml format)help)super__init__add_argument)selfargskwargs	__class__ Q/home/ubuntu/.local/lib/python3.10/site-packages/espnet2/utils/config_argparse.pyr      s   zArgumentParser.__init__Nc           	         s   t  ||\}}|jd urlt|j s| d|j  t|jddd}t|}W d    n1 s6w   Y  t	|t
sE| d |D ]}| jD ]	}||jkrU nqL| d| d|j d qG| jd	i | t  ||S )
NzNo such file: rzutf-8)encodingz.Config file has non dict value: {_args.config}zunrecognized arguments: z (from )r   )r   parse_known_argsconfigr   existserroropenyaml	safe_load
isinstancedict_actionsdestset_defaults)	r   r	   	namespace_args_fdkeyactionr   r   r   r      s$   




zArgumentParser.parse_known_args)NN)__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s    r   )argparsepathlibr   r   r   r   r   r   r   <module>   s    