
    i                       d Z ddlm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mZ ddlmZ ddlmZmZmZmZmZmZ ddlmZ ddlm Z m!Z!m"Z" ddl#m$Z$m%Z%m&Z&  ej'        d          Z( G d de          Z)dS )zdistutils.command.build_ext

Implements the Distutils 'build_ext' command, for building extension
modules (currently limited to C extensions, should accommodate C++
extensions ASAP).    )annotationsN)Callable)log)	USER_BASE)ClassVar   )newer_group)new_compilershow_compilers)Command)CCompilerErrorCompileErrorDistutilsErrorDistutilsOptionErrorDistutilsPlatformErrorDistutilsSetupError)	Extension)customize_compilerget_config_h_filenameget_python_version)get_platformis_freethreadedis_mingwz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$c                  j   e Zd ZU dZdej         dZddddd e             d	fd
dddez   fddddddez   fddddddddddgZg dZ	de
d <   d!d"d#efgZd$e
d%<   d& Zed'             ZdAd*ZdAd+ZdAd,Zd- Zd. ZdAd/Zd0 Zd1 Zej        d2             ZdAd3Zd4 Zd5 ZdBd8ZdBd9ZdBd:Z dCd>Z!d? Z"dCd@Z#d"S )D	build_extz8build C/C++ extensions (compile/link to build directory)z (separated by 'z'))z
build-lib=bz(directory for compiled extension modules)zbuild-temp=tz1directory for temporary files (build by-products)z
plat-name=pz;platform name to cross-compile for, if supported [default: ])inplaceiziignore build-lib and put compiled extensions into the source directory alongside your pure Python moduleszinclude-dirs=Iz.list of directories to search for header files)zdefine=DzC preprocessor macros to define)zundef=Uz!C preprocessor macros to undefine)z
libraries=lz!external C libraries to link withzlibrary-dirs=Lz.directories to search for external C libraries)zrpath=Rz7directories to search for shared C libraries at runtime)zlink-objects=Oz2extra explicit link objects to include in the link)debuggz'compile/link with debugging information)forcefz2forcibly build everything (ignore file timestamps))z	compiler=czspecify the compiler type)z	parallel=jznumber of parallel build jobs)swig-cppNz)make SWIG create C++ files (default is C))z
swig-opts=Nz!list of SWIG command line options)zswig=Nzpath to the SWIG executable)userNz#add user include, library and rpath)r    r)   r+   r/   r0   zClassVar[list[str]]boolean_optionszhelp-compilerNzlist available compilerszAClassVar[list[tuple[str, str | None, str, Callable[[], object]]]]help_optionsc                ,   d | _         d | _        d | _        d | _        d| _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d S )NF)
extensions	build_lib	plat_name
build_tempr    packageinclude_dirsdefineundef	librarieslibrary_dirsrpathlink_objectsr)   r+   compilerswigswig_cpp	swig_optsr0   parallelselfs    _/srv/django_bis/venv311/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.pyinitialize_optionszbuild_ext.initialize_optionsp   s     
 
 

		    c              #  <  K   |                      d          sdS | j        rdV  dS t          j        dk    rN|                      d          }|                      d          }t          j                            ||          V  dS |                      d          V  dS )z
        Resolve Python's library directory for building extensions
        that rely on a shared Python library.

        See python/cpython#44264 and python/cpython#48686
        Py_ENABLE_SHAREDN.zosbase
platlibdirLIBDIR)get_config_varpython_buildsysplatformospathjoin)	sysconfiginstalled_dirlib_dirs      rG   _python_lib_dirzbuild_ext._python_lib_dir   s       ''(:;; 	F! 	IIIF<5   &44V<<M..|<<G',,}g6666666 **84444444rI   returnNonec           
        ddl m} |                     ddddddd	d
           | j        | j        j        | _        | j        j        | _        |                                }|                    d          }| j	        | j        j	        pg | _	        t          | j	        t                    r)| j	                            t          j                  | _	        t          j        t          j        k    rB| j	                            t          j                            t          j        d                     | j	                            |                    t          j        j                             ||k    r<| j	                            |                    t          j        j                             |                     d           |                     d           | j        g | _        | j        g | _        nCt          | j        t                    r)| j                            t          j                  | _        | j        g | _        nCt          | j        t                    r)| j                            t          j                  | _        t          j        dk    rt7                      s| j                            t          j                            t          j        d                     t          j        t          j        k    rB| j                            t          j                            t          j        d                     | j        r+t          j                            | j        d          | _        n*t          j                            | j        d          | _        | j	                            t          j                            tA                                           | j                            t          j                   | j!        dk    rd}n| j!        dd          }t          j                            t          j        d          }|r t          j                            ||          }| j                            |           t          j"        d d         dk    ru|j#        sT| j                            t          j                            t          j        ddtI                      z   d                     n| j                            d           | j                            | %                    |                     | j&        r+| j&                            d          }d |D             | _&        | j'        r| j'                            d          | _'        | j(        g | _(        n| j(                            d          | _(        | j)        rt          j                            tT          d          }t          j                            tT          d          }t          j        +                    |          r| j	                            |           t          j        +                    |          r4| j                            |           | j                            |           t          | j,        t                    r9	 t[          | j,                  | _,        d S # t\          $ r t_          d           w xY wd S )!Nr   )rX   build)r5   r5   )r7   r7   )r@   r@   )r)   r)   )r+   r+   )rD   rD   )r6   r6   T)plat_specificincluder<   r?   ntlibsDebugReleasewin32   PCbuild   cygwinlibpythonconfigrL   ,c                    g | ]}|d fS )1 ).0symbols     rG   
<listcomp>z.build_ext.finalize_options.<locals>.<listcomp>  s    ???VFC=???rI    zparallel should be an integer)0	distutilsrX   set_undefined_optionsr8   distributionext_packageext_modulesr4   get_python_incr9   
isinstancestrsplitrU   pathseprS   exec_prefixbase_exec_prefixappendrV   rW   extendensure_string_listr<   r=   r>   namer   prefixr)   r7   dirnamer   r6   rT   rR   r   r[   r:   r;   rC   r0   r   isdirrD   int
ValueErrorr   )	rF   rX   
py_includeplat_py_includesuffixnew_libdefinesuser_includeuser_libs	            rG   finalize_optionszbuild_ext.finalize_options   s   ''''''""&($$&		
 		
 		
 <,8DL+7 --//
#222FF$ $ 1 > D"Dd'-- 	D $ 1 7 7
 C CD ?c222$$RW\\#/9%M%MNNN 	  !1!1"'/!B!BCCCj(($$_%:%:27?%K%KLLL,,,/// >!DN$ "D)3// 	D $ 1 7 7
 C CD:DJJ
C(( 	6))"*55DJ
 7d??8::? $$RW\\#/6%J%JKKK#sz11!((c6JF)S)STTTz K"$',,t"H"H"$',,t	"J"J $$RW__5J5L5L%M%MNNN$$S%9::: ~((  +gll3?I>>G 8',,w77$$W--- <x'') 	.!((GLL
E86H6J6J+JH     !((---  !5!5i!@!@AAA ; 	@k'',,G??w???DK
 : 	/))#..DJ>!DNN!^11#66DN 9 	,7<<	9==Lw||Iu55Hw}}\** 7!((666w}}X&& ,!((222
!!(+++dmS)) 	LL #DM 2 2 L L L*+JKKKL	L 	Ls   [   [:c                   | j         sd S | j                                        rb|                     d          }| j                            |                                pg            | j                            |j	                   t          | j        | j        | j        | j                  | _        t          | j                   t           j        dk    r6| j        t'                      k    r| j                            | j                   t           j        dk    r)t+                      r| j                            dd           | j        | j                            | j                   | j        (| j        D ] \  }}| j                            ||           !| j        $| j        D ]}| j                            |           | j        | j                            | j                   | j        | j                            | j                   | j        | j                            | j                   | j         | j        !                    | j                    | "                                 d S )N
build_clib)r@   verbosedry_runr+   rb   Py_GIL_DISABLEDrp   )#r4   rx   has_c_librariesget_finalized_commandr<   r   get_library_namesr=   r   r   r
   r@   r   r   r+   r   rU   r   r6   r   
initializer   define_macror9   set_include_dirsr:   r;   undefine_macroset_librariesset_library_dirsr>   set_runtime_library_dirsr?   set_link_objectsbuild_extensions)rF   r   r   valuemacros        rG   runzbuild_ext.run,  sO     	F
 ,,.. 	<33LAAJN!!*">">"@"@"FBGGG$$Z%:;;; %]LL*	
 
 
 	4=))) 7d??t~??M$$T^444
 7d??00?M&&'8#>>> (M**4+<===;"#{ 8 8e**47777:! 4 4,,U3333>%M''777(M**4+<===:!M224:>>>(M**4+<=== 	rI   c                   t          |t                    st          d          t          |          D ]	\  }}t          |t                    rt          |t
                    rt          |          dk    rt          d          |\  }}t          j        d|           t          |t                    rt                              |          st          d          t          |t                    st          d          t	          ||d                   }dD ]*}|                    |          }|t          |||           +|                    d
          |_        d|v rt          j        d           |                    d          }|rg |_        g |_        |D ]}	t          |	t
                    rt          |	          dv st          d          t          |	          dk    r!|j                            |	d                    kt          |	          dk    r|j                            |	           |||<   d	S )a  Ensure that the list of extensions (presumably provided as a
        command option 'extensions') is valid, i.e. it is a list of
        Extension objects.  We also support the old-style list of 2-tuples,
        where the tuples are (ext_name, build_info), which are converted to
        Extension instances here.

        Raise DistutilsSetupError if the structure is invalid anywhere;
        just returns otherwise.
        z:'ext_modules' option must be a list of Extension instancesr   zMeach element of 'ext_modules' option must be an Extension instance or 2-tuplezvold-style (ext_name, build_info) tuple found in ext_modules for extension '%s' -- please convert to Extension instancezRfirst element of each tuple in 'ext_modules' must be the extension name (a string)zOsecond element of each tuple in 'ext_modules' must be a dictionary (build info)sources)r9   r=   r<   extra_objectsextra_compile_argsextra_link_argsNr>   def_filez9'def_file' element of build info dict no longer supportedmacros)   r   z9'macros' element of build info dict must be 1- or 2-tupler   r   )r|   listr   	enumerater   tuplelenr   warningr}   extension_name_rematchdictgetsetattrruntime_library_dirsdefine_macrosundef_macrosr   )
rF   r4   r!   extext_name
build_infokeyvalr   r   s
             rG   check_extensions_listzbuild_ext.check_extensions_listr  s    *d++ 	%L    
++ G	  G	 FAs#y))  c5)) SXX]])4  
 $' HjK: 	   x-- 2C2I2I(2S2S )<  
 j$// )8   Hj&;<<C 
+ 
+ !nnS))?Cc*** (2~~g'>'>C$Z''WXXX  ^^H--F 8$&!#% # 8 8E&ue44 Uv9M9M1W   5zzQ(//a9999Uq)00777JqMMOG	  G	 rI   c                    |                      | j                   g }| j        D ]}|                    |j                   |S N)r   r4   r   r   )rF   	filenamesr   s      rG   get_source_fileszbuild_ext.get_source_files  sO    ""4?333	 ? 	* 	*CS[))))rI   c                ^                            j                    fd j        D             S )Nc                D    g | ]}                     |j                  S rq   )get_ext_fullpathr   )rr   r   rF   s     rG   rt   z)build_ext.get_outputs.<locals>.<listcomp>  s)    KKKC%%ch//KKKrI   )r   r4   rE   s   `rG   get_outputszbuild_ext.get_outputs  s:     	""4?333
 LKKK4?KKKKrI   c                    |                      | j                   | j        r|                                  d S |                                  d S r   )r   r4   rD   _build_extensions_parallel_build_extensions_serialrE   s    rG   r   zbuild_ext.build_extensions  sR    ""4?333= 	,++-----))+++++rI   c                     j         } j         du rt          j                    }	 ddlm} n# t
          $ r d }Y nw xY w|                                  d S  ||          5  fd j        D             }t           j        |          D ]F\  }} 	                    |          5  |
                                 d d d            n# 1 swxY w Y   G	 d d d            d S # 1 swxY w Y   d S )NTr   )ThreadPoolExecutor)max_workersc                F    g | ]}                     j        |          S rq   )submitbuild_extension)rr   r   executorrF   s     rG   rt   z8build_ext._build_extensions_parallel.<locals>.<listcomp>  s7       ?B 4c::  rI   )rD   rU   	cpu_countconcurrent.futuresr   ImportErrorr   r4   zip_filter_build_errorsresult)rF   workersr   futuresr   futr   s   `     @rG   r   z$build_ext._build_extensions_parallel  s   -=D  lnnG	======= 	 	 	GGG	 ?))+++FG444 	!    FJo  G  99 ! !S..s33 ! !JJLLL! ! ! ! ! ! ! ! ! ! ! ! ! ! !!		! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!sC   . ==$AC#(C	=C#	CC#CC##C'*C'c                    | j         D ]D}|                     |          5  |                     |           d d d            n# 1 swxY w Y   Ed S r   )r4   r   r   )rF   r   s     rG   r   z"build_ext._build_extensions_serial  s    ? 	* 	*C**3// * *$$S)))* * * * * * * * * * * * * * *	* 	*s   AA	A	c              #     K   	 d V  d S # t           t          t          f$ r3}|j        s |                     d|j         d|            Y d }~d S d }~ww xY w)Nzbuilding extension "z
" failed: )r   r   r   optionalwarnr   )rF   r   es      rG   r   zbuild_ext._filter_build_errors   s      	FEEEEE= 	F 	F 	F< IIDSXDDDDEEEEEEEEE	Fs   
 A(AAc                   |j         }|t          |t          t          f          st	          d|j         d          t          |          }|                     |j                  }||j        z   }| j	        s-t          ||d          st          j        d|j                   d S t          j        d|j                   |                     ||          }|j        pg }|j        d d          }|j        D ]}|                    |f           | j                            || j        ||j        | j        ||j                  }|d d          | _        |j        r|                    |j                   |j        pg }|j        p| j                            |          }	| j                            |||                     |          |j        |j         || !                    |          | j        | j        |	
  
         d S )Nz$in 'ext_modules' option (extension 'zD'), 'sources' must be present and must be a list of source filenamesnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension)
output_dirr   r9   r)   extra_postargsdepends)r<   r=   r   r   export_symbolsr)   r7   target_lang)"r   r|   r   r   r   r   sortedr   r   r+   r	   r   r)   infoswig_sourcesr   r   r   r   r@   compiler7   r9   _built_objectsr   r   r   languagedetect_languagelink_shared_objectget_librariesr=   r   get_export_symbols)
rF   r   r   ext_pathr   
extra_argsr   r;   objectsr   s
             rG   r   zbuild_ext.build_extension	  s*   +?*WtUm"D"D?%-sx - - -   //((22CK'
 	:k'8WEE 	:I<chGGGFH.999
 ##GS11  +1r
"111%% 	$ 	$EMM5(####-'')*%K ( 
 
 &aaaj
  	.NN3,---(.B
 <I4=#@#@#I#I((((--)!$!9%22377*  	) 	
 	
 	
 	
 	
rI   c                   g }g }i }| j         rt          j        d           | j         sd| j        v s	d|j        v rd}nd}|D ]{}t          j                            |          \  }}	|	dk    r<|                    |dz   |z              |                    |           |d         ||<   f|                    |           ||s|S | j        p| 	                                }
|
dg}|
                    | j                   | j         r|                    d           | j        s|
                    |j                   |D ];}||         }t          j        d	||           |                     |d
||gz              <|S )zWalk the list of source files in 'sources', looking for SWIG
        interface (.i) files.  Run SWIG on all that are found, and
        return a modified 'sources' list with SWIG source files replaced
        by the generated C (or C++) files.
        z/--swig-cpp is deprecated - use --swig-opts=-c++z-c++z.cppz.cz.i_wrapz-pythonzswigging %s to %sz-o)rB   r   r   rC   rU   rV   splitextr   rA   	find_swigr   r   spawn)rF   r   	extensionnew_sourcesr   swig_targets
target_extsourcerN   r   rA   swig_cmdtargets                rG   r   zbuild_ext.swig_sourcesZ  s     = 	KKIJJJ M	$.(()---JJJ 	+ 	+F'**622KT3d{{""4'>J#>???##F+++'22V$$""6**** 	y,DNN,,)$'''= 	$OOF### ~ 	1OOI/000" 	: 	:F!&)FH(&&999JJx4"889999rI   c                   t           j        dk    rdS t           j        dk    rMdD ]H}t           j                            d| d          }t           j                            |          r|c S IdS t          dt           j         d          )	zReturn the name of the SWIG executable.  On Unix, this is
        just "swig" -- it should be in the PATH.  Tries a bit harder on
        Windows.
        posixrA   rb   )z1.3z1.2z1.1zc:\swigzswig.exez;I don't know how to find (much less run) SWIG on platform '')rU   r   rV   rW   isfiler   )rF   versfns      rG   r   zbuild_ext.find_swig  s    
 7g6W__ . " "W\\"3T"3"3Z@@7>>"%% III "z(XbgXXX  rI   r   r}   c                *   |                      |          }|                    d          }|                     |d                   }| j        sDt	          j        j        |dd         |gz    }t          j                            | j        |          S d                    |dd                   }|                     d          }t          j        	                    |
                    |                    }t          j                            ||          S )zReturns the path of the filename for a given extension.

        The file is located in `build_lib` or directly in the package
        (inplace option).
        rL   r   Nr   build_py)get_ext_fullnamer~   get_ext_filenamer    rU   rV   rW   r5   r   abspathget_package_dir)rF   r   fullnamemodpathfilenamer8   r
  package_dirs           rG   r   zbuild_ext.get_ext_fullpath  s     ((22..%%((55| 	: w|WSbS\XJ%>?H7<<999 ((71R4=))--j99gooh&>&>w&G&GHH w||K222rI   c                .    | j         |S | j         dz   |z   S )zSReturns the fullname of a given extension name.

        Adds the `package.` prefixNrL   )r8   )rF   r   s     rG   r  zbuild_ext.get_ext_fullname  s#     <O<#%00rI   c                z    ddl m} |                    d          } |d          }t          j        j        | |z   S )zConvert the name of an extension (eg. "foo.bar") into the name
        of the file from which it will be loaded (eg. "foo/bar.so", or
        "foo\bar.pyd").
        r   rQ   rL   
EXT_SUFFIX)rX   rQ   r~   rU   rV   rW   )rF   r   rQ   r   
ext_suffixs        rG   r  zbuild_ext.get_ext_filename  sJ    
 	/.....>>#&&#^L11
w|X&33rI   r   r   	list[str]c                `   |                      |          }	 |                    d           d|z   }nO# t          $ rB d|                    d                              dd                              d          z   }Y nw xY wd|z   }||j        vr|j                            |           |j        S )a  Return the list of symbols that a shared extension has to
        export.  This either uses 'ext.export_symbols' or, if it's not
        provided, "PyInit_" + module_name.  Only relevant on Windows, where
        the .pyd file (DLL) must export the module "PyInit_" function.
        ascii_U_punycode   -   _PyInit)_get_module_name_for_symbolencodeUnicodeEncodeErrorreplacedecoder   r   )rF   r   r   r   initfunc_names        rG   r   zbuild_ext.get_export_symbols  s     //44	  KK    4ZFF " 	X 	X 	XDKK
33;;D$GGNNwWWWFFF	X
 !6) 222%%m444!!s   2 A	A>=A>c                    |j                             d          }|d         dk    rt          |          dk    r|d         S |d         S )NrL   r   __init__r   )r   r~   r   )rF   r   partss      rG   r!  z%build_ext._get_module_name_for_symbol  sH     s##9
""s5zzQ9RyrI   c                .   t           j        dk    rgt                      sYddlm} t          | j        |          s=d}| j        r|dz   }|t           j        dz	  t           j        dz	  dz  fz  }|j	        |gz   S ndd	l
m} d
} |d          rjt          t           d          rd}nRt           j        dk    st                      rd}n1dt          j        v r# |d          dk    rd}n |d          dk    rd}|r |d          }|j	        d|z   gz   S |j	        S )zReturn the list of libraries to link against when building a
        shared extension.  On most platforms, this is just 'ext.libraries';
        on Windows, we add the Python library (eg. python20.dll).
        rf   r   )MSVCCompilerz
python%d%d_d         r  FrK   getandroidapilevelTrj   _PYTHON_HOST_PLATFORMANDROID_API_LEVELr   MACHDEP	LDVERSIONrl   )rS   rT   r   _msvccompilerr,  r|   r@   r)   
hexversionr<   rX   rQ   hasattrrU   environ)rF   r   r,  template	pythonlibrQ   link_libpython	ldversions           rG   r   zbuild_ext.get_libraries  sq    <7""8::"444444dm\:: 
3': /'$H$Nb(^r)T1( 	 }	{22
3( 322222"N~011 .3 455 	.%)NN\X---%)NN,
::%~&9::a??)-'	22h>>)- >*N;77	}9(<'===}rI   )r\   r]   )r   r}   r\   r}   )r   r   r\   r  )$__name__
__module____qualname__descriptionrU   r   sep_byr   user_optionsr1   __annotations__r   r2   rH   staticmethodr[   r   r   r   r   r   r   r   r   
contextlibcontextmanagerr   r   r   r   r   r  r  r   r!  r   rq   rI   rG   r   r   &   s        LK( /
...FGQ+%+ + +	
	
 <vE	

 	<<@<vE	

 	STAL7;GA6=K&LP, , ,O     
$ :NKWL      0 5 5 \50IL IL IL ILVD  D  D  D LV  V  V  V p  	L 	L 	L, , , ,! ! !** * *
 F F FO
 O
 O
 O
b6 6 6p  03 3 3 361 1 1 1	4 	4 	4 	4" " " "*  5 5 5 5 5 5rI   r   )*__doc__
__future__r   rF  rU   rerS   collections.abcr   distutils._logr   siter   typingr   	_modifiedr	   	ccompilerr
   r   corer   errorsr   r   r   r   r   r   r   r   rX   r   r   r   utilr   r   r   r   r   r   rq   rI   rG   <module>rT     s    # " " " " "     				 				 



 $ $ $ $ $ $                   # # # # # # 4 4 4 4 4 4 4 4                      " ! ! ! ! ! U U U U U U U U U U : : : : : : : : : : BJUVV F F F F F F F F F FrI   