B <ÓFdâxã@sfdZddlmZmZmZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZddlmZddlmZmZddlmZdd lmZmZmZmZmZdd lmZdd lmZ d d „Z!Gd d„de j ƒZ"e #dej$¡j%Z&e #dej$¡j%Z'e #dej$¡j%Z(e #dej$¡j)Z*e #dej$¡j)Z+dd„Z,dd„Z-dd„Z.e #dej$¡j%Z/e #dej$¡j%Z0dd„Z1dS)z Build swig and f2py sources. é)ÚdivisionÚabsolute_importÚprint_functionN)Ú build_ext)Ú newer_groupÚnewer)Ú get_platform)ÚDistutilsErrorÚDistutilsSetupError)Úlog)Úfortran_ext_matchÚ appendpathÚ is_stringÚ is_sequenceÚget_cmd)Ú process_filec Cst d¡}t|dƒ}zlt|dƒ}zRxL|D]D}| |¡}|rb| | d| d¡|| d¡¡¡q(| |¡q(WWd| ¡XWd| ¡XdS)zPSubstitute any occurrence of @foo@ by d['foo'] from source file into target.z@([a-zA-Z_]+)@ÚrÚwz@%s@éN)ÚreÚcompileÚopenÚsearchÚwriteÚreplaceÚgroupÚclose)ÚtargetÚsourceÚdÚvarZfsZftÚlÚm©r#úT/opt/alt/python37/lib64/python3.7/site-packages/numpy/distutils/command/build_src.pyÚ subst_varss     (r%c @sÎeZdZdZdddddddd d g Zd d gZgZd d„Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zgfd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3S)4Ú build_srcz1build sources from SWIG, F2PY files or a function)z build-src=rzdirectory to "build" sources to)z f2py-opts=Nz!list of f2py command line options)zswig=Nzpath to the SWIG executable)z swig-opts=Nz!list of SWIG command line options)zswig-cppNzAmake SWIG create C++ files (default is autodetected from sources))z f2pyflags=Nz3additional flags to f2py (use --f2py-opts= instead))z swigflags=Nz3additional flags to swig (use --swig-opts= instead))ÚforceÚfz2forcibly build everything (ignore file timestamps))ÚinplaceÚiziignore build-lib and put compiled extensions into the source directory alongside your pure Python modulesr'r)cCsdd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_dS)N)Ú extensionsÚpackageÚ py_modulesÚpy_modules_dictr&Ú build_libÚ build_baser'r)Ú package_dirÚ f2pyflagsÚ f2py_optsÚ swigflagsÚ swig_optsÚswig_cppÚswig)Úselfr#r#r$Úinitialize_optionsDs zbuild_src.initialize_optionscCsÈ| dddd¡|jdkr$|jj|_|jj|_|jjp8g|_|jjpFg|_|jjpTg|_|j dkrdt ƒt j dd…f}t j |jd|¡|_ i|_|jr¼|jr®t d ¡n|j|_d|_|jdkrÎg|_nt |j¡|_|jr|jröt d ¡n|j|_d|_|jdkrg|_nt |j¡|_| d ¡}|jdkrD|j|_|jdkrX|j|_xjd D]b}d | dd¡}t||dƒ}|r^t||ƒr t d|¡nt d||f¡t |||ƒq^WdS)NZbuild)r0r0)r/r/)r'r'z.%s-%sréÚsrcz0ignoring --f2pyflags as --f2py-opts already usedz0ignoring --swigflags as --swig-opts already usedr)r7Zswig_optz--Ú_ú-z-both build_src and build_ext define %s optionz+using "%s=%s" option from build_ext command)!Zset_undefined_optionsr,Ú distributionZ ext_packageZ ext_modulesr+Ú librariesr-Ú data_filesr&rÚsysÚversionÚosÚpathÚjoinr0r.r2r3r ÚwarnÚshlexÚsplitr4r5Úget_finalized_commandr)r6rÚgetattrÚinfoÚsetattr)r8Zplat_specifierrÚcÚoÚvr#r#r$Úfinalize_optionsVsV              zbuild_src.finalize_optionscCs&t d¡|js|jsdS| ¡dS)Nr&)r rKr+r?Ú build_sources)r8r#r#r$Úruns  z build_src.runcCsv|jr| d¡j|_| ¡x|jD]}|j|Žq$W|jrb| |j¡x|jD]}| |¡qPW|  ¡|  ¡dS)NZbuild_py) r)rIÚget_package_dirÚbuild_py_modules_sourcesr?Úbuild_library_sourcesr+Zcheck_extensions_listÚbuild_extension_sourcesÚbuild_data_files_sourcesÚbuild_npy_pkg_config)r8Z libname_infoÚextr#r#r$rQ–s   zbuild_src.build_sourcesc CsT|js dSt d¡ddlm}g}x|jD]}t|tƒrJ| |¡q.t|tƒr2|\}}|j r~|  d  |  t j¡¡¡}nt j  |j|¡}dd„|Dƒ}dd„|Dƒ}xj|D]b}|jjdkrÊ||ƒ} n|ƒ} | dk r°t| tƒrî| | ¡q°t| tƒr| | ¡q°tt| ƒƒ‚q°W|||fƒ} | || f¡q.tt|ƒƒ‚q.W||jdd…<dS) Nzbuilding data_files sourcesr)Úget_data_filesÚ.cSsg|]}t|dƒr|‘qS)Ú__call__)Úhasattr)Ú.0r(r#r#r$ú ¹sz6build_src.build_data_files_sources..cSsg|]}t|dƒs|‘qS)r\)r])r^r(r#r#r$r_ºsr)r@r rKÚnumpy.distutils.misc_utilrZÚ isinstanceÚstrÚappendÚtupler)rSrErHrCÚseprDr&Ú__code__Ú co_argcountÚlistÚextendÚ TypeErrorÚrepr) r8rZZnew_data_filesÚdatarÚfilesÚ build_dirZfuncsr(ÚsÚ filenamesr#r#r$rWªs:             z"build_src.build_data_files_sourcescCsÆddl}|\}}}tj |¡}x| ¡D]\}} | ||<q(W|jdkrVtj ||¡} ntj |j||¡} tj tj  |¡d¡} tj | | ¡} tj  | ¡s¤t  | ¡t | ||ƒtj ||¡} | | fS)Nrr) ÚshutilrCrDÚdirnameÚitemsr)rEr&ÚbasenameÚsplitextÚexistsÚmakedirsr%)r8rKÚgdrqÚtemplateÚ install_dirZ subst_dictZ template_dirÚkrOZ generated_dirÚ generatedZgenerated_pathZfull_install_dirr#r#r$Ú_build_npy_pkg_configÎs         zbuild_src._build_npy_pkg_configc CsØt d¡t tdƒ¡}|jdks*| ¡d}i}|jdkrFd}d}nt|dƒrZ|j}d}|rÔxt|j j   ¡D]d\}}|j j |}t j t j |¡|¡}d|i} x0|D](} | | | ¡\} } |j j | | gf¡q¤WqlWdS) Nz(build_src: building npy-pkg config filesZinstallrFr[TÚinstall_libbaseÚprefix)r rKÚcopyrZ finalizedrPr)r]r~r>Zinstalled_pkg_configrsr1rCrDrEÚabspathr}r@rc) r8Z install_cmdZ build_npkgrxZ top_prefixZpkgZinfosZpkg_pathrrrKrzr|r#r#r$rXås*       zbuild_src.build_npy_pkg_configcCsô|js dSt d¡g}xÈ|jD]¾}t|ƒrÔt|ƒdkrÔ|\}}}|jrT| |¡}ntj  |j tjj |  d¡Ž¡}t |dƒr–tj  ||d¡}||ƒ}|dkr q |||fg}||j krÀg|j |<|j ||7<q | |¡q W||jdd…<dS)Nzbuilding py_modules sourcesr:r[r\z.py)r-r rKrÚlenr)rSrCrDrEr&rHr]r.rc)r8Znew_py_modulesrr,Z module_basernrÚmodulesr#r#r$rTs,         z"build_src.build_py_modules_sourcescCstt| dg¡ƒ}|sdSt d|¡| |||f¡}| |||f¡}| |¡\}}|rht d|j|¡||d<dS)NÚsourceszbuilding library "%s" sourcesz#%s - nothing done with h_files = %s)rhÚgetr rKÚgenerate_sourcesÚtemplate_sourcesÚfilter_h_filesr,)r8Zlib_nameÚ build_infor„Úh_filesr#r#r$rUs zbuild_src.build_library_sourcesc Cs*t|jƒ}t d|j¡| |j¡}| d¡}d |dd…¡}|jrT|  |¡|_ |  ||¡}|  ||¡}|  ||¡}| ||¡}| ||¡}| |¡\}}||jkr²g|j|<g}x4|D],}tj tj |¡¡d} | || |f¡q¼W|j||7<| |¡\}} | r t d|| ¡||_dS)Nzbuilding extension "%s" sourcesr[réÿÿÿÿz#%s - nothing done with h_files = %s)rhr„r rKÚnameZget_ext_fullnamerHrEr)rSÚext_target_dirr†r‡Ú swig_sourcesÚ f2py_sourcesÚ pyrex_sourcesÚfilter_py_filesr.rCrDrurtrcrˆ) r8rYr„ÚfullnameZmodpathr,Úpy_filesrƒr(ÚmodulerŠr#r#r$rV6s2            z!build_src.build_extension_sourcesc Csôg}g}x*|D]"}t|ƒr&| |¡q| |¡qW|s<|S|jrRt|ƒsR|j}n:t|ƒrd|d}n|j}tjj|j g|  d¡dd…Ž}|  |¡xX|D]P}|||ƒ}|s°qœt|ƒrÒdd„|Dƒ|  |¡qœt  d|f¡| |¡qœW|S)Nrr[r‹cSsg|]}t d|f¡‘qS)z adding '%s' to sources.)r rK)r^ror#r#r$r_}sz.build_src.generate_sources..z adding '%s' to sources.)rrcr)rrrŒrCrDrEr&rHÚmkpathrir rK) r8r„Ú extensionÚ new_sourcesZ func_sourcesrrnrŒÚfuncr#r#r$r†^s4        zbuild_src.generate_sourcescCs| |dg¡S)Nz.py)Ú filter_files)r8r„r#r#r$r‘…szbuild_src.filter_py_filescCs| |dddg¡S)Nz.hz.hppz.inc)r™)r8r„r#r#r$rˆˆszbuild_src.filter_h_filescCsLg}g}x:|D]2}tj |¡\}}||kr6| |¡q| |¡qW||fS)N)rCrDrurc)r8r„Zextsr—rmrÚbaserYr#r#r$r™‹s  zbuild_src.filter_filescCsfg}t|ƒr*|d d¡}|d d¡}n |j}|j}x(|D]}tj |¡\}}|dkrT|jrrtj |¡} nt |j tj |¡ƒ} |  | ¡tj  | tj  |¡¡} |js¾t|g|| ƒrt|ƒrÞt d| ¡t|ƒ} nt d| ¡t|ƒ} t| dƒ} |  | ¡|  ¡t| ƒrHtj | ¡} | |krHt d| ¡| | ¡| | ¡q>| |¡q>W|S) NrÚdependsÚ include_dirsz.srczfrom_template:> %szconv_template:> %srz adding '%s' to include_dirs.)rr…r›rœrCrDrur)rrr r&r•rErtr'rÚ_f_pyf_ext_matchr rKÚprocess_f_fileÚprocess_c_filerrrÚ_header_ext_matchrc)r8r„r–r—r›rœrršrYÚ target_dirÚ target_fileZoutstrZfidrr#r#r$r‡–s>          zbuild_src.template_sourcesc Csdg}|j d¡d}xJ|D]B}tj |¡\}}|dkrR| ||||¡}| |¡q| |¡qW|S)z@Pyrex not supported; this remains for Cython support (see below)r[r‹z.pyx)rŒrHrCrDruÚgenerate_a_pyrex_sourcerc) r8r„r–r—Úext_namerršrYr¢r#r#r$r»s  zbuild_src.pyrex_sourcescCsgS)zÄPyrex is not supported, but some projects monkeypatch this method. That allows compiling Cython code, see gh-6955. This method will remain here for compatibility reasons. r#)r8ršr¤rr–r#r#r$r£Êsz!build_src.generate_a_pyrex_sourcecCs$g}g}g}i}g}|j d¡d}d} xj|D]`} tj | ¡\} } | dkrr|jrdtj | ¡} nt|jtj | ¡ƒ} tj  | ¡rºt | ƒ}||kr¦t d| ||fƒ‚tj  | |d¡}nt  d| ¡|}d} tj  | |d¡}tj  |¡sJt  d ||f¡tj | ¡} tj  | |d¡}tj  |¡s}tj  | ||¡}tj  |¡rÚt  d|¡| |¡qÚW||S) Nr[r‹rz.pyfz;mismatch of extension names: %s provides %r but expected %rzmodule.cz. source %s does not exist: skipping f2py'ing.rzd target %s does not exist: Assuming %smodule.c was generated with "build_src --inplace" command.z %r missingz& Yes! Using %r as up-to-date target.Ú f2py_optionszf2py options: %szConly one .pyf file is allowed per extension module but got more: %rrzf2py: %sz --build-dirz+ skipping '%s' f2py interface (up-to-date)z f2py:> %sz--lowerz-mz3 skipping f2py fortran files for '%s' (up-to-date)z!f2py target file %r not generatedzfortranobject.czfortranobject.hz adding '%s' to sources.z adding '%s' to include_dirs.r;zf2py target_c file %r not foundzf2py target_h file %r not found)z-f2pywrappers.fz-f2pywrappers2.f90)'rŒrHrCrDrur)rrr r&ÚisfileÚget_f2py_modulenamer rEr ÚdebugrFrKrcr r•r¥r3r>r?rir…r‚r›r'rZ numpy.f2pyZf2pyZrun_mainrr rœÚ__file__rZ copy_file)r8r„r–r—rZ f_sourcesZ f2py_targetsÚ target_dirsr¤Z skip_f2pyrršrYr¡rŒr¢rr¥r‰r›ZnumpyrnZtarget_cZtarget_hZsource_cZsource_hZname_extÚfilenamer#r#r$rÒsà                           zbuild_src.f2py_sourcesc Csœg}g}i}g}g}d}d|jkr8d} d} |j d¡n|jrHd} d} nd} d} d} |j d¡d} x|D]} tj | ¡\}}|d krt|jr¦tj  |¡}|j }nt |j tj  |¡ƒ}|}tj  | ¡r¨t| ƒ}|| d d…krþtd | || d d…fƒ‚| dkrt| ƒ} | dk} nlt| ƒ}|dkr@t d | | f¡nF| |kr†t d | | |f¡|dkrxt d¡d} nt d| ¡| rd}tj |d||f¡}nˆt d| ¡| d d…}d } t||ƒ}tj  |¡s0t d||f¡tj  |¡}t||ƒ}tj  |¡s"td|fƒ‚t d|¡| |¡| |¡| tj ||d¡¡| | ¡|d|| <ql| | ¡qlW|sŒ|S| rš||Sx|D]}| |¡q W|jpÂ| ¡}|dg|j}| râ| d¡x|jD]}| d|¡qêWx|D]ˆ} || }| g|j}|js6t||dƒr€t dtj |¡| rRdpTd| f¡| ||jd|d|| g¡nt  d| ¡qW||S) Nz.cz-c++zc++TFrr[r‹z.irz;mismatch of extension names: %s provides %r but expected %rz>source %r does not define swig target, assuming %s swig targetz0expected %r but source %r defines %r swig targetzAresetting swig target to c++ (some targets may have .c extension)z$assuming that %r has c++ swig targetz.cppz %s_wrap%sz. source %s does not exist: skipping swig'ing.zi target %s does not exist: Assuming %s_wrap.{c,cpp} was generated with "build_src --inplace" command.z %r missingz& Yes! Using %r as up-to-date target.z.pyz-pythonz-Irz%s: %sz++Úz-oz-outdirz+ skipping '%s' swig interface (up-to-date))!r5Úremover6rŒrHrCrDrur)rrrr r&r¦Úget_swig_modulenamer Úget_swig_targetr rFrEÚ_find_swig_targetrcr•r7Z find_swigrœr›r'rrKrtZspawnr¨)r8r„r–r—rŽZ swig_targetsrªr“Z target_extÚtypZis_cppZ skip_swigr¤rršrYr¡Z py_target_dirrŒZtyp2r¢rr7Zswig_cmdrr›r#r#r$rŽ\s¸                       zbuild_src.swig_sourcesN)Ú__name__Ú __module__Ú __qualname__Ú descriptionZ user_optionsZboolean_optionsZ help_optionsr9rPrRrQrWr}rXrTrUrVr†r‘rˆr™r‡rr£rrŽr#r#r#r$r&.s@:$(' % r&z".*[.](f90|f95|f77|for|ftn|f|pyf)\Zz.*[.](inc|h|hpp)\ZzQ\s*%module\s*(.*\(\s*package\s*=\s*"(?P[\w_]+)".*\)|)\s*(?P[\w_]+)z-[*]-\s*c\s*-[*]-z-[*]-\s*c[+][+]\s*-[*]-cCs:t|dƒ}d}| ¡}t|ƒr"d}t|ƒr.d}| ¡|S)Nrzc++rM)rÚreadlineÚ_has_cpp_headerÚ _has_c_headerr)rr(ÚresultÚliner#r#r$r¯×s r¯cCs@t|dƒ}d}x$|D]}t|ƒ}|r| d¡}PqW| ¡|S)NrrŒ)rÚ_swig_module_name_matchrr)rr(rŒrºr"r#r#r$r®âs   r®cCs6x0dD](}tj |d||f¡}tj |¡rPqW|S)N)z.cppz.cz %s_wrap%s)rCrDrEr¦)r¡rŒrYrr#r#r$r°ís   r°z%\s*python\s*module\s*(?P[\w_]+)z4\s*python\s*module\s*(?P[\w_]*?__user__[\w_]*)cCsHd}t|ƒ}x.|D]&}t|ƒ}|rt|ƒr,q| d¡}PqW| ¡|S)NrŒ)rÚ_f2py_module_name_matchÚ_f2py_user_module_name_matchrr)rrŒr(rºr"r#r#r$r§ûs  r§)2Ú__doc__Z __future__rrrrCrrArGr€Zdistutils.commandrZdistutils.dep_utilrrZdistutils.utilrZdistutils.errorsr r Znumpy.distutilsr r`r r rrrZnumpy.distutils.from_templaterržZnumpy.distutils.conv_templaterŸr%r&rÚIÚmatchrr r»rr¸r·r¯r®r°r¼r½r§r#r#r#r$ÚsF     %