
    ?e9                         d dl m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 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mZ  G d de          ZdS )    )abstractmethodN   )AbstractBuilder)BuildableFromSources)set_globals)write_metadata)UserException)Installable)
copy_sip_hcopy_sip_pyi)OLDEST_SUPPORTED_MINOR)SIP_VERSIONSIP_VERSION_STRc                       e Zd ZdZd Zeddd            Zeddd            Zd	 Zd
 Z	d Z
eddd            Zd Zd ZdS )Builderz7 The default base implementation of a project builder. c                     |                                   |                                  | j        j        r!|                     | j        j                   dS dS )z Build the project in-situ. N)_generate_bindings_generate_scriptsprojectcompilebuild_project
target_dir)selfs    0lib/python3.11/site-packages/sipbuild/builder.pybuildzBuilder.build-   s^     	!!!   < 	8t|677777	8 	8    T)fatalc                    dS )z{ Build an executable from a BuildableExecutable object and return
        the relative pathname of the executable.
        N )r   	buildabler   s      r   build_executablezBuilder.build_executable6         r   N	wheel_tagc                    dS )z Build the project. Nr   r   r   r$   s      r   r   zBuilder.build_project<   r"   r   c           	         | j         }d                    |j                            dd          |j                  }t
          j                            |j        |          }t          j	        |           g }|j
        D ]L}|                    t          j        t
          j                            |j        |                               Mt          j        |j                  D ]\  }}}	||j        k    r|dd= 	 |                    d           n# t           $ r Y nw xY w|	D ]}
t
          j                            ||
          }||v r't
          j                            |t
          j                            ||j                            }t          j        t
          j                            |          d           t)          j        ||           t-          |j        |                                t
          j                            |d          |j                   |d	z   }t
          j                            t
          j                            ||                    }t          j                    }t          j        |j                   d
dl}|                    |d|j                  }|                    |           |                                  t          j        |           |S )zW Build an sdist for the project and return the name of the sdist
        file.
        {}-{}-_N__pycache__T)exist_okzPKG-INFOz.tar.gzr   zw:gz)format)!r   r-   namereplaceversion_strospathjoin	build_dirmkdirsdist_excludesextendglobroot_dirwalkremove
ValueErrorrelpathmakedirsdirnameshutilcopy2r   metadataget_requires_distsabspathgetcwdchdirtarfileopen
PAX_FORMATaddclose)r   sdist_directoryr   
sdist_name
sdist_rootexcludedpattdnamedirnames	filenamess_fn	s_fn_path	d_fn_path
sdist_file
sdist_path	saved_cwdrG   tfs                     r   build_sdistzBuilder.build_sdist@   s   
 , ^^GL$8$8c$B$B#% %
 W\\'"3Z@@

 * 	M 	MDOODIbgll73CT&J&JKKLLLL*,''2B*C*C 	3 	3&E8Y)))QQQK....    " 
3 
3GLL55	((GLL	73CDDF F	BGOOI66FFFFY	2222
3 	w')C)C)E)EZ44g6F	H 	H 	H  )+
W__RW\\/:%N%NOO
IKK	
"###\\*fW5G\HH
z




s   <D
DDc           	      n   | j         }t          j                            |j        d          }t          j        |           |                                  d}|j        D ]"}t          |t                    r|j
        sd} n#g }|r@|                    dt          t                    z              |                    d           nd                    t          j        dz	  dz  t          j        d	z	  dz            }|                    d
                    |                     	 |                    d|z   t          j        z              n%# t$          $ r |                    d           Y nw xY w|                    |                                           d                    |          }t)          |j                  D ]\  }\  }	}
t          j                            |	          s%t          j                            |j        |	          }	t1          j        |	          }|r\t3          |rd                    |          nd|
          }|j                            |           |j                            |           |                     ||           |                     ||           d                    |j                             dd          |j!                  }|j"        r|d                    |j"                  z  }|d                    |          z  }t          j        #                    t          j                            ||                    }t          j$                    }t          j%        |           ddl&m'}m(}  ||d|          5 }t          j)        d          D ]]\  }}}|D ]T}t          j        *                    t          j                            ||                    }|+                    |           U^	 ddd           n# 1 swxY w Y   t          j%        |           |S )zV Build a wheel for the project and return the name of the wheel
        file.
        wheelTFcp3abi3z{}{}         zcp{}cpnoner)   zwheel_includes_{}wheel_includestarget_subdirr#   r(   r*   z-{}z-{}.whlr   )ZipFileZIP_DEFLATEDw)compression.N),r   r1   r2   r3   r4   r5   r   
buildables
isinstancer   uses_limited_apiappendstrr   r-   sys
hexversionabiflagsAttributeErrorget_platform_tag	enumeratere   isabsr9   r8   r
   filesr7   installablesr   install_projectr.   r/   r0   	build_tagrD   rE   rF   zipfilerh   ri   r:   r=   write)r   wheel_directoryr   wheel_build_dirall_use_limited_apir    r$   major_minornrrP   rg   re   installable
wheel_file
wheel_pathrY   rh   ri   zfdirpathr*   rS   filenamer.   s                           r   build_wheelzBuilder.build_wheel   sl   
 , ',,w'8'BB
!!! 	!!! # + 	 	I)%9::  1 */'E 	 	) US)?%@%@@AAAV$$$$ --2)=(E^r)T13 3K V]];77888)  !3cl!BCCCC! ) ) )  ((((() 	1133444HHY''	 *373I)J)J 
	9 
	9%B%}7==&& <w||G$4d;;!Yt__N 9):<R+222666BR&35 5 5 !((888$++K888 	?i@@@ 	_	BBB^^GL$8$8c$B$B#% %
  	:%,,w'8999Ji&&y111
W__RW\\/:%N%NOO
 IKK	
!!!11111111WZ,??? 	#2)+ # #%I ) # #H7??27<<+J+JKKDHHTNNNN	##	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	s%   $%E
 
E,+E,A3PPPc                     | j         j        }|                                  |                                  |                     |           |                     |           dS )z Install the project. N)r   r   r   r   r   r{   )r   r   s     r   installzBuilder.install   s`     \,
!!!   :&&&Z(((((r   c                    dS )z. Install the project into a target directory. Nr   r&   s      r   r{   zBuilder.install_project   r"   r   c                 
   | j         }|j                            d          \  }}t          |j                  }|j        r|                    |j                   t          j	        
                    |j        d          }|                    |           |                    t          j	        
                    |j        |                                                     t          ||j        |j        |j                   t!          t"          |j        rt$          ndt'          |          t'          |          |j        t(                     g }|j                                        D ]}|                    d                    |j                             ||_        |                                }|`|j        s\|                    t          j	        
                    |j        |j        dz                        |j        r|                    |           |j                            |           |j         r|!                                }	t          j	        
                    |j        d          }
|"                    |
          }|#                    |$                                           |%                                 tM          d|		          }|j'                            |
           |j(                            |           |j                                        D ]}|j)        rtU          ||j                   tM          d
|		          }|j'                            t          j	        
                    |j        d                     |j(                            |           t          j	        
                    |j        d          }tW          |d          5 }	 ddd           n# 1 swxY w Y   tM          d|		          }|j'                            |           |j(                            |            n|j,        r|j        dz   }|                    d                    |                     t          j	        
                    |j        |          }|"                    |          }|D ]P}tW          |          5 }|#                    |-                                           ddd           n# 1 swxY w Y   Q|%                                 tM          d|j,        	          }|j'                            |           |j(                            |           dS dS )z0 Generate the bindings for all enabled modules. rl   bindings)version_infoNzGenerating the {0} bindingsz.apiz__init__.pyinitrf   sip_pyizsip.pyizpy.typedrj   py_typedzGenerating the {0} fileapi).r   abi_versionsplitlistsip_include_dirs
sip_modulerp   sip_files_dirr1   r2   r3   r4   r   get_bindings_dirr   r   r   r   r   intr	   r   valuesprogressr-   r.   _sip_include_dirsgenerateinternaltargetwrite_configurationrm   dunder_initget_package_diropen_for_writingr~   get_dunder_initrK   r
   ry   rz   
pep484_pyir   rH   api_dirread)r   r   abi_major_versionabi_minor_versionr   local_bindings_dir	api_filesr   r    package_dir	init_pathinit_fr   py_typed_pathr*   api_fnapi_pathapi_fpart_fnpart_fs                       r   r   zBuilder._generate_bindings   s    ,/6/B/H/H/M/M,,   899 	K##G$9::: "$g.?!L!L##$6777 ##GLL!3#44668 89 9 9
 ('*;&W5IK K K K 	K#*#7AT%&&,=(>(>"M	3 	3 	3 	(//11 	1 	1H188GGI I I *:H& ))++I*$ F  W%6 ) 06 9; ;< < <
 % F112DEEE%%i0000  "	!1133KW%6FFI--i88FLL0022333LLNNN%fKHHHK$$Y/// ''444 $,3355  &  !2G4EFFF"-i*5#7 #7 #7K%,,GLL):IFFH H H(//<<< %'GLL1BJ$O$OMmS11 Q               #.j*5#7 #7 #7K%,,];;;(//<<<E', ? 	5\F*F6==fEEFFF w||G$5v>>H,,X66E$ / /']] /fKK.../ / / / / / / / / / / / / / / KKMMM &e7?KKKK$$X... ''44444%	5 	5s$   O**O.	1O.	(S99S=	 S=	c                    | j         }|j        |j        z   }|sdS t          d|j                  }|D ]}|                    dd                              d          }t          |          dk    r"t          d	                    |                    |\  }}|                    d	          d
         }|j
        dk    r|dz  }|                    d	                    |                     t          j                            |j        |          }|j                            |           |                    |          }	|j
        dk    r4|	                    d	                    t(          j        |                     n;|	                    d           |	                    dt(          j        d|d           |	                                 t          j        |t0          j        t0          j        z  t0          j        z  t0          j        z  t0          j        z  t0          j        z  t0          j        z             
|j                             |           dS )z, Generate the scripts for any entry points. Nscriptsrf     =   z('{0}' is an invalid script specification:r   win32z.batzGenerating the {} scriptz%@{} -m {} %1 %2 %3 %4 %5 %6 %7 %8 %9
z
#!/bin/sh
zexec z -m z ${1+"$@"}
)!r   console_scriptsgui_scriptsr
   scripts_dirr/   r   lenr	   r-   py_platformr   r1   r2   r3   r4   ry   rp   r   r~   rr   
executablerK   chmodstatS_IRUSRS_IWUSRS_IXUSRS_IRGRPS_IXGRPS_IROTHS_IXOTHrz   )
r   r   r   r   epep_partsscriptmodulescript_pathscript_fs
             r   r   zBuilder._generate_scripts`  sU    , )G,?? 	F ")7;NOOO '	/ '	/Bzz#r**0055H8}}!!#BII"MMO O O &NFF \\#&&q)F"g--& 7>>vFFGGG',,w'8&AAK$$[111//<<H"g--@GG #8 89 9 9 9 }---7:~~~ &() ) ) NN H[L-dl:L!!%.L!!%./ / / /
 	##K00000r   )__name__
__module____qualname____doc__r   r   r!   r   r[   r   r   r{   r   r   r   r   r   r   r   *   s        AA8 8 8 37     ^
 59 # # # # ^#@ @ @DZ Z Zx) ) ) 7; = = = = ^=r5 r5 r5h61 61 61 61 61r   r   )abcr   r8   r1   r@   r   rr   abstract_builderr   r    r   code_generatorr   distinfor   
exceptionsr	   r   r
   r   r   r   py_versionsr   versionr   r   r   r   r   r   <module>r      s2  0        				   



 - - - - - - + + + + + + ' ' ' ' ' ' $ $ $ $ $ $ % % % % % % $ $ $ $ $ $ , , , , , , , , / / / / / / 1 1 1 1 1 1 1 1l1 l1 l1 l1 l1o l1 l1 l1 l1 l1r   