o 6at%@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^tdur-ztjtWn tyYnwzttWn ttfy(YnwdadSdSN) _module_dirsyspathremove ValueErrorshutilrmtreeIOErrorOSErrorrr7/usr/lib/python3/dist-packages/numpy/f2py/tests/util.py_cleanups rcCs6tdurtattttjvrtjdttSNr) rtempfilemkdtempatexitregisterrrr insertrrrrget_module_dir,s   rcCs,t}dt}td7a|tjvrtd|S)Nz_test_ext_module_%dz%Temporary module name already in use.)r _module_numrmodules RuntimeError)dnamerrrget_temp_module_name6s  r csifdd}j|_|S)Nc sht||f}|vr'z |i||<Wnty&}z||<d}~ww|}t|tr2||Sr)repr Exception isinstance)akwkeyeretfuncmemorrwrapperEs  z_memoize..wrapper)__name__)r*r,rr)r_memoizeBs r.c Csdttj}t}g}g}|D]5} tj| std| tj|tj| } t | | | | tj | \} } | dvrE| | q|durMt }dd|g||} |r_| dg|7} |rh| dg|7} t}zDt|tjd|g| }tj|tjtjd }|\}}|jd krtd |d dt|fWt||D]} t| qt|St||D]} t| qw) zH Compile and import a f2py module, built from the given files. zEimport sys; sys.path = %s; import numpy.f2py as f2py2e; f2py2e.main()%s is not a file).f90.fz.cz.pyfNz-cz-mzskip:zonly:stdoutstderrrzRunning f2py failed: %s %s)r!rr rosisfilerjoinbasenamer copyfileappendsplitextr getcwdchdir executable subprocessPopenPIPESTDOUT communicate returncoderunlinkr) source_filesoptionsskiponly module_namecoder dst_sources f2py_sourcesfndstbaseext f2py_optscwdcmdpouterrrrr build_moduleYsX             rYc Cs|durd}t|d,}t|d }||Wdn1s!wYt|g||||dWdS1s:wYdS)z6 Compile and import Fortran code using f2py. Nr1)suffixwrHrIrJrK)ropenwriterY) source_coderHrIrJrZrKr frrr build_codes    $rac Cs tdurtSdatd}|tttjd}t}z?t j |d}t |d }| |Wdn1s8wYtj ddg}tj|tjtj|d}|\}}Wt|nt|wtd|}|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.pyr[config)r3r4rTsCOMPILERS:(\d+),(\d+),(\d+)r)_compiler_statustextwrapdedentdictr!rr rrr6r8r]r^r?r@rArBrCrDr r researchboolintgroup) rLtmpdirscriptr`rUrVrWrXmrrr_get_compiler_statuss0       rrcC tdSrrrrrrrhas_c_compiler rucCrs)Nrrtrrrrhas_f77_compilerrvrwcCrs)Nrdrtrrrrhas_f90_compilerrvrxc Ksddlm}ddlm}t}g}|D]$}tj|s!td|tj |tj |} t || | | qt|dd}tdt|ttjd} tj |td } | | t| d } | t| Wd n1suwYt} z@t|tj| d d g}tj|tjtjd}|\}}|j dkrtd|dd t!|fWt| |D]}t"|qnt| |D]}t"|qwt#|tj$|S)z6 Build a module via distutils and import it. r) Configuration)setupr/ 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_coderbz.pywbN build_extz-ir2z%Running distutils build failed: %s %sr5)%numpy.distutils.misc_utilrynumpy.distutils.corerzrr6r r7rr8r9r r:r;rgrhreplacerir!rr r]r^rr=r>r?r@rArBrCrDrErrF __import__r)rGr|rKr%ryrzrrMrOrPrLrpr`rTrUrVrWrXrrrbuild_module_distutilssT                 rc@s4eZdZdZdZgZgZgZdZdZ dZ ddZ dS)F2PyTestNr1cCstjdkr td|jdurdStstdg}|jr$||j|jdur/| |j d}d}|D]}| dr?d}q5| drFd}q5|rQt sQtd|r[t s[td |jdurqt|j|j|j|j|j |jd |_|jdurt|j|j|j|j|jd |_dSdS) Nwin32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFr1Tr0z No Fortran 77 compiler availablez No Fortran 90 compiler available)rHrIrJrZrKr\)rplatformpytestrImodulerusourcesextendrLr;rZendswithrwrxrarHrJrKrY)selfcodes needs_f77 needs_f90rOrrrrz@sF                  zF2PyTest.setup) r- __module__ __qualname__rLrrHrIrJrZrrKrzrrrrr6s r) __doc__r6rr@rr rrgrjr numpy.compatrr numpy.testingr importlibrrrrrr r.rYrarfrrrurwrxrrrrrrsB    8 7 F