o 6ay@sRdZddlZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZmZddlmZddlmZmZmZmZmZdd lmZdd lmZd d ZGd d d ejZedej j!Z"edej j!Z#edej j!Z$edej j%Z&edej j%Z'ddZ(ddZ)ddZ*edej j!Z+edej j!Z,ddZ-dS)z Build swig and f2py sources. N) build_ext) newer_groupnewer) get_platform)DistutilsErrorDistutilsSetupError)log)fortran_ext_match appendpath is_string is_sequenceget_cmd) process_filec Cstd}t|dK}t|d-}|D]"}||}|r0||d|d||dq||qWdn1s@wYWddSWddS1sXwYdS)zPSubstitute any occurrence of @foo@ by d['foo'] from source file into target.z@([a-zA-Z_]+)@rwz@%s@N)recompileopensearchwritereplacegroup)targetsourcedvarfsftlmr!C/usr/lib/python3/dist-packages/numpy/distutils/command/build_src.py subst_varss    ( "r#c@seZdZdZgdZgdZgZddZddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZddZgfddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*S)+ 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))forcefz2forcibly build everything (ignore file timestamps))inplaceiziignore build-lib and put compiled extensions into the source directory alongside your pure Python modules) verbose-cfgNzJchange logging level from WARN to INFO which will show all compiler output)r%r'r)cCsjd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_dSN) extensionspackage py_modulespy_modules_dictr$ build_lib build_baser%r' package_dir f2pyflags f2py_opts swigflags swig_optsswig_cppswig verbose_cfgselfr!r!r"initialize_options?s" zbuild_src.initialize_optionscCs|dddd|jdur|jj|_|jj|_|jjpg|_|jjp#g|_|jjp*g|_|j durKdj t gt j ddR}tj|jd||_ i|_|jra|jrZtdn|j|_d|_|jdurjg|_nt|j|_|jr|jr}td n|j|_d|_|jdurg|_nt|j|_|d }|jdur|j|_|jdur|j|_d D].}d |d d}t||d}|rt||rtd|qt d||ft!|||qdS)Nbuild)r0r0)r/r/)r%r%z .{}-{}.{}srcz0ignoring --f2pyflags as --f2py-opts already usedz0ignoring --swigflags as --swig-opts already usedr)r7swig_optz--_-z-both build_src and build_ext define %s optionz+using "%s=%s" option from build_ext command)"set_undefined_optionsr, distribution ext_package ext_modulesr+ librariesr- data_filesr$formatrsys version_infoospathjoinr0r.r2r3rwarnshlexsplitr4r5get_finalized_commandr'r6rgetattrinfosetattr)r:plat_specifierrcovr!r!r"finalize_optionsRs\              zbuild_src.finalize_optionscCs&td|js |js dS|dS)Nr$)rrSr+rF build_sourcesr9r!r!r"runs   z build_src.runcCsn|jr |dj|_||jD]}|j|q|jr-||j|jD]}||q%| | dS)Nbuild_py) r'rQget_package_dirbuild_py_modules_sourcesrFbuild_library_sourcesr+check_extensions_listbuild_extension_sourcesbuild_data_files_sourcesbuild_npy_pkg_config)r: libname_infoextr!r!r"rZs       zbuild_src.build_sourcesc CsB|jsdStdddlm}g}|jD]}t|tr"||qt|tr|\}}|j r;| d | t j}nt j |j|}dd|D}dd|D}|D]0}|jjdkr`||} n|} | durt| trr|| qSt| tr}|| qStt| qS|||f} ||| fqtt|||jdd<dS) Nzbuilding data_files sourcesr)get_data_files.cSsg|] }t|dr|qS__call__hasattr.0r&r!r!r" z6build_src.build_data_files_sources..cSsg|] }t|ds|qSrhrjrlr!r!r"rnror)rGrrSnumpy.distutils.misc_utilrf isinstancestrappendtupler'r]rMrPrKseprLr$__code__ co_argcountlistextend TypeErrorrepr) r:rfnew_data_filesdatarfiles build_dirfuncsr&s filenamesr!r!r"rbs<               z"build_src.build_data_files_sourcesc Cs|\}}}tj|}|D]\}}|||<q|jdkr%tj||} n tj|j||} tjtj|d} tj| | } tj | sLt | t | ||tj||} | | fS)Nrr) rKrLdirnameitemsr'rMr$basenamesplitextexistsmakedirsr#) r:rSgdtemplate install_dir subst_dict template_dirkrX generated_dir generatedgenerated_pathfull_install_dirr!r!r"_build_npy_pkg_configs        zbuild_src._build_npy_pkg_configc Cstdttd}|jdks|d}|jdkr!d}d}n t|dr+|j}d}|rd|j j D]2\}}|j j |}t jt j||}d|i}|D]} || |\} } |j j| | gfqNq3dSdS) Nz(build_src: building npy-pkg config filesinstallrFrgTinstall_libbaseprefix)rrScopyr finalizedrYr'rkrrCinstalled_pkg_configrr1rKrLrMabspathrrGrs) r: install_cmd build_npkg top_prefixpkginfospkg_pathrrrSrrr!r!r"rcs0      zbuild_src.build_npy_pkg_configcCs|jsdStdg}|jD]_}t|rit|dkri|\}}}|jr)||}ntj |j tjj | d}t |drJtj ||d}||}|durOq|||fg}||j vr_g|j |<|j ||7<q||q||jdd<dS)Nzbuilding py_modules sourcesrgri.py)r-rrSr lenr'r]rKrLrMr$rPrkr.rs)r:new_py_modulesrr, module_baserrmodulesr!r!r"r^s.          z"build_src.build_py_modules_sourcescCstt|dg}|s dStd|||||f}||||f}||\}}|r4td|j|||d<dS)Nsourceszbuilding library "%s" sources#%s - nothing done with h_files = %s)rxgetrrSgenerate_sourcestemplate_sourcesfilter_h_filesr,)r:lib_name build_inforh_filesr!r!r"r_szbuild_src.build_library_sourcesc Cs$t|j}td|j||j}|d}d|dd}|jr*| ||_ | ||}| ||}| ||}|||}|||}||\}}||jvrYg|j|<g}|D]}tjtj|d} ||| |fq]|j||7<||\}} | rtd|| ||_dS)Nzbuilding extension "%s" sourcesrgrr)rxrrrSnameget_ext_fullnamerPrMr'r]ext_target_dirrr swig_sources f2py_sources pyrex_sourcesfilter_py_filesr.rKrLrrrsr) r:rerfullnamemodpathr,py_filesrr&modulerr!r!r"ra0s4            z!build_src.build_extension_sourcesc Csg}g}|D]}t|r||q||q|s|S|jr't|s'|j}nt|r0|d}n|j}tjj|j g| ddd}| ||j rPt j}nt j}t |} |D](} | ||}|sdqZt|rudd|D||qZt d|f||qZt | |S)NrrgrcSsg|] }td|fqS) adding '%s' to sources.)rrS)rmrr!r!r"rn~sz.build_src.generate_sources..r)r rsr'r rrrKrLrMr$rPmkpathr8rINFOWARN set_thresholdryrS) r:r extension new_sources func_sourcesrrr new_level old_levelfuncr!r!r"rXs@          zbuild_src.generate_sourcescCs||dgS)Nr filter_filesr:rr!r!r"rszbuild_src.filter_py_filescCs||gdS)N)z.hz.hppz.incrrr!r!r"rszbuild_src.filter_h_filescCsHg}g}|D]}tj|\}}||vr||q||q||fSr*)rKrLrrs)r:rextsrr~rbaserer!r!r"rs  zbuild_src.filter_filesc Csng}t|r|dd}|dd}n|j}|j}|D]}tj|\}}|dkr|jr5tj|} n t |j tj|} | | tj | tj |} |jsZt|g|| rt|rjtd| t|} n td| t|} t| d } | | Wdn1swYt| rtj| } | |vrtd| || || q||q|S) Nrdepends include_dirsz.srczfrom_template:> %szconv_template:> %sr adding '%s' to include_dirs.)r rrrrKrLrr'rr r$rrMrr%r_f_pyf_ext_matchrrSprocess_f_fileprocess_c_filerr_header_ext_matchrs)r:rrrrrrrre target_dir target_fileoutstrfidrr!r!r"rs>        zbuild_src.template_sourcesc Cs`g}|jdd}|D]!}tj|\}}|dkr(|||||}||q ||q |S)z@Pyrex not supported; this remains for Cython support (see below)rgrz.pyx)rrPrKrLrgenerate_a_pyrex_sourcers) r:rrrext_namerrrerr!r!r"rs  zbuild_src.pyrex_sourcescCsgS)zPyrex 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!)r:rrrrr!r!r"rsz!build_src.generate_a_pyrex_sourcecCsg}g}g}i}g}|jdd}d} |D]} tj| \} } | dkr|jr.tj| } n t|jtj| } tj | rYt | }||krOt d| ||ftj | |d}nFt d| |}d} tj | |d}tj |st d ||ftj| } tj | |d}tj |st d |ft d ||| || ||| <||qt| r|| q|| q|s|s|S|D]}||q|j|j}|jjr|jjD]\}}||jvr||d gqt d ||rPt|dkr t d|f|d} || }tj|pd} | g|j}|js.t||drH| sHt d| ddl}|j |d| | gnpt d| nht!|rZ|d}n|j}tjj |jg|ddd} tj | |d}||||j}|jst||dr| st d||| ddl}|j |dd| gd|g|nt d|tj |st"d|ftj |j| }tj |d}tj |d}t d|||||j#vrt d||j#|| s %sz--lowerz-mz3 skipping f2py fortran files for '%s' (up-to-date)z!f2py target file %r not generatedzfortranobject.czfortranobject.hrrr>zf2py target_c file %r not foundzf2py target_h file %r not found)z-f2pywrappers.fz-f2pywrappers2.f90)'rrPrKrLrr'rr r$isfileget_f2py_modulenamerrMrdebugrNrSrsr rrr3rCrFryrrrr%r numpy.f2pyf2pyrun_mainr rr__file__r copy_file)r:rrrr f_sources f2py_targets target_dirsr skip_f2pyrrrerrrrrrrnumpyrtarget_ctarget_hsource_csource_hname_extfilenamer!r!r"rs                          zbuild_src.f2py_sourcesc Csg}g}i}g}g}d}d|jvrd} d} |jdn |jr$d} d} nd} d} d} |jdd} |D]} tj| \}}|d kr2|jrQtj |}|j }n t |j tj |}|}tj | rt| }|| d dkr|td | || d df| durt| } | dk} n3t| }|durtd | | fn!| |krtd | | |f|dkrtdd} ntd| | rd}tj|d||f}nDtd| | d d}d } t||}tj |std||ftj |}t||}tj |s td|ftd||||||tj||d|| |d|| <q4|| q4|s=|S| rD||S|D]}||qF|jpV|}|dg|j}| rf|d|jD] }|d|qi|D]E} || }| g|j}|jst||drtdtj|| rdpd| f|||jd|d|| gqvt d| qv||S) N.cz-c++c++TFrrgrz.irrz>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 target.cpp %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.rrrz-pythonz-Irz%s: %sz++z-oz-outdirz+ skipping '%s' swig interface (up-to-date))!r5remover6rrPrKrLrr'rrr r$rget_swig_modulenamerget_swig_targetrrNrM_find_swig_targetrsrr7 find_swigrrr%rrSrspawnr)r:rrrr swig_targetsrr target_exttypis_cpp skip_swigrrrrer py_target_dirrtyp2rrr7swig_cmdrrr!r!r"r\s                       zbuild_src.swig_sourcesN)__name__ __module__ __qualname__ description user_optionsboolean_options help_optionsr;rYr[rZrbrrcr^r_rarrrrrrrrrr!r!r!r"r$&s2:$(.  $ 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*-\*-cCsdt|d#}d}|}t|rd}t|r d}Wd|SWd|S1s+wY|S)NrrrV)rreadline_has_cpp_header _has_c_header)rr&resultliner!r!r"rs   rcCsht|d%}d}|D]}t|}|r|d}n q Wd|SWd|S1s-wY|S)Nrr)r_swig_module_name_matchr)rr&rrr r!r!r"rs    rcCs6dD]}tj|d||f}tj|r|Sq|S)N)rrr)rKrLrMr)rrrerr!r!r"rs rz%\s*python\s*module\s*(?P[\w_]+)z4\s*python\s*module\s*(?P[\w_]*?__user__[\w_]*)cCspd}t|(}|D]}t|}|rt|rq |d}n q Wd|SWd|S1s1wY|S)Nr)r_f2py_module_name_match_f2py_user_module_name_matchr)rrr&rr r!r!r"rs$    r).__doc__rKrrIrOrdistutils.commandrdistutils.dep_utilrrdistutils.utilrdistutils.errorsrrnumpy.distutilsrrpr r r r r numpy.distutils.from_templaterrnumpy.distutils.conv_templaterr#r$rImatchrrrrr r rrrrrrr!r!r!r"sX      -