B @`t%@s dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl mZddlmZdadaddZd d Zd d Zd dZegggdfddZegggddfddZdaddZddZddZddZeddZGdddZdS)z Utility functions for - building and importing modules on test time, using a temporary location - detecting if compilers are present N)asbytesasstr)temppath) import_moduleic Cs^tdk rZytjtWntk r,YnXyttWnttfk rTYnXdadS)N) _module_dirsyspathremove ValueErrorshutilrmtreeIOErrorOSErrorrr9/tmp/pip-unpacked-wheel-ecq9wray/numpy/f2py/tests/util.py_cleanupsrcCs6tdkr2tattttjkr2tjdttS)Nr) rtempfilemkdtempatexitregisterrrrinsertrrrrget_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_name6s  rcsifdd}j|_|S)Nc snt||f}|krTy|||<Wn,tk rR}z||<Wdd}~XYnX|}t|trj||S)N)repr Exception isinstance)akwkeyeret)funcmemorrwrapperEs  z_memoize..wrapper)__name__)r'r)r)r'r(r_memoizeBs 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)rrrrosisfilerjoinbasenamer copyfileappendsplitextrgetcwdchdir executable subprocessPopenPIPESTDOUT communicate returncoderunlinkr) source_filesoptionsskiponly module_namecoder dst_sourcesZ f2py_sourcesfndstbaseextZ f2py_optscwdcmdpouterrrrr build_moduleYsF             rPc CsV|dkr d}t|d6}t|d}||WdQRXt|g||||dSQRXdS)z6 Compile and import Fortran code using f2py. Nz.f)suffixw)rArBrCrD)ropenwriterP)Z source_coderArBrCrQrDrfrrr build_codes   rVc 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.pyrRconfig)r,r-rKsCOMPILERS:(\d+),(\d+),(\d+)r)_compiler_statustextwrapdedentdictrrrrrr/r1rSrTr8r9r:r;r<r=r r researchboolintgroup) rEZtmpdirscriptrUrLrMrNrOmrrr_get_compiler_statuss,      rfcCs tdS)Nr)rfrrrrhas_c_compilersrgcCs tdS)Nr)rfrrrrhas_f77_compilersrhcCs tdS)NrY)rfrrrrhas_f90_compilersric 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_coderWz.pywbN build_extz-i)r,r-z%Running distutils build failed: %s %sr.)%Znumpy.distutils.misc_utilrjZnumpy.distutils.corerkrr/rr0rr1r2r r3r4r\r]replacer^rrrrSrTrr6r7r8r9r:r;r<r=r>rr? __import__r)r@rmrDr#rjrkrrFrGrHrErdrUrKrLrMrNrOrrrbuild_module_distutilss@               rrc@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)rArBrCrQrD)rArBrCrD)rplatformpytestrBmodulergsourcesextendrEr4rQendswithrhrirVrArCrDrP)selfcodesZ needs_f77Z needs_f90rGrrrrk@s>                   zF2PyTest.setup) r* __module__ __qualname__rErxrArBrCrQrwrDrkrrrrrs6srs) __doc__r/rr9rr rr\r_rvZ numpy.compatrrZ numpy.testingr importlibrrrrrrr+rPrVr[rfrgrhrirrrsrrrrs<    87 G