
    g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y)    )abstractmethodN   )AbstractBuilder)BuildableFromSources)set_globals)write_metadata)UserException)Installable)
copy_sip_hcopy_sip_pyi)OLDEST_SUPPORTED_MINOR)SIP_VERSIONSIP_VERSION_STRc                   v    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y)Builderz7 The default base implementation of a project builder. c                     | j                          | j                          | j                  j                  r&| j	                  | j                  j
                         yy)z Build the project in-situ. N)_generate_bindings_generate_scriptsprojectcompilebuild_project
target_dir)selfs    0lib/python3.12/site-packages/sipbuild/builder.pybuildzBuilder.build-   sF     	! <<t||667      T)fatalc                     y)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                     y)z Build the project. Nr   r   r   r$   s      r   r   zBuilder.build_project<   r"   r   c           	      6   | j                   }dj                  |j                  j                  dd      |j                        }t
        j                  j                  |j                  |      }t        j                  |       g }|j                  D ]N  }|j                  t        j                  t
        j                  j                  |j                  |                   P t        j                  |j                        D ]  \  }}}	||j                  k(  r|dd= 	 |j                  d       |	D ]  }
t
        j                  j                  ||
      }||v r(t
        j                  j                  |t
        j                  j#                  ||j                              }t        j$                  t
        j                  j'                  |      d       t)        j*                  ||         t-        |j.                  |j1                         t
        j                  j                  |d      |j                         |d	z   }t
        j                  j3                  t
        j                  j                  ||            }t        j4                         }t        j6                  |j                         d
dl}|j;                  |d|j<                        }|j?                  |       |jA                          t        j6                  |       |S # t         $ r Y w xY w)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@   sJ   
 ,, ^^GLL$8$8c$B##%
 WW\\'"3"3Z@

 **DOODIIbggll73C3CT&JKL + +-'''2B2B*C&E8Y)))QK.
 "GGLL5	(GGLL	73C3CDF	BGGOOI6FY	2 " +D4 	w'')C)C)EZ4g6F6F	H  )+
WW__RWW\\/:%NO
IIK	
""#\\*fW5G5G\H
z


I  s   L	LLc           	      D   | j                   }t        j                  j                  |j                  d      }t        j
                  |       | j                          d}|j                  D ]#  }t        |t              s|j                  r!d} n g }|r3|j                  dt        t              z          |j                  d       ndj                  t        j                   dz	  dz  t        j                   d	z	  dz        }|j                  d
j                  |             	 |j                  d|z   t        j"                  z          |j                  |j'                                dj                  |      }t)        |j*                        D ]  \  }\  }	}
t        j                  j-                  |	      s*t        j                  j                  |j.                  |	      }	t1        j0                  |	      }|sjt3        |rdj                  |      nd|
      }|j4                  j7                  |       |j8                  j                  |        | j;                  ||       | j=                  ||       dj                  |j>                  jA                  dd      |jB                        }|jD                  r|dj                  |jD                        z  }|dj                  |      z  }t        j                  jG                  t        j                  j                  ||            }t        jH                         }t        jJ                  |       ddl&m'}m(}  ||d|      5 }t        jR                  d      D ][  \  }}}|D ]P  }t        j                  jU                  t        j                  j                  ||            }|jW                  |       R ] 	 ddd       t        jJ                  |       |S # t$        $ r |j                  d       Y w xY w# 1 sw Y   AxY w)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   sN   
 ,, '',,w'8'8'B
! 	! # ++I)%9: 11*/'	 , 	 US)?%@@AV$ --2)=(E^^r)T13K V]];78)  !3cll!BC 	1134HHY'	 *373I3I)J%B%}77==&ww||G$4$4d;!YYt_N):<+2226BR&35 !!((8$$++K8 *K 	?i@ 	_	B^^GLL$8$8c$B##%
 %,,w'8'899Ji&&y11
WW__RWW\\/:%NO
 IIK	
!1Z,?2)+%I )H77??277<<+JKDHHTN	 !* *6 @ 	g " )  ()R @?s   "%O5 !A4P5PPPc                     | j                   j                  }| j                          | j                          | j	                  |       | j                  |       y)z Install the project. N)r   r   r   r   r   r{   )r   r   s     r   installzBuilder.install   sG     \\,,
! :&Z(r   c                     y)z. Install the project into a target directory. Nr   r&   s      r   r{   zBuilder.install_project   r"   r   c                 
   | j                   }|j                  j                  d      \  }}t        |j                        }|j
                  r|j                  |j                         t        j                  j                  |j                  d      }|j                  |       |j                  t        j                  j                  |j                  |j                                      t        ||j                  |j
                  |j                         t!        t"        |j                  rt$        ndt'        |      t'        |      |j
                  t(               g }|j*                  j-                         D ]  }|j/                  dj1                  |j2                               ||_        |j7                         }|`|j8                  sc|j                  t        j                  j                  |j                  |j:                  dz                |j
                  r|j=                         |j>                  j                  |        |j@                  r|jC                         }	t        j                  j                  |j                  d      }
|jE                  |
      }|jG                  |jI                                |jK                          tM        d|		      }|jN                  j                  |
       |jP                  j                  |       |j*                  j-                         D ]  }|jR                  stU        ||j                         tM        d
|		      }|jN                  j                  t        j                  j                  |j                  d             |jP                  j                  |       t        j                  j                  |j                  d      }tW        |d      5 }	 ddd       tM        d|		      }|jN                  j                  |       |jP                  j                  |        n |jX                  r|j2                  dz   }|j/                  dj1                  |             t        j                  j                  |j                  |      }|jE                  |      }|D ]5  }tW        |      5 }|jG                  |j[                                ddd       7 |jK                          tM        d|jX                  	      }|jN                  j                  |       |jP                  j                  |       yy# 1 sw Y   `xY w# 1 sw Y   xY w)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   sJ    ,,/6/B/B/H/H/M,,   8 89##G$9$9: "$g.?.?!L##$67 ##GGLL!3!3#44689
 ('*;*;&&W5I5IK 	K#*#7#7T%&,=(>""M	3 	((//1H188GI *:H& ))+I*$$  W%6%6 ) 0 06 9;<
 %%112DE%%i0) 2. !113KW%6%6FI--i8FLL0023LLN%fKHK$$Y/  ''4 $,,335&& !2G4E4EF"-i*5#7K%%,,GGLL):):IFH((//< %'GGLL1B1BJ$OMmS1Q 2 #.j*5#7K%%,,];((//<) 6. ??\\F*F6==fEF ww||G$5$5v>H,,X6E$']fKK. #] % KKM &e7??KK$$X.  ''4%  21* #]s   6U U#U 	#U,	c                    | j                   }|j                  |j                  z   }|syt        d|j                        }|D ]  }|j                  dd      j                  d      }t        |      dk7  rt        dj                  |            |\  }}|j                  d	      d
   }|j                  dk(  r|dz  }|j                  dj                  |             t        j                  j                  |j                  |      }|j                   j#                  |       |j%                  |      }	|j                  dk(  r0|	j'                  dj                  t(        j*                  |             n7|	j'                  d       |	j'                  dt(        j*                  d|d       |	j-                          t        j.                  |t0        j2                  t0        j4                  z  t0        j6                  z  t0        j8                  z  t0        j:                  z  t0        j<                  z  t0        j>                  z          |j@                  j#                  |       y)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`  s    ,, ))G,?,?? ")7;N;NOBzz#r*005H8}!#BII"MO O &NFF \\#&q)F""g-& 7>>vFG'',,w'8'8&AK$$[1//<H""g-@GG #89 }-7:~~ &() NN HH[LL-dll:LL!!%.LL!!%./I R 	##K0r   )__name__
__module____qualname____doc__r   r   r!   r   r[   r   r   r{   r   r   r   r   r   r   r   *   sn    A8 37  
 59 # #@DZx) 7; = =r5h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      sB   0   	   
 - + ' $ % $ , / 1l1o l1r   