B { `%@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl mZddlmZddlmZdadadd Zd d Zd d ZddZegggdfddZegggddfddZdaddZddZddZddZeddZ GdddZ!dS) z Utility functions for - building and importing modules on test time, using a temporary location - detecting if compilers are present N)asbytesasstr)temppath) import_module)md5ic Cs^tdk rZytjtWntk r,YnXyttWnttfk rTYnXdadS)N) _module_dirsyspathremove ValueErrorshutilrmtreeIOErrorOSErrorrr9/tmp/pip-unpacked-wheel-4iou4664/numpy/f2py/tests/util.py_cleanup srcCs6tdkr2tattttjkr2tjdttS)Nr) rtempfilemkdtempatexitregisterrrr insertrrrrget_module_dir.s   rcCs,t}dt}td7a|tjkr(td|S)Nz_test_ext_module_%dz%Temporary module name already in use.)r _module_numrmodules RuntimeError)dnamerrrget_temp_module_name8s  rcsifdd}j|_|S)Nc snt||f}|krTy|||<Wn,tk rR}z||<Wdd}~XYnX|}t|trj||S)N)repr Exception isinstance)akwkeyeret)funcmemorrwrapperGs  z_memoize..wrapper)__name__)r(r*r)r(r)r_memoizeDs r,c Csrdttj}t}g}g}xr|D]j} tj| s>td| tj|tj| } t | | | | tj | \} } | dkr"| | q"W|dkrt }dd|g||} |r| dg|7} |r| dg|7} t}zft|tjd|g| }tj|tjtjd }|\}}|jd kr@td |d dt|fWdt|x|D]} t| qTWXt|S) zH Compile and import a f2py module, built from the given files. zEimport sys; sys.path = %s; import numpy.f2py as f2py2e; f2py2e.main()z%s is not a file)z.f90z.fz.cz.pyfNz-cz-mzskip:zonly:)stdoutstderrrzRunning f2py failed: %s %s)r rr rosisfilerjoinbasenamer copyfileappendsplitextrgetcwdchdir executable subprocessPopenPIPESTDOUT communicate returncoderunlinkr) source_filesoptionsskiponly module_namecoder dst_sourcesZ f2py_sourcesfndstbaseextZ f2py_optscwdcmdpouterrrrr build_module[sF             rQc CsV|dkr d}t|d6}t|d}||WdQRXt|g||||dSQRXdS)z6 Compile and import Fortran code using f2py. Nz.f)suffixw)rBrCrDrE)ropenwriterQ)Z source_coderBrCrDrRrEr frrr build_codes   rWc Cstdk r tSdatd}|tttjd}t}z`t j |d}t |d}| |WdQRXtj ddg}tj|tjtj|d}|\}}Wdt|Xtd|}|rtt|d tt|d tt|d fatS) N)FFFa import os import sys sys.path = %(syspath)s def configuration(parent_name='',top_path=None): global config from numpy.distutils.misc_util import Configuration config = Configuration('', parent_name, top_path) return config from numpy.distutils.core import setup setup(configuration=configuration) config_cmd = config.get_config_cmd() have_c = config_cmd.try_compile('void foo() {}') print('COMPILERS:%%d,%%d,%%d' %% (have_c, config.have_f77c(), config.have_f90c())) sys.exit(99) )syspathzsetup.pyrSconfig)r-r.rLsCOMPILERS:(\d+),(\d+),(\d+)r)_compiler_statustextwrapdedentdictr rr rrr0r2rTrUr9r:r;r<r=r>r r researchboolintgroup) rFZtmpdirscriptrVrMrNrOrPmrrr_get_compiler_statuss,      rgcCs tdS)Nr)rgrrrrhas_c_compilersrhcCs tdS)Nr)rgrrrrhas_f77_compilersricCs tdS)NrZ)rgrrrrhas_f90_compilersrjc Ksddlm}ddlm}t}g}xP|D]H}tj|sDtd|tj |tj |} t || | | q(Wt|dd}tdt|ttjd} tj |td } | | t| d } | t| Wd QRXt} zdt|tj| d d g}tj|tjtjd}|\}}|j dkrNtd|dd t!|fWd t| x|D]}t"|qbWXt#|tj$|S)z6 Build a module via distutils and import it. r) Configuration)setupz%s is not a file z a import os import sys sys.path = %(syspath)s def configuration(parent_name='',top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('', parent_name, top_path) %(config_code)s return config if __name__ == "__main__": from numpy.distutils.core import setup setup(configuration=configuration) ) config_coderXz.pywbN build_extz-i)r-r.z%Running distutils build failed: %s %sr/)%Znumpy.distutils.misc_utilrkZnumpy.distutils.corerlrr0r r1rr2r3r r4r5r]r^replacer_r rrrTrUrr7r8r9r:r;r<r=r>r?rr@ __import__r)rArnrEr$rkrlrrGrHrIrFrerVrLrMrNrOrPrrrbuild_module_distutilss@               rsc@s4eZdZdZdZgZgZgZdZdZ dZ ddZ dS)F2PyTestNz.fcCstjdkrtd|jdk r"dSts2tdg}|jrH||j|jdk r^| |j d}d}x*|D]"}| drd}ql| drld}qlW|rt std|rt std |jdk rt|j|j|j|j|j |jd |_|jdk rt|j|j|j|j|jd |_dS) Nwin32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFz.fTz.f90z No Fortran 77 compiler availablez No Fortran 90 compiler available)rBrCrDrRrE)rBrCrDrE)rplatformpytestrCmodulerhsourcesextendrFr5rRendswithrirjrWrBrDrErQ)selfcodesZ needs_f77Z needs_f90rHrrrrlBs>                   zF2PyTest.setup) r+ __module__ __qualname__rFryrBrCrDrRrxrErlrrrrrt8srt)"__doc__r0rr:rr rr]r`rwZ numpy.compatrrZ numpy.testingr importlibrhashlibrrrrrrr,rQrWr\rgrhrirjrsrtrrrrs>     87 G