U
    IwZ                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZejdkrHd dlmZ nd dlmZ ejdk rld dl	m
Z
 nd dlm
Z
 e je je je je jfZi ZdddZddd	ZG d
d de je je jZG dd deZG dd deZG dd deZG dd deZdZdZ dZ!dZ"G dd de j#Z#dd Z$dd Z%e j&j$e j&_'e$e j&_$e j(Z(e jZe jZe jZe j)Z)e j*Z*e j+Z+e j,Z,e j-Z-e j.Z.e j/Z/e j0Z0e j1Z1e j2Z2eZ3eZ4eZ5eZ6eZ7eZ8e#Z9e#Z:e j&j$e j&_;e j&j$e j&_<e#j=e#_>e#j?e#_@eZAeZBeZCdS )     N)   r   )StringIO)      )OrderedDictc                 K   sT   | dkrd} | t kr(td| t |  f |dtj |dd tf |t | < dS )zCreates a global ArgumentParser instance with the given name,
    passing any args other than "name" to the ArgumentParser constructor.
    This instance can then be retrieved using get_argument_parser(..)
    Ndefaultzbkwargs besides 'name' can only be passed in the first time. '%s' ArgumentParser already exists: %sZformatter_classZconflict_handlerZresolve)_parsers
ValueError
setdefaultargparseArgumentDefaultsHelpFormatterArgumentParsernamekwargs r   0/usr/lib/python3/dist-packages/configargparse.pyinit_argument_parser   s     r   c                 K   s4   | dkrd} t |dks | tkr,t| f| t|  S )a  Returns the global ArgumentParser instance with the given name. The 1st
    time this function is called, a new ArgumentParser instance will be created
    for the given name, and any args other than "name" will be passed on to the
    ArgumentParser constructor.
    Nr   r   )lenr   r   r   r   r   r   get_argument_parser.   s
    r   c                   @   s   e Zd ZdZdS ) ArgumentDefaultsRawHelpFormatterzCHelpFormatter that adds default values AND doesn't do line-wrappingN__name__
__module____qualname____doc__r   r   r   r   r   =   s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ConfigFileParserzRThis abstract class can be extended to add support for new config file
    formatsc                 C   s   t ddS )z3Returns a string describing the config file syntax.z*get_syntax_description(..) not implementedNNotImplementedErrorselfr   r   r   get_syntax_descriptionI   s    z'ConfigFileParser.get_syntax_descriptionc                 C   s   t ddS )aN  Parses the keys and values from a config file.

        NOTE: For keys that were specified to configargparse as
        action="store_true" or "store_false", the config file value must be
        one of: "yes", "no", "true", "false". Otherwise an error will be raised.

        Args:
            stream: A config file input stream (such as an open file object).

        Returns:
            OrderedDict of items where the keys have type string and the
            values have type either string or list (eg. to support config file
            formats like YAML which allow lists).
        zparse(..) not implementedNr   )r    streamr   r   r   parseM   s    zConfigFileParser.parsec                 C   s   t ddS )a  Does the inverse of config parsing by taking parsed values and
        converting them back to a string representing config file contents.

        Args:
            items: an OrderedDict of items to be converted to the config file
            format. Keys should be strings, and values should be either strings
            or lists.

        Returns:
            Contents of config file as a string
        zserialize(..) not implementedNr   )r    itemsr   r   r   	serialize^   s    zConfigFileParser.serializeNr   r   r   r   r!   r#   r%   r   r   r   r   r   E   s   r   c                   @   s   e Zd ZdZdS )ConfigFileParserExceptionz'Raised when config file parsing failed.Nr   r   r   r   r   r'   m   s   r'   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	DefaultConfigFileParsera  Based on a simplified subset of INI and YAML formats. Here is the
    supported syntax:


        # this is a comment
        ; this is also a comment (.ini style)
        ---            # lines that start with --- are ignored (yaml style)
        -------------------
        [section]      # .ini-style section names are treated as comments

        # how to specify a key-value pair (all of these are equivalent):
        name value     # key is case sensitive: "Name" isn't "name"
        name = value   # (.ini style)  (white space is ignored, so name = value same as name=value)
        name: value    # (yaml style)
        --name value   # (argparse style)

        # how to set a flag arg (eg. arg which has action="store_true")
        --name
        name
        name = True    # "True" and "true" are the same

        # how to specify a list arg (eg. arg which has action="append")
        fruit = [apple, orange, lemon]
        indexes = [1, 12, 35 , 40]

    c                 C   s   d}|S )NzrConfig file syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at https://goo.gl/R74nmi).r   r    msgr   r   r   r!      s    z.DefaultConfigFileParser.get_syntax_descriptionc                 C   s  t  }t|D ]\}}| }|r|d dks|dr<qd}d}|d | d }|d }td	| | d
 |}	|	r|	d}d||< qtd	| | | d
 |}
|
r|
d}|
d}|dr|drdd |dd dD }|||< qt	d|t
|dd|f q|S )z,Parses the keys + values from a config file.r   )#;[z---z\s*z(?P<key>[^:=;#\s]+?)z[:=\s]z(?P<value>.+?)z(?P<comment>\s[;#].*)?^$keytruevaluer-   ]c                 S   s   g | ]}|  qS r   strip).0elemr   r   r   
<listcomp>   s     z1DefaultConfigFileParser.parse.<locals>.<listcomp>   ,zUnexpected line %s in %s: %sr   r"   )r   	enumerater5   
startswithrematchgroupendswithsplitr'   getattr)r    r"   r$   ilineZwhite_spacer0   r2   ZcommentZkey_only_matchZkey_value_matchr   r   r   r#      s6    



 
zDefaultConfigFileParser.parsec                 C   sT   t  }| D ]<\}}t|tr8ddtt| d }|d||f  q| S )zDoes the inverse of config parsing by taking parsed values and
        converting them back to a string representing config file contents.
        r-   , r3   z%s = %s
)	r   r$   
isinstancelistjoinmapstrwritegetvalue)r    r$   rr0   r2   r   r   r   r%      s    
z!DefaultConfigFileParser.serializeNr&   r   r   r   r   r(   q   s   #r(   c                   @   s2   e Zd ZdZdd Zdd Zdd Zdd	d
ZdS )YAMLConfigFileParserzdParses YAML config files. Depends on the PyYAML module.
    https://pypi.python.org/pypi/PyYAML
    c                 C   s   d}|S )NzThe config file uses YAML syntax and must represent a YAML 'mapping' (for details, see http://learn.getgrav.org/advanced/yaml).r   r)   r   r   r   r!      s    z+YAMLConfigFileParser.get_syntax_descriptionc                 C   s.   zddl }W n tk
r(   tdY nX |S )zmlazy-import PyYAML so that configargparse doesn't have to dependend
        on it unless this parser is used.r   NzJCould not import yaml. It can be installed by running 'pip install PyYAML')yamlImportErrorr'   )r    rP   r   r   r   
_load_yaml   s
    zYAMLConfigFileParser._load_yamlc              
   C   s   |   }z||}W n. tk
rD } ztd| W 5 d}~X Y nX t|tsntdt|ddt|jf t	 }|
 D ](\}}t|tr|||< q|t|||< q||S )z.Parses the keys and values from a config file.zCouldn't parse config file: %sNzThe config file doesn't appear to contain 'key: value' pairs (aka. a YAML mapping). yaml.load('%s') returned type '%s' instead of 'dict'.r   r"   )rR   Z	safe_load	Exceptionr'   rG   dictrC   typer   r   r$   rH   rK   )r    r"   rP   Z
parsed_objeresultr0   r2   r   r   r   r#      s"    

 

zYAMLConfigFileParser.parseFc                 C   s   |   }t|}|j||dS )zDoes the inverse of config parsing by taking parsed values and
        converting them back to a string representing config file contents.

        Args:
            default_flow_style: defines serialization format (see PyYAML docs)
        )default_flow_style)rR   rT   dump)r    r$   rX   rP   r   r   r   r%      s    	zYAMLConfigFileParser.serializeN)F)r   r   r   r   r!   rR   r#   r%   r   r   r   r   rO      s
   rO   Zcommand_lineZenvironment_variablesconfig_filedefaultsc                   @   s   e Zd ZdZdddg deg ddg dfddZdddejfd	d
ZdddejfddZ	dddZ
dd Zdd Zdd Zdd Zdd Zdd ZejfddZdd ZdS ) r   zDrop-in replacement for argparse.ArgumentParser that adds support for
    environment variables and .ini or .yaml-style config files.
    TNFzconfig file pathzftakes the current command line args and writes them out to a config file at the given path, then exitsc                 K   s   || _ || _|| _tjj| f| |dkr4t | _n| | _|| _|| _	|rb| j
|d||	dd |
r|| j
|
dd|dd dS )a  Supports args of the argparse.ArgumentParser constructor
        as **kwargs, as well as the following additional args.

        Additional Args:
            add_config_file_help: Whether to add a description of config file
                syntax to the help message.
            add_env_var_help: Whether to add something to the help message for
                args that can be set through environment variables.
            auto_env_var_prefix: If set to a string instead of None, all config-
                file-settable options will become also settable via environment
                variables whose names are this prefix followed by the config
                file key, all in upper case. (eg. setting this to "foo_" will
                allow an arg like "--my-arg" to also be set via the FOO_MY_ARG
                environment variable)
            default_config_files: When specified, this list of config files will
                be parsed in order, with the values from each config file
                taking precedence over pervious ones. This allows an application
                to look for config files in multiple standard locations such as
                the install directory, home directory, and current directory.
                Also, shell * syntax can be used to specify all conf files in a
                directory. For exmaple:
                ["/etc/conf/app_config.ini",
                 "/etc/conf/conf-enabled/*.ini",
                "~/.my_app_config.ini",
                "./app_config.txt"]
            ignore_unknown_config_file_keys: If true, settings that are found
                in a config file but don't correspond to any defined
                configargparse args will be ignored. If false, they will be
                processed and appended to the commandline like other args, and
                can be retrieved using parse_known_args() instead of parse_args()
            config_file_parser_class: configargparse.ConfigFileParser subclass
                which determines the config file format. configargparse comes
                with DefaultConfigFileParser and YAMLConfigFileParser.
            args_for_setting_config_path: A list of one or more command line
                args to be used for specifying the config file path
                (eg. ["-c", "--config-file"]). Default: []
            config_arg_is_required: When args_for_setting_config_path is set,
                set this to True to always require users to provide a config path.
            config_arg_help_message: the help message to use for the
                args listed in args_for_setting_config_path.
            args_for_writing_out_config_file: A list of one or more command line
                args to use for specifying a config file output path. If
                provided, these args cause configargparse to write out a config
                file with settings based on the other provided commandline args,
                environment variants and defaults, and then to exit.
                (eg. ["-w", "--write-out-config-file"]). Default: []
            write_out_config_file_arg_help_message: The help message to use for
                the args in args_for_writing_out_config_file.
        NrZ   T)destZrequiredhelpis_config_file_argZ"write_out_config_file_to_this_pathZCONFIG_OUTPUT_PATH)r\   metavarr]   is_write_out_config_file_arg)_add_config_file_help_add_env_var_help_auto_env_var_prefixr   r   __init__r(   _config_file_parser_default_config_files _ignore_unknown_config_file_keysadd_argument)r    Zadd_config_file_helpZadd_env_var_helpZauto_env_var_prefixdefault_config_filesZignore_unknown_config_file_keysZconfig_file_parser_classZargs_for_setting_config_pathZconfig_arg_is_requiredZconfig_arg_help_messageZ args_for_writing_out_config_fileZ&write_out_config_file_arg_help_messager   r   r   r   rd     s,    B
 zArgumentParser.__init__c                 C   s2   | j ||||d\}}|r.| dd|  |S )T  Supports all the same args as the ArgumentParser.parse_args(..),
        as well as the following additional args.

        Additional Args:
            args: a list of args as in argparse, or a string (eg. "-x -y bla")
            config_file_contents: String. Used for testing.
            env_vars: Dictionary. Used for testing.
        )args	namespaceconfig_file_contentsenv_varszunrecognized arguments: %s )parse_known_argserrorrI   )r    rk   rl   rm   rn   argvr   r   r   
parse_argsh  s    

zArgumentParser.parse_argsc                    s|   dkrt jdd  nt tr,   nt  t } D ]N}|r|d jkrd|kr|dd\}}|| || q>|| q>| jD ]}	|	j	 |	_
qt _ rdt f}
d|
ijt< jdk	r@jD ]^}	|	}|r|	js|	j
s|	js|	jst|	tjs|d j}j| dd |	_qg } fdd	jD }|D ]h}|j}| }|jst|tjrtd
|}|rdd	 |ddD }||||7 }q^ |  |rtfdd	|D jt< tdd jD }|od kpd k}t fddjD }g }|dk	rZt!|}d|_"|g}n|sj# }t$|D ]}zDzj'(|}W n. t)k
r } z*| W 5 d}~X Y nX W 5 t%|dr|&  X g }|+ D ]\}}||kr|| }t, |j	}nd}j-p$t, .|g}|s||||7 }dt/|j"f }|jkrdt j|< ||fj| |< q |  qrt }jD ]}|j
 p|jt0t1fk}t, |j	s|r|j2dks|j2t3kst|t4rqn,|j	r |j	d }n|j5}|t|j2f||< q|r,|jt6< tj7j8 d\}fdd	jD }dd	 |D }j9|dd |fS )rj   Nr9   r   = -_c                    s2   g | ]*}|j s|jr|jkrt |js|qS r   )is_positional_argenv_varalready_on_command_lineoption_stringsr6   a)rk   rn   r   r   r8     s      
z3ArgumentParser.parse_known_args.<locals>.<listcomp>z\[(.*)\]c                 S   s   g | ]}|  r|  qS r   r4   )r6   valr   r   r   r8     s      r;   c                    s    g | ]}|j | |j  ffqS r   )ry   r|   )rn   r   r   r8     s   c                 s   s   | ]}t |tjr|V  qd S N)rG   r   _HelpActionr|   r   r   r   	<genexpr>  s     z2ArgumentParser.parse_known_args.<locals>.<genexpr>z-hz--helpc                 3   s&   | ]}  |D ]}||fV  qqd S r   )get_possible_config_keys)r6   actionZ
config_keyr   r   r   r     s     z
method argclosez%s|%sr:   )rk   rl   c                    s&   g | ]}t |d drt  |jdqS )r`   FN)rC   r\   r|   )rl   r   r   r8     s    c                 S   s   g | ]}|d k	r|qS r   r   r|   r   r   r   r8     s      T)
exit_after):sysrr   rG   rK   rB   rH   prefix_charsappend_actionsr{   rx   r   _source_to_settings_COMMAND_LINE_SOURCE_KEYrc   r   ry   r^   r`   r   r   r5   replaceuppernargs_AppendActionr>   r?   r@    convert_item_to_command_line_arg_ENV_VAR_SOURCE_KEYanyrT   r   r   _open_config_filesreversedhasattrr   re   r#   r'   rq   r$   rz   rg   4get_command_line_key_for_unknown_config_file_setting_CONFIG_FILE_SOURCE_KEYOPTIONALZERO_OR_MOREr   SUPPRESS#ACTION_TYPES_THAT_DONT_NEED_A_VALUEr\   _DEFAULTS_SOURCE_KEYr   rp   write_config_file)r    rk   rl   rm   rn   Znormalized_argsargr0   r2   r}   Za_v_pairconfig_file_keysZstripped_config_file_keyZenv_var_argsZactions_with_env_var_valuesr   Zelement_captureZsupports_help_argZskip_config_file_parsingZknown_config_keysZconfig_streamsr"   config_itemsrV   Zconfig_argsZdiscard_this_keyZ
source_keyZdefault_settingsZcares_about_default_valueZunknown_argsoutput_file_pathsr   )rk   rn   rl   r    r   rp   {  s   







   




 

 
  


  
zArgumentParser.parse_known_argsc           
      C   s   |D ]R}zt |d}W 5 Q R X W q tk
rT } ztd||f W 5 d}~X Y qX q|r| | j|}| j|}|D ]$}t |d}|| W 5 Q R X qzdd| }	|r| 	d|	 nt
|	 dS )a4  Write the given settings to output files.

        Args:
            parsed_namespace: namespace object created within parse_known_args()
            output_file_paths: any number of file paths to write the config to
            exit_after: whether to exit the program after writing the config files
        wz Couldn't open %s for writing: %sNzWrote config file to rF   r   )openIOErrorr	    get_items_for_config_file_outputr   re   r%   rL   rI   exitprint)
r    parsed_namespacer   r   Zoutput_file_pathZoutput_filerV   r   Zfile_contentsmessager   r   r   r     s,      z ArgumentParser.write_config_filec                 C   s"   | | j}| jd d | }|S )a  Compute a commandline arg key to be used for a config file setting
        that doesn't correspond to any defined configargparse arg (and so
        doesn't have a user-specified commandline arg key).

        Args:
            key: The config file key that was being set.
        r   r   )r5   r   )r    r0   Zkey_without_prefix_charscommand_line_keyr   r   r   r   <  s    zCArgumentParser.get_command_line_key_for_unknown_config_file_settingc                    s  t  }| D ]\}}|tkr|d \}| jD ]}| |  r2|js2t|jr2t||j	d}|dk	r2t
|trt| }n@t|jrć fddtdtd D }	|	rĈ|	d d  }|| d < q2q|tkr&| D ]<\}
\}}| |  rt||j	d}|dk	r|| d < qq|trT| D ]\}
\}}|||
< q:q|tkr| D ]B\}
\}}| |  rdt||j	d}|dk	rd|| d < qdq|S )a  Converts the given settings back to a dictionary that can be passed
        to ConfigFormatParser.serialize(..).

        Args:
            source_to_settings: the dictionary described in parse_known_args()
            parsed_namespace: namespace object created within parse_known_args()
        Returns:
            an OrderedDict where keys are strings and values are either strings
            or lists
        ru   Nc                    s   g | ]}|  kr|qS r   r   )r6   rD   r   Zexisting_command_line_argsr   r   r8   c  s      zCArgumentParser.get_items_for_config_file_output.<locals>.<listcomp>r   r9   r:   )r   r$   r   r   r   rx   rz   r{   rC   r\   rG   boolrK   lowercallablerU   ranger   r   r=   r   r   )r    Zsource_to_settingsr   Zconfig_file_itemssourcesettingsrw   r   r2   foundr0   r   r   r   r   I  sL    




"



z/ArgumentParser.get_items_for_config_file_outputc                 C   sT  g }|dkr|  |}n
|jd }|dk	rnt|trn| dkrL|| n | dkrZn| d||f  nt|tr|dkst|tj	r|D ]}|| |t
| qnft|tjr|jdkst|jtr|jdkr|| |D ]}|t
| qn| d||f  n6t|t
r<|| || ntd	t||f |S )
a  Converts a config file or env var key + value to a list of
        commandline args to append to the commandline.

        Args:
            action: The argparse Action object for this setting, or None if this
                config file setting doesn't correspond to any defined
                configargparse arg.
            key: string (config file key or env var name)
            value: parsed value of type string or list
        Nr:   )r1   Zyes1)ZfalseZno0zQUnexpected value for %s: '%s'. Expecting 'true', 'false', 'yes', 'no', '1' or '0')+*r9   zp%s can't be set to a list '%s' unless its action type is changed to 'append' or nargs is set to '*', '+', or > 1z&Unexpected value type %s for value: %s)r   r{   rG   r   r   r   rq   rH   r   r   rK   _StoreActionr   intr	   rU   )r    r   r0   r2   rk   r   Z	list_elemr   r   r   r   {  sJ    




 z/ArgumentParser.convert_item_to_command_line_argc                    sP   g }t |ddr|S |jD ]0 t fdd| jD r| dd  g7 }q|S )zThis method decides which actions can be set in a config file and
        what their keys will be. It returns a list of 0 or more config keys that
        can be used to set the given action's value in a config file.
        r`   Nc                    s   g | ]}  d | qS )r   )r=   )r6   cr   r   r   r8     s     z;ArgumentParser.get_possible_config_keys.<locals>.<listcomp>r   )rC   r{   r   r   )r    r   keysr   r   r   r     s    
z'ArgumentParser.get_possible_config_keysc                 C   s   dd t tjt tjj| jD }dd | jD }|s:|S |D ]}tj| j	dd}|
| dd }t|||_|j|d}|sq>|\}}	t||jd	}
|
sq>tj|
}
tj|
s| d
|
  |t|
g7 }q>|S )aj  Tries to parse config file path(s) from within command_line_args.
        Returns a list of opened config files, including files specified on the
        commandline as well as any default_config_files specified in the
        constructor that are present on disk.

        Args:
            command_line_args: List of all args (already split on spaces)
        c                 S   s   g | ]}|D ]}t |qqS r   )r   )r6   filesfr   r   r   r8     s     z5ArgumentParser._open_config_files.<locals>.<listcomp>c                 S   s   g | ]}t |d dr|qS r^   FrC   r|   r   r   r   r8     s     F)r   Zadd_helpc                 S   s   d S r   r   )r    r   r   r   r   error_method  s    z7ArgumentParser._open_config_files.<locals>.error_method)rk   NzFile not found: %s)rJ   globospath
expanduserrf   r   r   r   r   Z_add_actiontypes
MethodTyperq   rp   rC   r\   isfiler   )r    Zcommand_line_argsZconfig_filesZuser_config_file_arg_actionsr   Z
arg_parserr   Z
parsed_argrl   rw   Zuser_config_filer   r   r   r     s4    
"
z!ArgumentParser._open_config_filesc                 C   s   t dtdtdtdi}t }| j D ]\}}|d}||d  t|dd  }|	| | D ]`\}\}}|r|	d	|d
 |f  qdt
|tr|	d|  qdt
|trd|	dd|  qdq$| S )zReturns a string with all args and settings and where they came from
        (eg. commandline, config file, enviroment variable or default)
        zCommand Line Args: zEnvironment Variables:
zConfig File (%s):
z
Defaults:
|r   r9   Nz
  %-19s%s
:z  %s
ro   )r   r   r   r   r   r   r$   rB   tuplerL   rG   rK   rH   rI   rM   )r    Zsource_key_to_display_value_maprN   r   r   r0   r   r2   r   r   r   format_values  s,        



zArgumentParser.format_valuesc                 C   s   | |   dS )zBPrints the format_values() string (to sys.stdout or another file).N)rL   r   )r    filer   r   r   print_values  s    zArgumentParser.print_valuesc              	      s  d}d}d} j r؈ j}d jd  } fdd jD }dd  jD }|r|sV|rd _ d}|d	||d d f 7 }d
dd |D }|rd| }|s|r|dd
t|ttd |g  7 }|d j  7 } j	r6dd  jD }	|	D ]@\}
}d|
 }|j
sd|_
||j
kr| j
|7  _
d}d _	q|sB|rzdg}|rXdg| }|rhdg| }|dd| 7 }|r jpdd |  _tj S )Nru   Fr   r   c                    s@   g | ]8}|j D ],} |r|jd ks|js|js||fqqS )r]   )r{   r   r\   r^   r`   )r6   r}   r   r   r   r   r8     s    

 z.ArgumentParser.format_help.<locals>.<listcomp>c                 S   s   g | ]}t |d dr|qS r   r   r|   r   r   r   r8   !  s    TzCArgs that start with '%s' (eg. %s) can also be set in a config filez or c                 s   s   | ]}|j r|j d  V  qdS )r   N)r{   r|   r   r   r   r   +  s    z-ArgumentParser.format_help.<locals>.<genexpr>zspecified via z (%s).ro   c                 S   s"   g | ]}t |d dr|j|fqS )ry   N)rC   ry   r|   r   r   r   r8   5  s    z   [env var: %s]r[   zconfig file valueszenvironment variableszT If an arg is specified in more than one place, then commandline values override %s.z which override )ra   rf   r   r   rI   r   filterre   r!   rb   r]   Zdescriptionr   r   format_help)r    r*   Zadded_config_file_helpZadded_env_var_helpri   ZccZconfig_settable_argsZconfig_path_actionsZconfig_arg_stringZenv_var_actionsry   r}   Zenv_var_help_stringZvalue_sourcesr   r   r   r     sd    




zArgumentParser.format_help)F)r   r   r   r   r(   rd   r   environrs   rp   r   r   r   r   r   r   r   r   stdoutr   r   r   r   r   r   r     s>   
\ 
 
 #
237r   c                 O   s   | dd}| ddp"| dd}| dd}| j||}|j |_||_||_||_|jrj|rjtd|jrt|t	j
std|jrd}t|t	j
st|d	 |rt|d
 |S )a
  
    This method supports the same args as ArgumentParser.add_argument(..)
    as well as the additional args below.

    Additional Args:
        env_var: If set, the value of this environment variable will override
            any config file or default values for this arg (but can itself
            be overriden on the commandline). Also, if auto_env_var_prefix is
            set in the constructor, this env var name will be used instead of
            the automatic name.
        is_config_file_arg: If True, this arg is treated as a config file path
            This provides an alternative way to specify config files in place of
            the ArgumentParser(fromfile_prefix_chars=..) mechanism.
            Default: False
        is_write_out_config_file_arg: If True, this arg will be treated as a
            config file path, and, when it is specified, will cause
            configargparse to write all current commandline args to this file
            as config options and then exit.
            Default: False
    ry   Nr^   Zis_config_filer`   z*env_var can't be set for a positional arg.z9arg with is_config_file_arg=True must have action='store'z+arg with is_write_out_config_file_arg=True zmust have action='store'z'can't also have is_config_file_arg=True)poporiginal_add_argument_methodr{   rx   ry   r^   r`   r	   rG   r   r   )r    rk   r   ry   r^   r`   r   Zerror_prefixr   r   r   rh   O  s<       

rh   c                    s   t  fdd|D S )zsUtility method for checking if any of the potential_command_line_args is
    already present in existing_args.
    c                 3   s   | ]}| kV  qd S r   r   )r6   Zpotential_argexisting_args_listr   r   r     s   z*already_on_command_line.<locals>.<genexpr>)r   )r   Zpotential_command_line_argsr   r   r   rz     s    rz   )N)N)Dr   r   r   r>   r   r   version_infoior   Zordereddictr   collectionsZ_StoreTrueActionZ_StoreFalseActionZ_CountActionZ_StoreConstActionZ_AppendConstActionr   r   r   r   r   ZRawTextHelpFormatterZRawDescriptionHelpFormatterr   objectr   rS   r'   r(   rO   r   r   r   r   r   rh   rz   Z_ActionsContainerr   ZHelpFormatterZArgumentErrorZArgumentTypeErrorZActionZFileTypeZ	NamespaceZONE_OR_MOREr   Z	REMAINDERr   r   ZinitArgumentParserZgetArgumentParserZgetArgParserZ	getParserZget_arg_parserZ
get_parserZ	ArgParserZParserZadd_argaddrs   r#   rp   Zparse_knownZRawFormatterZDefaultsFormatterZDefaultsRawFormatterr   r   r   r   <module>   s   

  


(Q?    L6
