
    c                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlm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mZ  ede          Z G d dee                   ZdS )zTool to configure Python tools.    )annotations)SUPPRESSArgumentParser)is_dataclass)Path)GenericSequenceTypeVar)_gather_config_fields)	PyProjectPyToolSource)ConfigField	Dataclass)UniversalConfig)_dict_to_dataclass_recursive_merge
DataclassT)boundc                      e Zd ZU dZg Zded<   ded<   ded<   ded	<   d
Zded<   dZded<   ded<   	 	 	 	 	 dd dZd!d"dZ	d#dZ
d$dZdS )%PyToolConfigz%Python Tool Configuration Aggregator.zlist[Source]sourcesstrtoolr   working_directorytype[DataclassT]modelFboolfall_throughNArgumentParser | None
arg_parserzdict[str, ConfigField]_config_fieldscustom_sourcesSequence[Source] | Noneglobal_configglobal_sourcesc	                   t          |          sJ || _        t          |          | _        || _        t          ||g|	R i |
g| _        |r| j                            |           |r'| j                            t          |                     |r| j                            |           || _
        || _        |                                  dS )a\  Initialize the configuration object.

        :param tool: name of the tool to use.
        :param working_directory: working directory in use.
        :param model: Model of configuration.
        :param arg_parser: Arugument Parser.
        :param custom_sources: Custom sources
        :param global_config: Enable global configuration
        :param global_sources: Custom global sources
        :param fall_through: Configuration options should fall through between sources.
        :param args: Passed to constructor for PyProject
        :param kwargs: Passed to constructor for PyProject
        N)r   r   r   r"   r   r   r   extendappendr   r!   r   _setup_arg_parser)selfr   r   r   r!   r#   r%   r&   r   argskwargss              9lib/python3.11/site-packages/pytoolconfig/pytoolconfig.py__init__zPyToolConfig.__init__   s    4 E"""""
3E::	!"3TKDKKKFKKL 	0L/// 	.Lt--- 	0L///$(         r,   list[str] | Nonereturnr   c                    |                                  }t          | j        d         t                    sJ | j        d                                         }| j        rI|g }| j                            |          }|                                D ]\  }}t          |||           | j	        
                                D ]>\  }}|j        r2t          |          |j        j                 }|t          |||           ?|S )z_Parse the configuration.

        :param args: any additional command line overwrites.
        r   )_parse_sources
isinstancer   r   universalconfigr!   
parse_args_get_kwargssetattrr"   itemsuniversal_configvarsname)	r+   r,   configuration	universalparsedr=   valuefielduniversal_values	            r.   parsezPyToolConfig.parseG   s   
 ++--$,q/955555%)\!_%D%D%F%F	? 	4 _//55F%1133 4 4etU3333.4466 	 	KD%% "&y//%2H2M"N" %'  
 r0   Nonec           
         | j         rR| j                                        D ]:\  }}|j        r,|j        } | j         j        ||j        |j        t          ||d 9d S d S )N)typehelpdefaultmetavardest)r!   r"   r:   command_lineadd_argument_typedescriptionr   )r+   r=   rB   flagss       r.   r*   zPyToolConfig._setup_arg_parser`   s    ? 	#288:: 
 
e% 	!.E0DO0"[". ( $!   		 	
 
r0   c                &   |                                  }| j        r>t          | j                  D ](}|                                }|t          ||          })n7| j        D ]/}|                                }|rt          | j         |          c S 0|S N)r   r   reversedr   rD   r   r   )r+   r>   sourcer@   s       r.   r4   zPyToolConfig._parse_sourcesn   s    

 
	B"4<00 L L L$4]F$K$KML , B B B-dj&AAAAABr0   )NNFNF)r   r   r   r   r   r   r!   r    r#   r$   r%   r   r&   r$   r   r   rR   )r,   r1   r2   r   )r2   rE   )r2   r   )__name__
__module____qualname____doc__r   __annotations__r   r!   r/   rD   r*   r4    r0   r.   r   r      s         //GIIIL(,J,,,,**** -126#26"(! (! (! (! (!T    2        r0   r   N)rX   
__future__r   argparser   r   dataclassesr   pathlibr   typingr   r	   r
   pytoolconfig.fieldsr   pytoolconfig.sourcesr   r   r   pytoolconfig.typesr   r   pytoolconfig.universal_configr   pytoolconfig.utilsr   r   r   r   rZ   r0   r.   <module>re      s@   % % " " " " " " - - - - - - - - $ $ $ $ $ $       - - - - - - - - - - 5 5 5 5 5 5 : : : : : : : : : : 5 5 5 5 5 5 5 5 9 9 9 9 9 9 C C C C C C C CW\333
i i i i i7:& i i i i ir0   