
    ?eX)                     ^    d dl mZ ddlmZ ddlmZ  G d d          Z G d d          Zd	S )
    )Marker   )UserException)PyProjectOptionExceptionc                   Z    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zed             ZdS )Configurablez A base class for an object that can be configured by a pyproject.toml,
    a build script or (possibly) the user via command line options.
    Nc           	         ||                                  }|D ]b}t          | |j                  |j        !|j        r
||j        vr2|                    |t                                }|                    |            t          |          dk    r}|j	        }|j
        rd|z   }d|z   }|j        t          u r-|                    ||j        |j
        rdnd|j                   |j        t          u rP|                    d          r
|dd	         }|                    ||j        |j        d
|j        |j                   .|                    ||j        |j        |j        |j        |j                   ddS )z Add the object's command line options to an argument parser and
        update a map of Object instances and the configurables that they should
        be applied to.
        Nr   zno-z--store_false
store_true)destactionhelpsappend)r   choicesr   r   metavar)r   typer   r   r   )get_optionsgetattrnamer   tools
setdefaultlistr   len	user_nameinvertedoption_typebooladd_argumentr   endswithr   r   )selfparsertoolall_optionsoptionsoptionconfigurablesargument_names           5lib/python3.11/site-packages/sipbuild/configurable.pyadd_command_line_optionsz%Configurable.add_command_line_options#   s    ?&&((G -	B -	BF tV[))5 {" | FL 8 8 (226466BBM  &&&=!!Q&& #,M 6 % 5 =0M!T))##M17 !2%1#[ $ * * * * #t++ ))#.. 7$1#2#$6M##M &x#[&. $ B B B B ##M#/#[&. $ B B B BW-	B -	B    c                 4    |                      |d           dS )zd Set default values for each non-user configurable option that
        hasn't been set yet.
        FuserN_apply_defaultsr"   r$   s     r*   apply_nonuser_defaultsz#Configurable.apply_nonuser_defaults[   s#    
 	T.....r,   c                 4    |                      |d           dS )z` Set default values for each user configurable option that hasn't
        been set yet.
        Tr.   Nr0   r2   s     r*   apply_user_defaultsz Configurable.apply_user_defaultsb   s#    
 	T-----r,   c           
         |                     |          }|2|                                D ]\  }}|                                 D ]}|j        |k    r nt	          |d|          t          ||j                  sBt	          |d                    |j        j        t          |          j                  |          t          | |j                  t	          |d|          t          |t                    r7g }|D ]0}	|                     |	||          }	|	|                    |	           1|}t          | |j        |           |                     |           dS )z1 Perform the initial configuration of an object. Nzis not a supported optionsection_namez%should be of type '{0}' and not '{1}'z2has already been set in code and cannot be changed)get_sectionitemsr   r   r   
isinstancer   format__name__r   r   r   r   _handle_markerr   setattrr3   )
r"   	pyprojectr8   r$   sectionr   valuer'   	new_valuevs
             r*   	configurezConfigurable.configurei   s    ''55&}} $2 $2e"..00 7 7F'4// 0 347)57 7 7 7
 "%);<< 724CJJ$*$6$?$(KK$8: : *6	7 7 7 7 4--924&)57 7 7 7 eT** & "I" 0 0 //4FF=%,,Q///%Efk51111##D)))))r,   c                     t                      S )z( Return a list of configurable options. )r   )r"   s    r*   r   zConfigurable.get_options   s     vvr,   c                 2   g }|                                  D ]B}|j        }|                    |           t          | ||                    |                     C|                                D ](}||vr"t          d                    |                    )dS )z Initialise the options. z'{0}' is not a valid optionN)r   r   r   r?   getkeysr   r<   )r"   kwargsnamesr'   r   kws         r*   initialise_optionszConfigurable.initialise_options   s    
 &&(( 	2 	2F;DLLD$

4 0 01111 ++-- 	N 	NB#$A$H$H$L$LMMM 	N 	Nr,   c                     dS )z; Verify that the configuration is complete and consistent. N r2   s     r*   verify_configurationz!Configurable.verify_configuration   s      r,   c                    |                                  D ]}|r|j        |s|j        t          | |j                  }||j        }|^|j        t          u rg }nb|j        t          u rd}nQ|j        t          u rd}n@|j        t          u r|j
        rdnd}n&|j        t          u rd}n|                    |          }t          | |j        |           dS )z\ Set default values for each user/non-user option that hasn't been
        set yet.
        Ng        r   TF )r   r   r   r   defaultr   r   floatintr   r   strr?   )r"   r$   r/   r'   rB   s        r*   r1   zConfigurable._apply_defaults   s   
 &&(( 	2 	2F + FK3D&+..E}=)T11 "+u44 #+s22 !+t33(. BU+s22 " #..u55Efk51115	2 	2r,   c                     d| vr| S |                      dd          \  } }	 t          |                                          }n*#  t          |d                    |          |          xY w|r| ndS )z Handle any environment marker in a value.  The value is returned if
        a marker evaluates to True.  None is returned if a marker evaluates to
        False.
        ;r   )maxsplitzhas an invalid marker '{0}'r7   N)splitr   evaluater   r<   )rB   r   r8   marker	satisfieds        r*   r>   zConfigurable._handle_marker   s     eLC!44v	/v//11II	/*4188@@!-/ / / / "+uut+s   !A 'A+)N)r=   
__module____qualname____doc__r+   r3   r5   rE   r   rM   rP   r1   staticmethodr>   rO   r,   r*   r   r      s         6B 6B 6B 6Bp/ / /. . .,* ,* ,*\  
N N N$J J J
2 2 2B , , \, , ,r,   r   c                   <    e Zd ZdZdZedz   ZdZeddddddddZdS )	Optiona9   Encapsulate a configuration option.  This defines and implements an
    attribute of a Configurable object.  The value of the attribute can be set
    either by __init__(), the pyproject.toml file and by the user using a
    command line argument (in that order).  Once the value is set it cannot be
    changed subsequently.  For example, if an attribute is set
    in pyproject.toml then the user will not then be able to modify it from the
    command line.  The value can only be changed from the command line if the
    Option object has help text specified.
    )buildinstallwheel)sdistr   NF)r   r   rS   r   r   r   r   c                   || _         |                    dd          | _        || _        || _        || _        || _        || _        || _        || j	        | _
        n8|D ].}	|	| j        vr#t          d                    ||	                    /|| _
        dt          t          |           j                  z   | _        t          |           xj        dz  c_        dS )z Initialise the option. _-Nz''{0}' option has an invalid tools '{1}'dr   )r   replacer   r   rS   r   r   r   r   BUILD_TOOLSr   
_ALL_TOOLSr   r<   rV   r   	option_nrr   )
r"   r   r   r   rS   r   r   r   r   r$   s
             r*   __init__zOption.__init__   s     	c3//&	 =)DJJ 1 1t..'ELL$($0 01 1 1 /
 DJ#d4jj2333	T

!r,   )	r=   r^   r_   r`   rm   rn   ro   rV   rp   rO   r,   r*   rc   rc      sa          0K {*J I,/tte4" " " " " " "r,   rc   N)packaging.markersr   
exceptionsr   r@   r   r   rc   rO   r,   r*   <module>rs      s   0 % $ $ $ $ $ % % % % % % / / / / / /J, J, J, J, J, J, J, J,Z." ." ." ." ." ." ." ." ." ."r,   