o ¯)»aÃ{ã@sÂdZddlZddlZddlZddlZddlmZddlTddlm Z m Z ddlm Z ddl m Z ddlmZdd lmZdd lmZd d lmZdd lmZe d¡Zdd„ZGdd„deƒZdS)z¶distutils.command.build_ext Implements the Distutils 'build_ext' command, for building extension modules (currently limited to C extensions, should accommodate C++ extensions ASAP).éN)ÚCommand)Ú*)Úcustomize_compilerÚget_python_version)Úget_config_h_filename)Ú newer_group)Ú Extension)Ú get_platform)Úlogé)Ú py37compat)Ú USER_BASEz3^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$cCsddlm}|ƒdS)Nr©Úshow_compilers)Údistutils.ccompilerrr©rúZ/opt/alt/python310/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.pyrs  rc@seZdZdZdejZdddddeƒfdd d d efd d ddddefddddddddddgZgd¢Z ddde fgZ d d!„Z d"d#„Z d$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zejd2d3„ƒZd4d5„Zd6d7„Zd8d9„Zd:d;„Zdd?„Zd@dA„ZdBdC„ZdS)DÚ build_extz8build C/C++ extensions (compile/link to build directory)z (separated by '%s'))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: %s))Ú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)zdefine=ÚDzC preprocessor macros to define)zundef=Ú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)zrpath=Ú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=Úczspecify the compiler type)z parallel=Újznumber of parallel build jobs)úswig-cppNz)make SWIG create C++ files (default is C))z swig-opts=Nz!list of SWIG command line options)zswig=Nzpath to the SWIG executable)ÚuserNz#add user include, library and rpath)rr r"r&r'z help-compilerNzlist available compilerscCs‚d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_dS)Nr)Ú extensionsÚ build_libÚ plat_nameÚ build_temprÚpackageÚ include_dirsÚdefineÚundefÚ librariesÚ library_dirsÚrpathÚ link_objectsr r"ÚcompilerÚswigÚswig_cppÚ swig_optsr'Úparallel©ÚselfrrrÚinitialize_optionsks* zbuild_ext.initialize_optionsc CsØddlm}| ddddddd d ¡|jdur|jj|_|jj|_| ¡}|jd d }|j dur7|jj p5g|_ t |j t ƒrE|j   t j¡|_ tjtjkrW|j  t j tjd ¡¡|j  |  t jj¡¡||krq|j  |  t jj¡¡| d¡| d¡|jdurƒg|_|jdurŒg|_nt |jt ƒrš|j  t j¡|_|jdur£g|_nt |jt ƒr±|j  t j¡|_t jdkr-|j t j tjd¡¡tjtjkrÕ|j t j tjd¡¡|jrât j |jd¡|_n t j |jd¡|_|j  t j tƒ¡¡t tddƒ}|r|j |¡|j!dkrd}n|j!dd…}t j tjd¡}|r't j ||¡}|j |¡tj"dd…dkrS|j#sM|j t j tjddt$ƒd¡¡n|j d¡| %d¡rm|j#sg|j | %d¡¡n|j d¡|j&r|j&  d ¡}d!d"„|Dƒ|_&|j'rŠ|j'  d ¡|_'|j(dur”g|_(n|j(  d#¡|_(|j)rÍt j t*d ¡}t j t*d¡} t j +|¡rº|j  |¡t j +| ¡rÍ|j | ¡|j | ¡t |j,t ƒrêz t-|j,ƒ|_,WdSt.yét/d$ƒ‚wdS)%Nr)Ú sysconfigZbuild)r)r))r+r+)r4r4)r r )r"r")r8r8)r*r*r )Z plat_specificZincluder0r3ÚntZlibsZDebugZReleaseÚ_homeÚwin32éZPCbuildéÚcygwinÚlibÚpythonZconfigÚ.ÚPy_ENABLE_SHAREDZLIBDIRú,cSsg|]}|df‘qS)Ú1r)Ú.0ZsymbolrrrÚ úsz.build_ext.finalize_options..ú zparallel should be an integer)0Ú distutilsr<Zset_undefined_optionsr,Ú distributionZ ext_packageZ ext_modulesr(Zget_python_incr-Ú isinstanceÚstrÚsplitÚosÚpathsepÚsysÚ exec_prefixÚbase_exec_prefixÚappendÚpathÚjoinÚextendZensure_string_listr0r1r2ÚnameÚprefixr r+ÚdirnamerÚgetattrr*ÚplatformZ python_buildrÚget_config_varr.r/r7r'r Úisdirr8ÚintÚ ValueErrorZDistutilsOptionError) r:r<Z py_includeZplat_py_includeZ _sys_homeÚsuffixZnew_libZdefinesZ user_includeZuser_librrrÚfinalize_optionsƒs´ ù       ÿ             þ        ÿýzbuild_ext.finalize_optionscCsbddlm}|js dS|j ¡r&| d¡}|j | ¡pg¡|j   |j ¡||j |j |j|jd|_ t|j ƒtjdkrJ|jtƒkrJ|j  |j¡|jdurV|j  |j¡|jdurj|jD] \}}|j  ||¡q^|jdur{|jD]}|j  |¡qr|jdur‡|j  |j¡|j dur“|j  |j ¡|jdurŸ|j  |j¡|j dur«|j  !|j ¡| "¡dS)Nr)Ú new_compilerÚ build_clib)r4ÚverboseÚdry_runr"r=)#rrer(rMZhas_c_librariesÚget_finalized_commandr0rYZget_library_namesr1rVrfr4rgrhr"rrQrZr*r Z initializer-Zset_include_dirsr.Z define_macror/Zundefine_macroZ set_librariesZset_library_dirsr2Zset_runtime_library_dirsr3Zset_link_objectsÚbuild_extensions)r:rerfrZÚvalueÚmacrorrrÚruns@   ý          z build_ext.runc Csht|tƒs tdƒ‚t|ƒD]¤\}}t|tƒrq t|tƒr"t|ƒdkr&tdƒ‚|\}}t d|¡t|t ƒr:t   |¡s>tdƒ‚t|t ƒsGtdƒ‚t||dƒ}dD]}|  |¡}|d urat|||ƒqP|  d ¡|_d |vrqt d ¡|  d ¡}|r­g|_g|_|D],} t| tƒrt| ƒdvs‘tdƒ‚t| ƒdkr |j | d¡q€t| ƒdkr¬|j | ¡q€|||<q 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 instancesé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)r-r1r0Ú extra_objectsÚextra_compile_argsÚextra_link_argsNr2Zdef_filez9'def_file' element of build info dict no longer supportedÚmacros)r rnz9'macros' element of build info dict must be 1- or 2-tupler r)rNÚlistÚDistutilsSetupErrorÚ enumeraterÚtupleÚlenr ÚwarnrOÚextension_name_reÚmatchÚdictÚgetÚsetattrÚruntime_library_dirsÚ define_macrosÚ undef_macrosrV) r:r(rÚextÚext_nameZ build_infoÚkeyÚvalrsrlrrrÚcheck_extensions_listWsd ÿ ÿþ ÿÿ ÿ  €   ÿ   € Âzbuild_ext.check_extensions_listcCs,| |j¡g}|jD]}| |j¡q |S©N)r†r(rYro)r:Ú filenamesr‚rrrÚget_source_files¥s  zbuild_ext.get_source_filescCs2| |j¡g}|jD] }| | |j¡¡q |Sr‡)r†r(rVÚget_ext_fullpathrZ)r:Zoutputsr‚rrrÚ get_outputs®s  zbuild_ext.get_outputscCs*| |j¡|jr| ¡dS| ¡dSr‡)r†r(r8Ú_build_extensions_parallelÚ_build_extensions_serialr9rrrrj¼s   zbuild_ext.build_extensionsc sâˆj}ˆjdur t ¡}zddlm}Wn tyd}Ynw|dur*ˆ ¡dS||d8‰‡‡fdd„ˆjDƒ}tˆj|ƒD]\}}ˆ  |¡ |  ¡Wdƒn1sYwYqAWdƒdS1sjwYdS)NTr)ÚThreadPoolExecutor)Ú max_workerscsg|] }ˆ ˆj|¡‘qSr)ZsubmitÚbuild_extension)rIr‚©Úexecutorr:rrrJÒsÿz8build_ext._build_extensions_parallel..) r8rQÚ cpu_countÚconcurrent.futuresrŽÚ ImportErrorrr(ÚzipÚ_filter_build_errorsÚresult)r:ÚworkersrŽZfuturesr‚Zfutrr‘rrŒÄs,  ÿ  ÿ  ÿ€ÿ"ýz$build_ext._build_extensions_parallelc CsD|jD]}| |¡ | |¡Wdƒn1swYqdSr‡)r(r—r)r:r‚rrrrØs   ÿ€ÿz"build_ext._build_extensions_serialc csXzdVWdStttfy+}z|js‚| d|j|f¡WYd}~dSd}~ww)Nz"building extension "%s" failed: %s)ZCCompilerErrorZDistutilsErrorZ CompileErrorZoptionalryrZ)r:r‚Úerrrr—Ýs€ ÿ€ýzbuild_ext._filter_build_errorsc CsL|j}|dust|ttfƒstd|jƒ‚t|ƒ}| |j¡}||j}|j s6t ||dƒs6t   d|j¡dSt   d|j¡| ||¡}|jpGg}|jdd…}|jD]}| |f¡qR|jj||j||j|j ||jd}|dd…|_|jr|| |j¡|jp€g}|jp‰|j |¡} |jj||| |¡|j|j || !|¡|j |j| d dS)Nzjin 'ext_modules' option (extension '%s'), 'sources' must be present and must be a list of source filenamesZnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension)Z output_dirrsr-r Úextra_postargsÚdepends)r0r1rr›Úexport_symbolsr r+Z target_lang)"rorNrtrwrurZÚsortedrŠrœr"rr r ÚinfoÚ swig_sourcesrqr€rrVr4Úcompiler+r-Z_built_objectsrprYrrÚlanguageZdetect_languageZlink_shared_objectÚ get_librariesr1rÚget_export_symbols) r:r‚roÚext_pathrœZ extra_argsrsr/Zobjectsr¢rrrrçsVþÿ     ú    ÷zbuild_ext.build_extensioncCs$g}g}i}|jrt d¡|jsd|jvsd|jvrd}nd}|D](}tj |¡\}} | dkrE| |d|¡| |¡|d||<q"| |¡q"|sO|S|jpU|  ¡} | dg} |   |j¡|jrh|  d¡|jsv|jD]} |  | ¡qn|D]}||} t  d || ¡|  | d | |g¡qx|S) züWalk 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Ú_wrapéÿÿÿÿz-pythonzswigging %s to %sz-o) r6r ryr7rQrWÚsplitextrVr5Ú find_swigrYrŸZspawn)r:roÚ extensionZ new_sourcesr Z swig_targetsZ target_extÚsourceÚbaser‚r5Zswig_cmdÚoÚtargetrrrr 3s@ ÿ      zbuild_ext.swig_sourcescCsZtjdkrdStjdkr&dD]}tj d|d¡}tj |¡r#|SqdStdtjƒ‚)z›Return the name of the SWIG executable. On Unix, this is just "swig" -- it should be in the PATH. Tries a bit harder on Windows. Úposixr5r=)z1.3z1.2z1.1z c:\swig%szswig.exez>I don't know how to find (much less run) SWIG on platform '%s')rQrZrWrXÚisfileZDistutilsPlatformError)r:ZversÚfnrrrr©is   ÿÿÿzbuild_ext.find_swigcCsŽ| |¡}| d¡}| |d¡}|js)tjj|dd…|gŽ}tj |j|¡Sd |dd…¡}| d¡}tj  |  |¡¡}tj ||¡S)z¡Returns the path of the filename for a given extension. The file is located in `build_lib` or directly in the package (inplace option). rEr§NrÚbuild_py) Úget_ext_fullnamerPÚget_ext_filenamerrQrWrXr)riÚabspathZget_package_dir)r:rƒÚfullnameÚmodpathÚfilenamer,r²Z package_dirrrrrŠs   zbuild_ext.get_ext_fullpathcCs|jdur|S|jd|S)zSReturns the fullname of a given extension name. Adds the `package.` prefixNrE)r,)r:rƒrrrr³œs zbuild_ext.get_ext_fullnamecCs.ddlm}| d¡}|dƒ}tjj|Ž|S)z¦Convert 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©r_rEZ EXT_SUFFIX)Údistutils.sysconfigr_rPrQrWrX)r:rƒr_r¥Z ext_suffixrrrr´¥s  zbuild_ext.get_ext_filenamecCsz|j d¡d}z| d¡Wnty&d| d¡ dd¡ d¡}Ynwd|}d |}||jvr:|j |¡|jS) aReturn 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. rEr§ÚasciiZU_Zpunycodeó-ó_Ú_ZPyInit)rZrPÚencodeÚUnicodeEncodeErrorÚreplaceÚdecoderrV)r:r‚rZrcZ initfunc_namerrrr¤¯s  ÿ  zbuild_ext.get_export_symbolscCsìtjdkr/ddlm}t|j|ƒs.d}|jr|d}|tjd?tjd?d@f}|j|gSn@dd l m }d }|d ƒrat td ƒrCd }ntjdkrKd }ndt j vra|dƒdkrYd }n|dƒdkrad }|ro|dƒ}|jd|gS|jt ¡S)zÓReturn 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%dZ_déééÿr¹FrFZgetandroidapilevelTrBZ_PYTHON_HOST_PLATFORMZANDROID_API_LEVELZMACHDEPZ LDVERSIONrD)rSr^Zdistutils._msvccompilerrÃrNr4r Ú hexversionr0rºr_ÚhasattrrQÚenvironr Ú pythonlib)r:r‚rÃÚtemplaterÊr_Zlink_libpythonZ ldversionrrrr£Äs6  ÿ ø      zbuild_ext.get_libraries) Ú__name__Ú __module__Ú __qualname__Ú descriptionrQrRZsep_byr Z user_optionsZboolean_optionsrZ help_optionsr;rdrmr†r‰r‹rjrŒrÚ contextlibÚcontextmanagerr—rr r©rŠr³r´r¤r£rrrrr"sp ÿÿÿÿÙ+ÿÿ@N   L6  r)Ú__doc__rÐrQÚrerSZdistutils.corerZdistutils.errorsrºrrrZdistutils.dep_utilrZdistutils.extensionrZdistutils.utilr rLr Úr Zsiter r¡rzrrrrrrÚs(        ÿ