
    ʨsg|                         d 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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  ej:                  d      Zd Z G d de      Z y)zdistutils.command.build_ext

Implements the Distutils 'build_ext' command, for building extension
modules (currently limited to C extensions, should accommodate C++
extensions ASAP).    N)log)	USER_BASE   )newer_group)Command)CCompilerErrorCompileErrorDistutilsErrorDistutilsOptionErrorDistutilsPlatformErrorDistutilsSetupError)	Extension)customize_compilerget_config_h_filenameget_python_version)get_platformis_mingwz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$c                      ddl m}   |         y )Nr   show_compilers)	ccompilerr   r   s    Z/var/www/html/venv/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.pyr   r   !   s    *    c                   :   e Zd Z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d d!e
fgZd" Zed#        Zd$ Zd% Zd& Zd' Zd( Zd) Zd* Zd+ Zej0                  d,        Zd- Zd. Zd/ Zd0 Zd1 Zd2 Zd3 Z d4 Z!y )5	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help-compilerNzlist available compilersc                 *   d | _         d | _        d | _        d | _        d| _        d | _        d | _        d | _        d | _        d | _	        d | _
        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        y )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    r   initialize_optionszbuild_ext.initialize_optionsk   s     
 
 

		r   c              #   (  K   | j                  d      sy| j                  rd yt        j                  dk(  rE| j                  d      }| j                  d      }t        j
                  j                  ||       y| j                  d       yw)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      r   _python_lib_dirzbuild_ext._python_lib_dir   s      ''(:;!!I<<5  &44V<M..|<G'',,}g66 **844s   BBc           
      &   ddl m} | j                  ddddddd	d
       | j                  | j                  j
                  | _        | j                  j                  | _        |j                         }|j                  d      }| j                  | j                  j                  xs g | _	        t        | j                  t              r.| j                  j                  t        j                        | _	        t        j                   t        j"                  k7  rG| j                  j%                  t        j&                  j)                  t        j                   d             | j                  j+                  |j                  t        j&                  j                               ||k7  rB| j                  j+                  |j                  t        j&                  j                               | j-                  d       | j-                  d       | j.                  g | _        | j0                  g | _        nHt        | j0                  t              r.| j0                  j                  t        j                        | _        | j2                  g | _        nHt        | j2                  t              r.| j2                  j                  t        j                        | _        t        j4                  dk(  rt7               s| j0                  j%                  t        j&                  j)                  t        j                   d             t        j"                  t        j8                  k7  rG| j0                  j%                  t        j&                  j)                  t        j"                  d             | j:                  r0t        j&                  j)                  | j<                  d      | _        n/t        j&                  j)                  | j<                  d      | _        | j                  j%                  t        j&                  j?                  tA                            | j0                  j%                  t        j"                         | jB                  dk(  rd}n| jB                  dd  }t        j&                  j)                  t        j                   d      }|r t        j&                  j)                  ||      }| j0                  j%                  |       t        jD                  d d dk(  r||jF                  sU| j0                  j%                  t        j&                  j)                  t        j8                  ddtI               z   d             n| j0                  j%                  d       | j0                  j+                  | jK                  |             | jL                  r2| jL                  j                  d      }|D cg c]  }|df c}| _&        | jN                  r | jN                  j                  d      | _'        | jP                  g | _(        n | jP                  j                  d      | _(        | jR                  rt        j&                  j)                  tT        d      }t        j&                  j)                  tT        d      }	t        j&                  jW                  |      r| j                  j%                  |       t        j&                  jW                  |	      r6| j0                  j%                  |	       | j2                  j%                  |	       t        | jX                  t              r	 t[        | jX                        | _,        y y c c}w # t\        $ r t_        d       w xY w)!Nr   )rT   build)r3   r3   )r5   r5   )r>   r>   )r)   r)   )r+   r+   )rB   rB   )r4   r4   T)plat_specificincluder:   r=   ntlibsDebugReleasewin32   PCbuild   cygwinlibpythonconfigrH   ,1 zparallel should be an integer)0	distutilsrT   set_undefined_optionsr6   distributionext_packageext_modulesr2   get_python_incr7   
isinstancestrsplitrQ   pathseprO   exec_prefixbase_exec_prefixappendrR   rS   extendensure_string_listr:   r;   r<   namer   prefixr)   r5   dirnamer   r4   rP   rN   r   rW   r8   r9   rA   r0   r   isdirrB   int
ValueErrorr   )
rD   rT   
py_includeplat_py_includesuffixnew_libdefinessymboluser_includeuser_libs
             r   finalize_optionszbuild_ext.finalize_options   sF   '""&($$&		
 <<,,88DL++77 --/
#222F$ $ 1 1 > > D"Dd''- $ 1 1 7 7

 CD ??c222$$RWW\\#//9%MN 	  !1!1"''//!BCj($$_%:%:277??%KL,/ >>!DN$ "D))3/ $ 1 1 7 7

 CD::DJ

C())"**5DJ
 77d?8: $$RWW\\#//6%JK##szz1!!((c6J6JF)STzz"$'',,t"H"$'',,t	"J $$RWW__5J5L%MN$$S%9%9: ~~(  +ggll3??I>G'',,w7$$W- <<x'))!!((GGLL

E86H6J+JH !!((-  !5!5i!@A ;;kk'',G7>?VFC=?DK
 ::))#.DJ>>!DN!^^11#6DN 9977<<	9=Lww||Iu5Hww}}\*!!((6ww}}X&!!((2

!!(+dmmS)L #DMM 2 */ @4  L*+JKKLs   )]6]; ;^c                 P   ddl m} | j                  sy | j                  j	                         rc| j                  d      }| j                  j                  |j                         xs g        | j                  j                  |j                          || j                  | j                  | j                  | j                        | _        t!        | j                         t"        j$                  dk(  r<| j&                  t)               k7  r%| j                  j+                  | j&                         | j,                  %| j                  j/                  | j,                         | j0                  0| j0                  D ]!  \  }}| j                  j3                  ||       # | j4                  ,| j4                  D ]  }| j                  j7                  |        | j                  %| j                  j9                  | j                         | j                  %| j                  j;                  | j                         | j<                  %| j                  j?                  | j<                         | j@                  %| j                  jC                  | j@                         | jE                          y )Nr   )new_compiler
build_clib)r>   verbosedry_runr+   r\   )#r   r   r2   rm   has_c_librariesget_finalized_commandr:   rx   get_library_namesr;   rw   r   r>   r   r   r+   r   rQ   rz   r4   r   
initializer7   set_include_dirsr8   define_macror9   undefine_macroset_librariesset_library_dirsr<   set_runtime_library_dirsr=   set_link_objectsbuild_extensions)rD   r   r   rz   valuemacros         r   runzbuild_ext.run'  s   , 
 ,,.33LAJNN!!*">">"@"FBG$$Z%:%:; %]]LLLL**	
 	4==) 77d?t~~?MM$$T^^4 (MM**4+<+<=;;"#{{ 8e**478::! 4,,U34>>%MM''7(MM**4+<+<=::!MM224::>(MM**4+<+<= 	r   c                    t        |t              st        d      t        |      D ]  \  }}t        |t              rt        |t
              rt        |      dk7  rt        d      |\  }}t        j                  d|       t        |t              rt        j                  |      st        d      t        |t              st        d      t	        ||d         }dD ]#  }|j                  |      }|t        |||       % |j                  d
      |_        d|v rt        j                  d       |j                  d      }|rg |_        g |_        |D ]  }	t        |	t
              rt        |	      dv st        d      t        |	      dk(  r|j"                  j%                  |	d          Xt        |	      dk(  sg|j                   j%                  |	        |||<    y	)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)r7   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   )rq   listr   	enumerater   tuplelenr   warningrr   extension_name_rematchdictgetsetattrruntime_library_dirsdefine_macrosundef_macrosrw   )
rD   r2   r!   extext_name
build_infokeyvalr   r   s
             r   check_extensions_listzbuild_ext.check_extensions_listi  s    *d+%L   
+ H	 FAs#y) c5)SX])4 
 $' HjKK: 	 x-2C2I2I(2S)< 
 j$/)8  Hj&;<C 
+ !nnS)?Cc*
+ (2~~g'>C$Z'WX  ^^H-F$&!#% # 	8E&ue4Uv9M14  5zQ((//a9Uq))007	8  JqMQH	 r   c                     | j                  | j                         g }| j                  D ]  }|j                  |j                          |S N)r   r2   rx   r   )rD   	filenamesr   s      r   get_source_fileszbuild_ext.get_source_files  sF    ""4??3	 ?? 	*CS[[)	*r   c                     | j                  | j                         | j                  D cg c]  }| j                  |j                         c}S c c}w r   )r   r2   get_ext_fullpathrz   rD   r   s     r   get_outputszbuild_ext.get_outputs  s@     	""4??3
 <@??KC%%chh/KKKs   "Ac                     | j                  | j                         | j                  r| j                          y | j	                          y r   )r   r2   rB   _build_extensions_parallel_build_extensions_serialrC   s    r   r   zbuild_ext.build_extensions  s3    ""4??3==++-))+r   c                    | j                   }| j                   du rt        j                         }	 ddlm} || j                          y  |      5 }| j                  D cg c]  }|j                  | j                  |        }}t        | j                  |      D ]/  \  }}| j                  |      5  |j                          d d d        1 	 d d d        y # t
        $ r d }Y w xY wc c}w # 1 sw Y   [xY w# 1 sw Y   y xY w)NTr   )ThreadPoolExecutor)max_workers)rB   rQ   	cpu_countconcurrent.futuresr   ImportErrorr   r2   submitbuild_extensionzip_filter_build_errorsresult)rD   workersr   executorr   futuresfuts          r   r   z$build_ext._build_extensions_parallel  s    --==D llnG	= ?))+G4 	!FJoo?B 4 4c:G   9 !S..s3 !JJL! !!		! 	!  	G	! !	! 	!sG   C C:!#C)/C:3C.
C:C&%C&)C:.C73C::Dc                     | j                   D ]-  }| j                  |      5  | j                  |       d d d        / y # 1 sw Y   :xY wr   )r2   r   r   r   s     r   r   z"build_ext._build_extensions_serial  sK    ?? 	*C**3/ *$$S)* *	** *s	   >A	c              #      K   	 d  y # t         t        t        f$ r8}|j                  s | j	                  d|j
                   d|        Y d }~y d }~ww xY ww)Nzbuilding extension "z
" failed: )r   r
   r	   optionalwarnrz   )rD   r   es      r   r   zbuild_ext._filter_build_errors  sR     	F= 	F<<II,SXXJjDEE	Fs*   A	 AA.AAAAc                    |j                   }|t        |t        t        f      st	        d|j
                   d      t        |      }| j                  |j
                        }||j                  z   }| j                  s.t        ||d      s!t        j                  d|j
                         y t        j                  d|j
                         | j                  ||      }|j                  xs g }|j                   d d  }|j"                  D ]  }|j%                  |f        | j&                  j)                  || j*                  ||j,                  | j                  ||j                        }|d d  | _        |j0                  r|j3                  |j0                         |j4                  xs g }|j6                  xs | j&                  j9                  |      }	| j&                  j;                  ||| j=                  |      |j>                  |j@                  || jC                  |      | j                  | j*                  |	
       y )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   r7   r)   extra_postargsdepends)r:   r;   r   r   export_symbolsr)   r5   target_lang)"r   rq   r   r   r   rz   sortedr   r   r+   r   r   r)   infoswig_sourcesr   r   r   rw   r>   compiler5   r7   _built_objectsr   rx   r   languagedetect_languagelink_shared_objectget_librariesr;   r   get_export_symbols)
rD   r   r   ext_pathr   
extra_argsr   r9   objectsr   s
             r   r   zbuild_ext.build_extension  s   ++?*WtUm"D%6sxxj A- -  /((2CKK'

k'8WEII<chhGHH.9
 ##GS1  ++1r
""1%%% 	$EMM5(#	$ --''))**%KK ( 
 &aj
 NN3,,-((.B
 <<I4==#@#@#I((((-))!$!9!9%2237**  	) 	
r   c                    g }g }i }| j                   rt        j                  d       | j                   sd| j                  v sd|j                  v rd}nd}|D ]k  }t        j
                  j                  |      \  }}	|	dk(  r1|j                  |dz   |z          |j                  |       |d   ||<   [|j                  |       m |s|S | j                  xs | j                         }
|
dg}|j                  | j                         | j                   r|j                  d       | j                  s|j                  |j                         |D ]5  }||   }t        j                  d	||       | j                  |d
||gz          7 |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)r@   r   r   rA   rQ   rR   splitextrw   r?   	find_swigrx   r   spawn)rD   r   	extensionnew_sourcesr   swig_targets
target_extsourcerJ   r   r?   swig_cmdtargets                r   r   zbuild_ext.swig_sourcesR  sw     ==KKIJ MM$..()---JJ 	+F''**62KT3d{""4'>J#>?##F+'22V$""6*	+ yy,DNN,)$'==OOF# ~~OOI//0" 	:F!&)FHH(&&9JJx4"889	:
 r   c                 &   t         j                  dk(  ryt         j                  dk(  rNdD ]H  }t         j                  j                  d| d      }t         j                  j	                  |      sF|c S  y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.
        posixr?   r\   )z1.3z1.2z1.1zc:\swigzswig.exez;I don't know how to find (much less run) SWIG on platform '')rQ   rz   rR   rS   isfiler   )rD   versfns      r   r   zbuild_ext.find_swig  s    
 77gWW_ . "WW\\HTF"3Z@77>>"%I"
 "(  "y+ r   c                    | j                  |      }|j                  d      }| j                  |d         }| j                  sMt	        j
                  j                  |dd |gz    }t        j
                  j                  | j                  |      S dj                  |dd       }| j                  d      }t        j
                  j                  |j                  |            }t        j
                  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).
        rH   r   Nr   build_py)get_ext_fullnamers   get_ext_filenamer    rQ   rR   rS   r3   r   abspathget_package_dir)rD   r   fullnamemodpathfilenamer6   r   package_dirs           r   r   zbuild_ext.get_ext_fullpath  s     ((2..%((5|| ww||WSb\XJ%>?H77<<99 ((71R=)--j9ggooh&>&>w&GH ww||K22r   c                 B    | j                   |S | j                   dz   |z   S )zSReturns the fullname of a given extension name.

        Adds the `package.` prefixrH   )r6   )rD   r   s     r   r   zbuild_ext.get_ext_fullname  s'     <<O<<#%00r   c                 ~    ddl m} |j                  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   rM   rH   
EXT_SUFFIX)rT   rM   rs   rQ   rR   rS   )rD   r   rM   r   
ext_suffixs        r   r  zbuild_ext.get_ext_filename  s7    
 	/>>#&#L1
ww||X&33r   c                 d   |j                   j                  d      d   }	 |j                  d       d|z   }d	|z   }||j                  vr|j                  j                  |       |j                  S # t        $ r6 d|j                  d      j	                  dd      j                  d      z   }Y xw xY w)
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.
        rH   r   ascii_U_punycode   -   _PyInit)rz   rs   encodeUnicodeEncodeErrorreplacedecoder   rw   )rD   r   rz   r   initfunc_names        r   r   zbuild_ext.get_export_symbols  s     xx~~c"2&	  KK  4ZF 6) 2 22%%m4!!! " 	XDKK
3;;D$GNNwWWF	Xs   A0 0<B/.B/c                 \   t         j                  dk(  rt               swddlm} t        | j                  |      sOd}| j                  r|dz   }|t         j                  dz	  t         j                  dz	  dz  fz  }|j                  |gz   S |j                  S dd	l
m} d
} |d      r`t        t         d      rd}nMt         j                  dk(  s
t               rd}n-dt        j                  v r |d      dk7  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).
        r`   r   )MSVCCompilerz
python%d%d_d         r
  FrG   getandroidapilevelTrd   _PYTHON_HOST_PLATFORMANDROID_API_LEVELr   MACHDEP	LDVERSIONrf   )rO   rP   r   _msvccompilerr  rq   r>   r)   
hexversionr:   rT   rM   hasattrrQ   environ)rD   r   r  template	pythonlibrM   link_libpython	ldversions           r   r   zbuild_ext.get_libraries  s    <<7"8:4dmm\:'::'$H$NNb(^^r)T1( 	 }}	{22< }}) 3"N013 45%)N\\X-%)N,

:%&9:a?)-'	2h>)-*;7	}}9(<'===}}r   )"__name__
__module____qualname__descriptionrQ   rt   sep_byr   user_optionsboolean_optionsr   help_optionsrE   staticmethodrW   r   r   r   r   r   r   r   r   
contextlibcontextmanagerr   r   r   r   r   r   r  r   r    r   r   r   r   '   sP   LK(  

|2.FGQ%(+	
	
 <vE	

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

 	STAL7;GA6=K&LP HO 
$ :NKL0 5 50ILV@ DW r	L,!**
 F FO
b6p2361	4"*5r   r   )!__doc__r6  rQ   rerO   distutils._logr   siter   	_modifiedr   corer   errorsr   r	   r
   r   r   r   r   r   rT   r   r   r   utilr   r   r   r   r   r   r8  r   r   <module>rA     sc     	 	 
   #   " U U ) BJJUV u ur   