U +a{@sdZddlZddlZddlZddlZddlmZddlTddlm Z m Z ddlm Z ddl m Z ddlmZdd lmZdd lmZd d lmZdd lmZedZddZGdddeZdS)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)Command)*)customize_compilerget_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)Nrshow_compilers)distutils.ccompilerrrrO/tmp/pip-install-1bd_1mtk/setuptools/setuptools/_distutils/command/build_ext.pyrs rc@seZdZdZdejZdddddefdd d d efd d ddddefddddddddddgZddddd gZ d!d"d#e fgZ d$d%Z d&d'Z d(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zejd6d7Zd8d9Zd:d;Zdd?Zd@dAZdBdCZdDdEZdFdGZd"S)H 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))inplaceiziignore 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)debuggz'compile/link with debugging information)forcefz2forcibly 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 rpathrr r"r&r'z help-compilerNzlist available compilerscCsd|_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_temprpackage include_dirsdefineundef libraries library_dirsrpath link_objectsr r"compilerswigswig_cpp swig_optsr'parallelselfrrrinitialize_optionsks*zbuild_ext.initialize_optionsc Csddlm}|ddddddd d |jdkr8|jj|_|jj|_|}|jd d }|j dkrn|jj pjg|_ t |j t r|j t j|_ tjtjkr|j t jtjd |j | t jj||kr|j | t jj|d|d|jdkrg|_|jdkrg|_nt |jt r:|j t j|_|jdkrNg|_nt |jt rl|j t j|_t jdkrh|jt jtjdtjtjkr|jt jtjd|jrt j|jd|_nt j|jd|_|j t jtt tdd}|r|j||j!dkr*d}n|j!dd}t jtjd}|r\t j||}|j|tj"dddkrtj#$t jtjdr|jt jtjddt%dn |jd|&dr|j's|j|&d n |jd|j(r|j( d!}d"d#|D|_(|j)r4|j) d!|_)|j*dkrHg|_*n|j* d$|_*|j+rt jt,d }t jt,d} t j-|r|j |t j-| r|j| |j| t |j.t rzt/|j.|_.Wnt0k rt1d%YnXdS)&Nr) sysconfigbuild)r)r))r+r+)r4r4)r r )r"r")r8r8)r*r*r ) plat_specificincluder0r3ntZlibsZDebugZRelease_homewin32ZPCbuildcygwinbinlibpythonconfig.Py_ENABLE_SHAREDLIBDIR,cSsg|] }|dfqS)1r).0symbolrrr sz.build_ext.finalize_options.. zparallel should be an integer)2 distutilsr<set_undefined_optionsr, distribution ext_package ext_modulesr(get_python_incr- isinstancestrsplitospathsepsys exec_prefixbase_exec_prefixappendpathjoinextendensure_string_listr0r1r2nameprefixr r+dirnamergetattrr*platform executable startswithrget_config_var python_buildr.r/r7r'r isdirr8int ValueErrorDistutilsOptionError) r:r<Z py_includeZplat_py_include _sys_homesuffixZnew_libZdefinesZ user_includeZuser_librrrfinalize_optionss                           zbuild_ext.finalize_optionscCsjddlm}|jsdS|jrL|d}|j|p:g|j |j ||j |j |j|jd|_ t|j tjdkr|jtkr|j |j|jdk r|j |j|jdk r|jD]\}}|j ||q|jdk r|jD]}|j |q|jdk r|j |j|j dk r*|j |j |jdk rD|j |j|j dk r^|j !|j |"dS)Nr) new_compiler build_clib)r4verbosedry_runr"r@)#rrvr(rUhas_c_librariesget_finalized_commandr0rdZget_library_namesr1rarwr4rxryr"rr\rfr*r Z initializer-Zset_include_dirsr.Z define_macror/Zundefine_macroZ set_librariesZset_library_dirsr2Zset_runtime_library_dirsr3Zset_link_objectsbuild_extensions)r:rvrwrfvaluemacrorrrruns@            z build_ext.runc Csvt|tstdt|D]T\}}t|tr0qt|trFt|dkrNtd|\}}td|t|t rvt |s~tdt|t stdt||d}dD]"}| |}|d k rt|||q| d |_d |krtd | d }|rhg|_g|_|D]b} t| tr"t| dks*tdt| dkrJ|j| dnt| dkr|j| q|||<qd S)aEnsure 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 instanceszMeach 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_objectsextra_compile_argsextra_link_argsNr2Zdef_filez9'def_file' element of build info dict no longer supportedmacros)r rz9'macros' element of build info dict must be 1- or 2-tupler r)rYlistDistutilsSetupError enumeratertuplelenr warnrZextension_name_rematchdictgetsetattrruntime_library_dirs define_macros undef_macrosra) r:r(rextext_nameZ build_infokeyvalrr~rrrcheck_extensions_listWs^        zbuild_ext.check_extensions_listcCs,||jg}|jD]}||jq|SN)rr(rdr)r: filenamesrrrrget_source_filess   zbuild_ext.get_source_filescCs2||jg}|jD]}|||jq|Sr)rr(raget_ext_fullpathrf)r:outputsrrrr get_outputss   zbuild_ext.get_outputscCs(||j|jr|n|dSr)rr(r8_build_extensions_parallel_build_extensions_serialr9rrrr|s  zbuild_ext.build_extensionsc sj}jdkrt}zddlm}Wntk r@d}YnX|dkrVdS||dPfddjD}tj|D]&\}} || W5QRXqW5QRXdS)NTr)ThreadPoolExecutor) max_workerscsg|]}j|qSr)Zsubmitbuild_extension)rOrexecutorr:rrrQsz8build_ext._build_extensions_parallel..) r8r\ cpu_countconcurrent.futuresr ImportErrorrr(zip_filter_build_errorsresult)r:workersrZfuturesrZfutrrrrs"     z$build_ext._build_extensions_parallelc Cs0|jD]$}||||W5QRXqdSr)r(rr)r:rrrrrs  z"build_ext._build_extensions_serialc csTz dVWnDtttfk rN}z |js*|d|j|fW5d}~XYnXdS)Nz"building extension "%s" failed: %s)CCompilerErrorDistutilsError CompileErroroptionalrrf)r:rerrrrs zbuild_ext._filter_build_errorsc CsP|j}|dkst|ttfs*td|jt|}||j}||j}|j slt ||dslt d|jdSt d|j|||}|jpg}|jdd}|jD]}||fq|jj||j||j|j ||jd}|dd|_|jr||j|jpg}|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 filenamesnewerz$skipping '%s' extension (up-to-date)zbuilding '%s' extension) output_dirrr-r extra_postargsdepends)r0r1rrexport_symbolsr r+Z target_lang)"rrYrrrrfsortedrrr"rr r info swig_sourcesrrrrar4compiler+r-Z_built_objectsrrdrlanguageZdetect_languageZlink_shared_object get_librariesr1rget_export_symbols) r:rrext_pathr extra_argsrr/ZobjectsrrrrrsX        zbuild_ext.build_extensioncCs$g}g}i}|jrtd|js6d|jks6d|jkrI don't know how to find (much less run) SWIG on platform '%s'N)r\rfrbrcisfileDistutilsPlatformError)r:versfnrrrris    zbuild_ext.find_swigcCs||}|d}||d}|jsRtjj|dd|g}tj|j|Sd|dd}|d}tj | |}tj||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). rJrNrbuild_py) get_ext_fullnamer[get_ext_filenamerr\rbrcr)r{abspathZget_package_dir)r:rfullnamemodpathfilenamer,r package_dirrrrrs   zbuild_ext.get_ext_fullpathcCs |jdkr|S|jd|SdS)zSReturns the fullname of a given extension name. Adds the `package.` prefixNrJ)r,)r:rrrrrs zbuild_ext.get_ext_fullnamecCs.ddlm}|d}|d}tjj||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"). rrmrJ EXT_SUFFIX)distutils.sysconfigrmr[r\rbrc)r:rrmrZ ext_suffixrrrrs  zbuild_ext.get_ext_filenamecCs||jdd}z|dWn0tk rNd|dddd}Yn Xd|}d |}||jkrv|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. rJrasciiZU_punycode-__ZPyInit)rfr[encodeUnicodeEncodeErrorreplacedecoderra)r:rrfrtZ initfunc_namerrrrs"  zbuild_ext.get_export_symbolscCstjdkr^ddlm}t|j|sd}|jr4|d}|tjd?tjd?d@f}|j|gSndd l m }d }|d rt td rd }ns&