
    QneD                       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mZmZ erddlmZ  ede	          Zn ed          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 ddlmZmZ  G d dee                   Z dS )zTool to configure Python tools.    )annotations)SUPPRESSArgumentParser)is_dataclass)Path)TYPE_CHECKINGAnyGenericSequenceTypeVar)DataclassInstance
DataclassT)bound)_gather_config_fields)	PyProjectPyToolSource)ConfigField)UniversalConfig)_dict_to_dataclass_recursive_mergec                      e Zd ZU d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_sourcesargsr	   kwargsreturnNonec	                   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!   r)   r*   s              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///$(         list[str] | Noner   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)	r1   r)   configuration	universalparsedr@   valuefielduniversal_values	            r2   parsezPyToolConfig.parseL   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".%'  
 r4   c           
         | 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   )r1   r@   rE   flagss       r2   r0   zPyToolConfig._setup_arg_parsere   s    ? 	#288:: 
 
e% 	!.E0DO0"[". ( $!   		 	
 
r4   c                &   |                                  }| j        r>t          | j                  D ](}|                                }|t          ||          })n7| j        D ]/}|                                }|rt          | j         |          c S 0|S N)r   r!   reversedr   rG   r   r   )r1   rA   sourcerC   s       r2   r7   zPyToolConfig._parse_sourcess   s    

 
	B"4<00 L L%$4]F$K$KML , B B B-dj&AAAAABr4   )NNFNF)r   r   r   r   r   r   r#   r"   r%   r&   r'   r    r(   r&   r!   r    r)   r	   r*   r	   r+   r,   rT   )r)   r5   r+   r   )r+   r,   )r+   r   )__name__
__module____qualname____doc____annotations__r!   r#   r3   rG   r0   r7    r4   r2   r   r      s         //IIIL(,J,,,,**** -126#26"(! (! (! (! (!T    2        r4   r   N)!rZ   
__future__r   argparser   r   dataclassesr   pathlibr   typingr   r	   r
   r   r   	_typeshedr   r   pytoolconfig.fieldsr   pytoolconfig.sourcesr   r   r   pytoolconfig.typesr   pytoolconfig.universal_configr   pytoolconfig.utilsr   r   r   r\   r4   r2   <module>rh      sr   % % " " " " " " - - - - - - - - $ $ $ $ $ $       A A A A A A A A A A A A A A '++++++->???JJ&&J 5 5 5 5 5 5 : : : : : : : : : : * * * * * * 9 9 9 9 9 9 C C C C C C C Cj j j j j7:& j j j j jr4   