
     RneD                        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 y)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
y)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_fieldsc	                   t        |      sJ || _        t        |      | _        || _        t        ||g|	i |
g| _        |r| j                  j                  |       |r$| j                  j                  t        |             |r| j                  j                  |       || _
        || _        | j                          y)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#   custom_sourcesglobal_configglobal_sourcesr!   argskwargss              9lib/python3.12/site-packages/pytoolconfig/pytoolconfig.py__init__zPyToolConfig.__init__"   s    4 E""
3E:	!"3TKDKFKLLL/LLt-LL/$(     c                    | j                         }t        | j                  d   t              sJ | j                  d   j	                         }| j
                  rD|g }| j
                  j                  |      }|j                         D ]  \  }}t        |||        | j                  j                         D ]D  \  }}|j                  st        |      |j                  j                     }|8t        |||       F |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.parseL   s    
 ++-$,,q/955%)\\!_%D%D%F	??|__//5F%113 4etU34..446 	KD%%%"&y/%2H2H2M2M"N".%'		 r1   c           
        | j                   rt| j                  j                         D ]V  \  }}|j                  s|j                  } | j                   j                  ||j
                  |j                  t        ||d X y y )N)typehelpdefaultmetavardest)r#   r$   r9   command_lineadd_argument_typedescriptionr   )r)   r<   rA   flagss       r/   r(   zPyToolConfig._setup_arg_parsere   st    ??#2288: 
e%%!..E0DOO00"[[".. ( $!
 r1   c                *   | j                         }| j                  r;t        | j                        D ]!  }|j	                         }|t        ||      }# |S | j                  D ],  }|j	                         }|st        | j                   |      c S  |S N)r   r!   reversedr   rC   r   r   )r)   r=   sourcer?   s       r/   r3   zPyToolConfig._parse_sourcess   s    

"4<<0 L%$4]F$KML 	 ,, B-djj&AAB r1   )NNFNF)r   r   r   r   r   r   r#   r"   r*   Sequence[Source] | Noner+   r    r,   rS   r!   r    r-   r	   r.   r	   returnNonerP   )r-   zlist[str] | NonerT   r   )rT   rU   )rT   r   )__name__
__module____qualname____doc____annotations__r!   r#   r0   rC   r(   r3    r1   r/   r   r      s    /
IL$(,J%,** -126#26"(!(!  (!  	(!
 *(! 0(! (! 0(! (! (! (! 
(!T2r1   r   N)!rY   
__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[   r1   r/   <module>rg      s\    % " - $  A A+->?J&J 5 : : * 9 Cj7:& jr1   