
    ?e|                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZddl	m
Z
 ddlm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 dd
lmZmZ  G d dee          ZdS )    N   )AbstractBuilder)AbstractProject)Bindings)ConfigurableOption)UserException)resolve_abi_version)OLDEST_SUPPORTED_MINOR)PyProjectExceptionPyProjectOptionExceptionc            $       8    e Zd ZdZ ed           ed           ed           ede           eded	           ed
e           ed           ede           ed ej        d                     ed           ede	           ede	           edd           ede           ede           ed           ede           eded           eded           eddd d!d"g#           ed$d%d&'           ed(d)d*d"g#           ed+ed,d-d.g/           ed0ed,d1d"g/           ed2d3d4d"g#           ed5e
j                            ej                  d6d&d7d.g8           ed9 ej        d:          d;d&d7d.g8           ed<d=d&'           ed>ed,d?d7g/           ed@ed,dAd7g/          fZ edBedCd D           edEedFd D          fZ fdGZ fdHZ fdIZdJ ZdK ZdL ZdM ZdN ZdO ZdP Z fdQZdR ZdS ZdT Z	 dldVZdW Z e!dX             Z"e"j#        dY             Z"e!dZ             Z$e$j#        d[             Z$e%d\             Z&d] Z'dmd^Z(dd,d_d`Z)d,dadbZ*dc Z+dd Z,de Z-df Z.dg Z/e%dh             Z0di Z1dj Z2dk Z3 xZ4S )nProjectz@ Encapsulate a project containing one or more sets of bindings. abi_versionbindings_factorybuilder_factoryconsole_scripts)option_typedunder_initF)r   defaultgui_scriptsminimum_macos_versionpy_debugpy_include_dirinclude)r   py_platformpy_major_versionpy_minor_versionsip_files_dir.sdist_excludessip_include_dirs
sip_modulewheel_includesquietzdisable all progress messages)r   helpverbosez enable verbose progress messagesnamez+the name used in sdist and wheel file namesNAMEsdistwheel)r&   metavartools	build_dirzthe build directoryDIR)r&   r,   	build_tagz*the build tag to be used in the wheel nameTAGdistinfoTz#don't create a .dist-info directoryinstall)r   invertedr&   r-   	manylinuxzGdisable the use of manylinux in the platform tag used in the wheel nameminimum_glibc_versionzHthe minimum GLIBC version to be used in the platform tag of Linux wheelszM.Nscripts_dirz"the scripts installation directorybuild)r   r&   r,   r-   
target_dirplatlibz!the target installation directoryapi_dirz&generate a QScintilla .api file in DIRcompilez-disable the compilation of the generated codeversion_infozAdisable any reference to the SIP version number in generated codedisablezdisable the NAME bindings)r   r&   r,   enablezenable the NAME bindingsc                 4   t                                                       t          j                    | _        d| _        t          j                    | _        g | _	        d| _
        g | _        g | _        d| _        d| _        |                     |           dS )z Initialise the project. N)super__init__osgetcwdroot_dir	argumentscollectionsOrderedDictbindingsbindings_factoriesbuilder
buildablesinstallables_metadata_overrides_temp_build_dirinitialise_options)selfkwargs	__class__s     0lib/python3.11/site-packages/sipbuild/project.pyrB   zProject.__init__   s     	 	#/11"$#' #'''''    c                    | j         t          | _         n?t          | j         t                    r%|                     | j         t                    | _         | j        | j        +t          j        dz	  | _        t          j        dz	  dz  | _        | j	        .| j        | j        fdk    rddl
m} || _	        nMddlm} || _	        n?t          | j	        t                    r%|                     | j	        t                    | _	        | j        t          j        | _        | j        t%          t          d	          | _        t'                                          |           dS )
zL Set default values for non-user options that haven't been set yet.
        N         )   
   r   )SetuptoolsBuilder)DistutilsBuildergettotalrefcount)r   r   
isinstancestrimport_callabler   r   sys
hexversionr   setuptools_builderr\   distutils_builderr]   r   r   platformr   hasattrrA   apply_nonuser_defaults)rQ   toolr\   r]   rS   s       rT   rh   zProject.apply_nonuser_defaults   s_     ($,D!!-s33 	$($8$89N% %D!  (D,A,I$'Nb$8D!%(^r%9U$BD!'%t'<=HHAAAAAA'8$$??????'7$$,c22 	%#'#7#78L#$% $%D  #"|D= #C);<<DM&&t,,,,,rU   c                    | j         | j        d         | _         | j        7|dk    rd| _        n)t          j                    | _        | j        j         | _        t                                          |           |                                  | j	                            |           | j
                                        D ]}|                    |           dS )z@ Set default values for user options that haven't been set yet. Nr(   r8   )r(   metadatar.   tempfileTemporaryDirectoryrO   rA   apply_user_defaults_enable_disable_bindingsrK   rI   values)rQ   ri   rI   rS   s      rT   rn   zProject.apply_user_defaults   s     9f-DI >!w!('/'B'D'D$!%!5!:##D))) 	%%''' 	((...,,.. 	/ 	/H((....	/ 	/rU   c                 8    | j                                          dS )z Build the project in-situ. N)rK   r8   rQ   s    rT   r8   zProject.build   s     	rU   c                 b    | j                             |          }|                                  |S )zW Build an sdist for the project and return the name of the sdist
        file.
        )rK   build_sdist_remove_build_dir)rQ   sdist_directory
sdist_files      rT   rt   zProject.build_sdist   1    
 \--o>>
   rU   c                 b    | j                             |          }|                                  |S )zV Build a wheel for the project and return the name of the wheel
        file.
        )rK   build_wheelru   )rQ   wheel_directory
wheel_files      rT   rz   zProject.build_wheel  rx   rU   c                 f    t           j                            |                                 d          S )zh Return the name of the 'bindings' directory relative to the
        eventual target directory.
        rI   )rC   pathjoinget_package_dirrr   s    rT   get_bindings_dirzProject.get_bindings_dir  s&    
 w||D0022J???rU   c           	          t           j                            |d                    | j                            dd          | j                            S )zM Return the name of the .dist-info directory for a target directory.
        z{}-{}.dist-info-_)rC   r~   r   formatr(   replaceversion_str)rQ   r9   s     rT   get_distinfo_dirzProject.get_distinfo_dir  sK     w||J!(():):3)D)D " "# # 	#rU   c                     dS )z4 Return the contents of the __init__.py to install.   rr   s    rT   get_dunder_initzProject.get_dunder_init  s	     rrU   c                     i S )z Return a mapping of PEP 566 metadata names and values that will
        override any corresponding values defined in the pyproject.toml file.
        A typical use is to determine a project's version dynamically.
        r   rr   s    rT   get_metadata_overrideszProject.get_metadata_overrides   s	     	rU   c                     t                                                      }|                    | j                   |                    | j                   |S )z* Return the list of configurable options. )rA   get_optionsextend_options_multibindings_options)rQ   optionsrS   s     rT   r   zProject.get_options)  sH     ''%%''t}%%%t2333rU   c                 t    | j         r0| j                             d          }|d= t          j        j        | S dS )a#   Return the name of the package directory relative to the eventual
        target directory.  This is the directory containing the shared sip
        module (if there is one) or the target directory (if not).  It will
        normally be where the individual bindings are installed.
        r    r   )r#   splitrC   r~   r   )rQ   
name_partss     rT   r   zProject.get_package_dir2  s>     ? 	-..s33J27<,,rrU   c                    t          j                    }| j        dk    r| j        r|                    d          }t          |          dk    rxt          | j        d                   }t          | j        d                   }|d         dk    r
|dk     rd}d}d	                    ||          |d<   d                    |          }n| j        d
k    r| j	        r|                    d          }t          |          dk    r[| j
        r| j
        \  }}nd\  }}d|d<   |                    dd	                    ||                     d                    |          }|                    dd                              dd          S )z Return the platform tag to use in a wheel name.  This default
        implementation uses the platform name and applies PEP defined
        conventions depending on OS version and GLIBC version as appropriate.
        darwinr   rZ   r   r      arm64   z{}.{}linux)r      r5   r    r   )	sysconfigget_platformr   r   r   lenintr   r   r5   r6   insertr   )rQ   platform_tagparts	min_major	min_minormajorminors          rT   get_platform_tagzProject.get_platform_tagA  sw    !-//x''D,F' &&s++E5zzQ :1 =>>	 :1 =>>	 8w&&9r>> "I !I">>)Y??a"xx((T^( &&s++E5zzQ- (#'#=LE55#'LE5&aQue < <==="xx##C--55c3???rU   c                    | j         sg S | j                            d          }|g }nt          |t                    r|g}| j                             dd          }|D ]$}|                                d         |k    rg c S %t          | j                            d          d                   dz   }d	                    || j        |          gS )z? Return any 'Requires-Dist' to add to the project's meta-data. zrequires-distNr    r   r   r   z{} (>={}, <{}))
r#   rk   getr_   r`   r   r   r   r   r   )rQ   requires_distsip_project_namerdnext_abi_majors        rT   get_requires_distszProject.get_requires_distsi  s      	I))/:: MMs++ 	,*OM  ?223<< 	 	Bxxzz!} 000			 1 T-33C88;<<q@ ''(8$:J    ! 	!rU   Nc                    |d|d| j         ddg}|*|                    d           |                    |           |*|                    d           |                    |           |*|                    d           |                    |           | j        D ]@}|                    d	           |                    |                    d
d                     A| j        D ]@}|                    d           |                    |                    d
d                     A|                                 D ]?}|                    d           |                    d                    |                     @| j                                        D ]E\  }	}
|
r|	d|
z   z  }	d
|	v rd|	z   dz   }	|                    d           |                    |	           F|S )zM Return a sequence of command line arguments to invoke sip-distinfo.
        z--inventoryz--project-rootz--prefixz\"$(INSTALL_ROOT)\"Nz--generatorz--generator-versionz--wheel-tagz--console-script r   z--gui-scriptz--requires-distz\"{}\"=z\"z
--metadata)	rE   appendr   r   r   r   r   rN   items)rQ   sip_distinfo	inventory	generator	wheel_taggenerator_versionargsepr   rk   values              rT   get_sip_distinfo_command_linez%Project.get_sip_distinfo_command_line  s     M#
  KK&&&KK	"""(KK-...KK)*** KK&&&KK	"""& 	- 	-BKK*+++KK

3++,,,," 	- 	-BKK'''KK

3++,,,,))++ 	/ 	/BKK)***KK
))"--....#7==?? 	" 	"OHe (C%K'h 8+e3KK%%%KK!!!!rU   c                 `    | j                                          |                                  dS )z Install the project. N)rK   r3   ru   rr   s    rT   r3   zProject.install  s0     	     rU   c                     | j         S )z+ The getter for the minimum GLIBC version. )_minimum_glibc_versionrr   s    rT   r6   zProject.minimum_glibc_version       **rU   c                     |t          | d          s	d| _        dS |rJ	 |                     |          }n3# t          $ r& t	          dd                    |          d          w xY w|| _        dS )z+ The setter for the minimum GLIBC version. Nr   zminimum-glibc-versionz('{0}' is an invalid GLIBC version numbertool.sip.projectsection_name)rg   r   _convert_major_minor
ValueErrorr   r   rQ   r   s     rT   r6   zProject.minimum_glibc_version      
 =/G!H!H=*.D'F  	9911%88 9 9 9./FBII %' '%79 9 9 99 ',###	   5 0A%c                     | j         S )z+ The getter for the minimum macOS version. )_minimum_macos_versionrr   s    rT   r   zProject.minimum_macos_version  r   rU   c                     |t          | d          s	d| _        dS |rJ	 |                     |          }n3# t          $ r& t	          dd                    |          d          w xY w|| _        dS )z+ The setter for the minimum macOS version. Nr   zminimum-macos-versionz('{0}' is an invalid macOS version numberr   r   )rg   r   r   r   r   r   r   s     rT   r   zProject.minimum_macos_version  r   r   c                     	 t          | d          S # t          $ r6}t          d                    |           t	          |                    d}~ww xY w)z4 Open a file for writing while handling any errors. wz`There was an error creating '{0}' - make sure you have  write permission on the parent directory)detailN)openIOErrorr	   r   r`   )fnamees     rT   open_for_writingzProject.open_for_writing  sg    	#s### 	# 	# 	#@@Fuq66# # # #	#s    
A1AAc                 \    | j         s$|d         dk    r|dz  }t          |d           dS dS )z4 Print a progress message unless they are disabled. r   r    z...TflushN)r%   print)rQ   messages     rT   progresszProject.progress  sJ     z 	'r{c!!5 '&&&&&&		' 	'rU   c                    t           j                            |          }t           j                            |          r|S || j        }t           j                            t           j                            ||                    S )z Return a normalised version of a path.  A relative path is assumed
        to be relate to the project directory or some other provided directory.
        )rC   r~   normpathisabsrE   r   )rQ   r~   relative_tos      rT   project_pathzProject.project_path  sg    
 w%%7== 	K-Kw[$ ? ?@@@rU   
and_stderrfatalc             #     K   d                     |          }| j        rt          |d           |rt          j        nt          j        }t          j        |dt          j        t          j        |          5 }|j        D ]$}t          |t          j        j
                  V  %	 ddd           n# 1 swxY w Y   |j        dk    r*|r*t          d                    ||j                            dS dS )	z> A generator for each line of a pipe from a command's stdout. r   Tr   )shellstdinstdoutstderr)encodingNr   z'{0}' failed returning {1})r   r'   r   
subprocessSTDOUTPIPEPopenr   r`   rb   r   
returncoder	   r   )rQ   r   r   r   cmdr   pipelines           rT   read_command_pipezProject.read_command_pipe  sE      hhtnn< 	##T""""&0E""jocZ_!v7 7 7 	>:> > >$)<=======>	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>
 ?aE077T_MMO O O  s   7-B11B58B5)r   c                    |                      |d|          D ](}| j        rt          j                            |           )dS )z4 Run a command and display the output if requested. Tr   N)r   r'   rb   r   write)rQ   r   r   r   s       rT   run_commandzProject.run_command-  sS     **4D*NN 	' 	'D| '
  &&&	' 	'rU   c                    | j         D ]} ||           }|| j        |j        <   |                     ||           |                     ||           |j        rt          |j                  |                     |           | j        st          j
        dt                     | j        ]t          j                            | j                  | _        t#          j        | j        d           t          j        | j                   t          j        | j                   |                     |           t          j        | j                   |                     |           |t0          j        v r[| j        rV|                     d                    d                    | j                                                                       dS dS dS )z, Complete the configuration of the project. ignoreNT)ignore_errorsz!These bindings will be built: {}.z, )rJ   rI   r(   _set_initial_configuration_configure_from_arguments
toml_errorr   rn   r'   warningssimplefilterUserWarningrO   rC   r~   abspathr.   shutilrmtreemkdirchdirupdaterE   verify_configurationr   BUILD_TOOLSr   r   r   keys)rQ   	pyprojectri   tool_descriptionr   rI   s         rT   setupzProject.setup5  s    !% 7 	4 	4''--H+3DM(-(( 	''	4888 	&&t-=>>>  	;$Y%9::: 	  &&& | 	9!(K888 'W__T^<<DNM$.====HT^$$$
    	D
 	!!$'''6%%%$-%MM7>> IIdm&8&8&:&:;;= => > > > > &%%%rU   c                 N    |t           j        v r|                                  dS dS )z This should be re-implemented by any user supplied sub-class to
        carry out any updates to the configuration as required.  The current
        directory will be the temporary build directory.
        N)r   r	  update_buildable_bindings)rQ   ri   s     rT   r  zProject.updateg  s2     6%%%**,,,,, &%rU   c                     | j         rdS t          | j                                                  D ]#}|                                s| j        |j        = $t          | j                  dk    rt          d          dS )zr Update the list of bindings to ensure they are either buildable or
        have been explicitly enabled.
        Nr   z'There are no bindings that can be built)r?   listrI   rp   is_buildabler(   r   r	   )rQ   bs     rT   r  z!Project.update_buildable_bindingsq  s     ; 	Fdm**,,-- 	* 	*A>>## *M!&)t}"" IJJJ #"rU   c                 >     j         rI j         d                                         s*t          dd                     j                   d                                j                   _         fd j        D              _         j         j        f}dt          f}||k     s j        dk    r-t          d                     j         j                            t           j        d	
           _        |t          j        v r6 j        s/t!           j                  dk    rt          dd          d	 _        g } j        D ]}t)          |t*                    r|                    |df           /	 |\  }}n# t.          $ r dx}}Y nw xY wt)          |t*                    r-t)          |t*                    r|                    ||f           t          dd          | _        |dk    rc j        r\t2          j                             j                  s(t2          j                             j                  dk    rt          dd           j                            |            j                                        D ]}|                    |           dS )z; Verify that the configuration is complete and consistent. r   z	build-tagz'{0}' must begin with a digitr   r   c                 :    g | ]}                     |          S r   )r   ).0drQ   s     rT   
<listcomp>z0Project.verify_configuration.<locals>.<listcomp>  s7     !0 !0 !0 "&!2!21!5!5 !0 !0 !0rU   rZ   zPython v{}.{} is not supportedF)moduler   z
sip-modulezCmust be defined when the project contains multiple sets of bindingsNzwheel-includesz/elements must be strings or 2-tuples of stringsr+   z..zapi-dirz&must be relative when building a wheel) r0   isdigitr   r   r   r   r"   r   r   r   r	   r
   r   r   r	  r#   r   rI   r   r$   r_   r`   r   	TypeErrorr;   rC   r~   r   dirnamerK   r  rp   )rQ   ri   
py_versionfirst_version
normalisedwheel_includesubdirrI   s   `       rT   r  zProject.verify_configuration  s    > 	5$."3";";"="= 	5*;3::4>JJ!35 5 5 5
 "..t/ABB!0 !0 !0 !0.!0 !0 !0 +T-BC
23%%)>)B)B4;; 143HJ JK K K /t/?NNN 6%%%do%4=!!A%%.|+, , ,
  %D 
!0 	O 	OM--- O!!=$"788882,9)M66  2 2 2-11MFFF2 mS11 Oj6M6M O%%}f&=>>>>23CMO O O ) 7??t|?w}}T\** Bbgoodl.K.Kt.S.S.y@B B B 	))$///,,.. 	0 	0H))$////	0 	0s   6E<<FFc           
         ddl m} ddlm}  |||          }i }|                                 }t          | j                  dk     r| j        D ]}|                    |           | 	                    ||||           | j
        	                    |||           | j                                        D ]}	|		                    |||           |                    | j                  }
|                                D ]H\  }}|D ]@}t          |
|j                  r)t#          ||j        t'          |
|j                             AIdS )	z< Update the configuration from any user supplied arguments. r   )SUPPRESSr   )ArgumentParser)argument_defaultr   )r   N)argparser#  argument_parserr$  r   r   rI   r   removeadd_command_line_optionsrK   rp   
parse_argsrF   r   rg   destsetattrr(   getattr)rQ   ri   r  r#  r$  parserall_optionsr   multirI   r   optionconfigurablesconfigurables                 rT   r   z!Project._configure_from_arguments  s    	&%%%%%333333 08LLL ""$$t}!! 4 & &u%%%%%%fdK 	& 	! 	! 	! 	--fdKHHH,,.. 	I 	IH--fdKHHHH   00%0%6%6%8%8 	8 	8!FM - 8 84-- 8L&+#D&+668 8 88	8 	8rU   c                     |                      d          }t          |          dk    rt                      t          |d                   t          |d                   fS )z Convert a 'major.minor' version number to a 2-tuple of integers.
        Raise a ValueError exception if it is invalid.
        r    r   r   r   )r   r   r   r   )r   r   s     rT   r   zProject._convert_major_minor  sM     C  u::??,,58}}c%(mm++rU   c                 B   t          | j                                                  }| j        rt| j        D ](}||vr"t	          d                    |                    )t          | j                                                  D ]}|j        | j        vr| j        |j        = | j        rt| j        D ](}||vr"t	          d                    |                    )t          | j                                                  D ]}|j        | j        v r| j        |j        = dS dS )zL Check the enabled bindings are valid and remove any disabled ones.
        zUnknown enabled bindings '{0}'zUnknown disabled bindings '{0}'N)	r  rI   r
  r?   r	   r   rp   r(   r>   )rQ   namesenabledr  disableds        rT   ro   z Project._enable_disable_bindings  sc    T]''))** ; 		.; N N%'''<CCGLLN N N (
 $-..0011 . .6,,af- < 		. L P P5(('=DDXNNP P P )
 $-..0011 . .6T\))af-		. 		.. .rU   c                     d| _         dS )z Remove the build directory. N)rO   rr   s    rT   ru   zProject._remove_build_dir  s      $rU   c                    |                                 | _        |                                 | _        | j                            | j                   | j        d         | _        t          j                            | j                  j	        }|
                    d          }t          |          dk     r(|                    d           t          |          dk     (d}|D ]R}|dz  }	 |t          |          z  }# t          $ r+ t          dd                    | j                  d	          w xY w|| _        |                     |d
|           |                     |           | _        | j                            |d|           |                    d          }|E|                                D ]0}|| j        vr%|                     | |          }|| j        |j        <   1| j        s0|                     | | j        d                   }|| j        |j        <   | j                                        D ]!}|                    |d|j        z   |           "dS )z* Set the project's initial configuration. versionr    rZ   0r      z"'{0}' is an invalid version numberztool.sip.metadatar   r   ztool.sip.builderztool.sip.bindingsNr(   ztool.sip.bindings.)get_metadatark   r   rN   r  r   	packagingr;  parsebase_versionr   r   r   r   r   r   r   	configurer   rK   get_sectionr
  rI   r   r(   rp   )	rQ   r  ri   rA  r;  partbindings_sectionsr(   rI   s	            rT   r   z"Project._set_initial_configuration  s    "..00#'#>#>#@#@ T5666=3 !(..t/?@@M#))#..,!##$$$ ,!##   		: 		:DMG:3t99$ : : :.y<CC $ 02 2%8: : : ::  	y"4d;;; ++D11y*<dCCC &112EFF()..00 < <t},,#44T4@@H3;DM(-0 } 	4,,T4=3HIIH+3DM(-( ,,.. 	 	Hy*>*N   	 	s   )C<<5D1)NNN)N)5__name__
__module____qualname____doc__r   r  boolr   get_pathr   rC   r~   r  rb   
executabler   r   rB   rh   rn   r8   rt   rz   r   r   r   r   r   r   r   r   r   r3   propertyr6   setterr   staticmethodr   r   r   r   r   r  r  r  r  r   r   ro   ru   r   __classcell__)rS   s   @rT   r   r   ,   sU       JJ
 	} 	!"" 	 !! 	 d333 	}$>>> 	}$/// 	&'' 	zt,,, 	););I)F)FGGG 	} 	!s333 	!s333
 	,,,
 	T222 	!t444 	| 	T222 	wD4	6 	6 	6yd7	9 	9 	9vIw&8	: 	: 	:{!6FFF{!MgY	0 	0 	0ztd:9+	O 	O 	O{t,i	! 	! 	! 	&.gY	0 	0 	0 	}bgoocn&E&E95	*	, 	, 	, 	|%7Y%7	%B%B8%	*	, 	, 	, 	yG	 	 	ydTDi	! 	! 	! 	~4$)i	! 	! 	!AdHP 	yd1L	  	  	 xT0J	  	  	 ( ( ( ( (&!- !- !- !- !-F/ / / / /<  
    @ @ @# # #          &@ &@ &@P! ! !4 ?C4 4 4 4l! ! ! + + X+
 !, , "!,* + + X+
 !, , "!,* 	# 	# \	#' ' 'A A A A 5: O O O O O& *. ' ' ' ' '0> 0> 0>d- - -K K K G0 G0 G0R!8 !8 !8F 	, 	, \	,. . .<$ $ $
6 6 6 6 6 6 6rU   r   )rG   rC   r?  r  r   rb   r   rl   r   abstract_builderr   abstract_projectr   rI   r   r3  r   r   
exceptionsr	   r  r
   py_versionsr   r  r   r   r   r   rU   rT   <module>rU     s@  0     				          



       - - - - - - - - - - - -       . . . . . . . . % % % % % % ' ' ' ' ' ' / / / / / / C C C C C C C Cf f f f fo| f f f f frU   