idy+dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZmZddlmZmZddlmZdadaejdkr8eejjjZeed Zd Zd Z d Z!d Z"e"gggdfdZ#e"gggddfdZ$da%dZ&dZ'dZ(dZ)e"dZ*GddZ+dZ,e j-dZ.dS)z Utility functions for - building and importing modules on test time, using a temporary location - detecting if compilers are present - determining paths to tests N)Path)asbytesasstr)temppathIS_WASM) import_moduleicygwinz**/*.dllcte tjtn#t$rYnwxYw t jtn#t$rYnwxYwdadSdSN) _module_dirsyspathremove ValueErrorshutilrmtreeOSErrorJ/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/f2py/tests/util.py_cleanupr's  HOOK ( ( ( (    D   M+ & & & &    D  s$. ;;A A&%A&ctdtjatjt tt jvr%t jdttSNr) r tempfilemkdtempatexitregisterrr rinsertrrrget_module_dirr5sO&(( !!! ch & & HOOA{ + + + rctdtz}tdz a|tjvrt d|S)Nz_test_ext_module_%dz%Temporary module name already in use.)r _module_numr modules RuntimeError)names rget_temp_module_namer&?sE ; .D1K s{BCCC Krc2ifd}j|_|S)Nct||f}|vr% |i||<n#t$r }||<d}~wwxYw|}t|tr||Sr )repr Exception isinstance)akwkeyeretfuncmemos rwrapperz_memoize..wrapperNsAr7mm d??  D!NrNNS    S  3i c9 % % I s $ 949)__name__)r1r3r2s` @r_memoizer5Ks8 D      }G Nrc dtjd}t}g}g}|D]} tj| st d| ztj|tj| } tj | | | | tj | \} } | dvr| | |t}dd|g|z|z} |r | dg|zz } |r | d g|zz } tj } tj|tjd|g| z}t!j|t jt j }|\}}|jd kr*t d |d ddt-| tj||D]} tj| n2#tj||D]} tj| wxYwtjdkr{t2t7jtj|d|t!jgdt2zt=|S)zH Compile and import a f2py module, built from the given files. zimport sys; sys.path = z&; import numpy.f2py; numpy.f2py.main()%s is not a file).f90.fz.c.pyfNz-cz-mzskip:zonly:stdoutstderrrzRunning f2py failed:  r z{:s}*)z/usr/bin/rebasez --databasez --obliviousz --verbose)r rrosisfiler$joinbasenamercopyfileappendsplitextr&getcwdchdir executable subprocessPopenPIPESTDOUT communicate returncoderunlinkplatform _module_listextendglobformat check_callr) source_filesoptionsskiponly module_namecoded dst_sources f2py_sourcesfndstbaseext f2py_optscwdcmdpouterrs r build_modulerjds XSX W W WDAKL % %w~~b!! 81B677 7gll1bg..r2233C   3G$$S)) c . . .    $ $ $ *,, t[)G3lBI &gY%%  &gY%%  )++C  ~tT*Y6  S$.O$.$5 7 7 7==??S <1  , #ABBs 566 6     B IbMMMM     B IbMMMM  |x  Ibgll1gnn[&A&ABB C C     I I I      % %%s BH /H;c|d}t|5}t|d5}||dddn #1swxYwYt|g||||cdddS#1swxYwYdS)z6 Compile and import Fortran code using f2py. Nr9)suffixwrXrYrZr[)ropenwriterj) source_coderXrYrZrlr[rfs r build_coderss~  5D $__ ! GGK  ! ! ! ! ! ! ! ! ! ! ! ! ! ! !TF$+!%!%(3 555555555555555555555s3A4A A4A A4A A44A8;A8c &ttSdatrtStjdt t jd}|tt t jz}tj } tj |d}t|d5}| |dddn #1swxYwYt jddg}tj|tjtj|}|\}}t)j|n#t)j|wxYwt-jd |}|rt1t3|d t1t3|d t1t3|d fatS) N)FFFz8 import os import sys sys.path = a{ 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.pyrmconfig)r<r=resCOMPILERS:(\d+),(\d+),(\d+)r!)_compiler_statusrtextwrapdedentr)r rdictrrr@rBrorprIrJrKrLrMrNrrresearchboolintgroup) r\tmpdirscriptrrrfrgrhrims r_get_compiler_statusrs#,  ? NN     D* $tCH~~... .D    F fj11 &#   ! GGDMMM               ~z84  S$.O$.$5!' ) ) )==??S f f 1377A QWWQZZ ! ! QWWQZZ ! ! QWWQZZ ! !  s1 0E<C EC""E%C"&AEE&c*tdSrrrrrhas_c_compilerr   ! !! $$rc*tdS)Nr!rrrrhas_f77_compilerrrrc*tdS)Nrwrrrrhas_f90_compilerrrrc jt}g}|D]}tj|st d|ztj|tj|}tj||| |tj | dd}dttjd|d}tj|tdz} | | t!| d5} | t%|d d d n #1swxYwYtj} tj|tj| d d g} t-j| t,jt,j } | \}}| jd kr*t d| dd dt9| tj| |D]}tj|n2#tj| |D]}tj|wxYwt=|tj|S)z6 Build a module via distutils and import it. r7r?z z! import os import sys sys.path = z def configuration(parent_name='',top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('', parent_name, top_path) z return config if __name__ == "__main__": from numpy.distutils.core import setup setup(configuration=configuration) z.pywbN build_extz-ir;rz Running distutils build failed: r>) rr@rrAr$rBrCrrDrErzr{replacer)r r&rorprrGrHrIrJrKrLrMrNrOrrP __import__r#)rW config_coder[r-r]r^r`rar\rrrrerfrgrhris rbuild_module_distutilsrs AK  w~~b!! 81B677 7gll1bg..r2233C   3/+..66tXFFK  NN     DW\\!133e; < ((Q//3OOclOOOOrctjdkrtjd|jdSt stjdg}|jr||j|j| |j d}d}d}|D]p}t| drd}'t| drd}Lt| drd}q|r"tstjd |r"tstjd |r0ts"tstjd |j8t|j|j|j|j|j |j |_|j4t'|j|j|j|j|j |_dSdS)Nwin32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFr9Tr8r:z No Fortran 77 compiler availablez No Fortran 90 compiler availablezNo Fortran compiler available)rXrYrZrlr[rn)r rQpytestrYmodulersourcesrSr\rErlstrendswithrrrsrXrZr[rj)rcodes needs_f77 needs_f90 needs_pyfr`s r setup_methodzF2PyTest.setup_methodns <7 " " KC D D D ; " F 3 K1 2 2 2 < ' LL & & & 9 LL % % %    ! !B2ww%% ! R!!&)) ! R!!&)) !  <-// < K: ; ; ;  <-// < K: ; ; ;  9.00 94D4F4F 9 K7 8 8 8 9 $  YY{ , DK < #&  YY , DKKK $ #r) r4r __qualname__r\rrXrYrZrlrpropertyr[rrrrrr`sb DGG D D F F PPXP44444rrcttjjj}|j|Sr )rnumpyf2py__file__parentresolvejoinpath)r,r]s rgetpathrs1 UZ !!(0022A 1:q>rc#Ktj}tj| dVtj|dS#tj|wxYwr )rrer@rH)rcurpaths r switchdirrsXhjjGHTNNN  s AA)/__doc__rTr@r rJrrrrzr}r contextlibrpathlibr numpy.compatrr numpy.testingrr importlibrr r"rQrrNUMPY_INSTALL_ROOTlistrRrrr&r5rjrsryrrrrrrrcontextmanagerrrrrrs    ''''''''++++++++######   <8h.5<4*// ;;<