1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
U
P±dp*ã@sBdZddlZddlZddlZddlZddlZddlZddlZddlZddl    Z    ddl
Z
ddl Z ddl m Z ddlmZmZddlmZmZddlmZdadadd    „Zd
d „Zd d „Zdd„Zegggdfdd„ƒZegggddfdd„ƒZdadd„Zdd„Z dd„Z!dd„Z"edd„ƒZ#Gdd„dƒZ$d d!„Z%e
j&d"d#„ƒZ'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)ÚasbytesÚasstr)ÚtemppathÚIS_WASM)Ú import_moduleicCsZtdk    rVztj t¡Wntk
r,YnXzt t¡Wntk
rPYnXdadS©N)Ú _module_dirÚsysÚpathÚremoveÚ
ValueErrorÚshutilÚrmtreeÚOSError©rrúLd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/f2py/tests/util.pyÚ_cleanup"srcCs6tdkr2t ¡at t¡ttjkr2tj dt¡tS©Nr)    r    ÚtempfileÚmkdtempÚatexitÚregisterrr
r ÚinsertrrrrÚget_module_dir0s 
 
rcCs,tƒdt}td7a|tjkr(tdƒ‚|S)Nz_test_ext_module_%déz%Temporary module name already in use.)rÚ _module_numr
ÚmodulesÚ RuntimeError)ÚnamerrrÚget_temp_module_name:s 
r csi‰‡‡fdd„}ˆj|_|S)Nc
snt||fƒ}|ˆkrTzˆ||Žˆ|<Wn,tk
rR}z|ˆ|<‚W5d}~XYnXˆ|}t|tƒrj|‚|Sr)ÚreprÚ    ExceptionÚ
isinstance)ÚaÚkwÚkeyÚeÚret©ÚfuncÚmemorrÚwrapperIs 
z_memoize.<locals>.wrapper)Ú__name__)r*r,rr)rÚ_memoizeFs r.c
Csrdtj›d}tƒ}g}g}|D]j}    tj |    ¡s<td|    ƒ‚tj |tj |    ¡¡}
t     |    |
¡| 
|
¡tj  |
¡\} } | dkr | 
|
¡q |s”t ‚|dkr¢t ƒ}dd|g||} |rÆ| dg|7} |rØ| d    g|7} t ¡}zft |¡tjd|g| }tj|tjtjd
}| ¡\}}|jd krDtd |d d…t|ƒfƒ‚W5t |¡|D]}    t |    ¡qVXt|ƒ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:©ÚstdoutÚstderrrzRunning f2py failed: %s
%sé)r
r rÚosÚisfilerÚjoinÚbasenamerÚcopyfileÚappendÚsplitextÚAssertionErrorr ÚgetcwdÚchdirÚunlinkÚ
executableÚ
subprocessÚPopenÚPIPEÚSTDOUTÚ communicateÚ
returncoderr)Ú source_filesÚoptionsÚskipÚonlyÚ module_nameÚcodeÚdÚ dst_sourcesZ f2py_sourcesÚfnÚdstÚbaseÚextZ    f2py_optsÚcwdÚcmdÚpÚoutÚerrrrrÚ build_module_sL   
 
þ  ÿ
 
rZc
Csb|dkr d}t|dB}t|dƒ}| |¡W5QRXt|g||||dW5QR£SQRXdS)z6
    Compile and import Fortran code using f2py.
 
    Nr1)ÚsuffixÚw©rJrKrLrM)rÚopenÚwriterZ)Z source_coderJrKrLr[rMr ÚfrrrÚ
build_codešs   ürac        Cstdk    r tSdatrtSt dttjƒ›d¡}|tttjƒd}t     ¡}z`t j  |d¡}t|dƒ}| |¡W5QRXtjddg}tj|tjtj|d}| ¡\}}W5t
  |¡Xt d    |¡}|rþtt| d
¡ƒƒtt| d ¡ƒƒtt| 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)
        )Zsyspathzsetup.pyr\Úconfig)r4r5rUsCOMPILERS:(\d+),(\d+),(\d+)réé)Ú_compiler_statusrÚtextwrapÚdedentr!r
r Údictrrrrr7r9r^r_rBrCrDrErFrGÚreÚsearchÚboolÚintÚgroup)    rNZtmpdirÚscriptr`rVrWrXrYÚmrrrÚ_get_compiler_status¸s:ý
  ý  ýrpcCs
tƒdSr©rprrrrÚhas_c_compilerösrrcCs
tƒdS)NrrqrrrrÚhas_f77_compilerúsrscCs
tƒdS)NrcrqrrrrÚhas_f90_compilerþsrtc
Ksftƒ}g}|D]H}tj |¡s*td|ƒ‚tj |tj |¡¡}t ||¡|     |¡qt
  |¡  dd¡}dt tjƒ›d|›d}tj |tƒd¡}    |     |    ¡t|    dƒ}
|
 t|ƒ¡W5QRXt ¡} zdt |¡tj|    d    d
g} tj| tjtjd } |  ¡\}}| jd kr.td | dd…t|ƒfƒ‚W5t | ¡|D]}t |¡q@Xt|ƒtj|S)z6
    Build a module via distutils and import it.
 
    r/Ú
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.pyÚwbÚ    build_extz-ir3rz%Running distutils build failed: %s
%sr6N) rr7r r8rr9r:rr;r<rfrgÚreplacer!r
r r^r_rr?r@rArBrCrDrErFrGrHrÚ
__import__r)rIZ config_coderMr%rOrPrQrRrNrnr`rUrVrWrXrYrrrÚbuild_module_distutilssH    ýø
 
þ  ÿ
 
rzc@s<eZdZdZdZgZgZgZdZdZ    e
dd„ƒZ dd„Z dS)ÚF2PyTestNr1cCs*t|ƒ}d|j dd¡d›d|j›dS)NÚ_Ú.réÿÿÿÿZ _ext_module)ÚtypeÚ
__module__Úrsplitr-)ÚselfÚclsrrrrMUszF2PyTest.module_namecCsLtjdkrt d¡|jdk    r"dStƒs2t d¡g}|jrH| |j¡|jdk    r^|     |j
¡d}d}d}|D]>}t |ƒ  d¡r†d}qnt |ƒ  d¡ršd}qnt |ƒ  d¡rnd}qn|rÂt ƒsÂt d    ¡|rÖtƒsÖt d
¡|rðtƒsðt ƒsðt d ¡|jdk    rt|j|j|j|j|j
|jd |_|jdk    rHt|j|j|j|j|jd |_dS)NÚwin32z)Fails with MinGW64 Gfortran (Issue #9673)zNo C compiler availableFr1Tr0r2z No Fortran 77 compiler availablez No Fortran 90 compiler availablezNo Fortran compiler available)rJrKrLr[rMr])r
ÚplatformÚpytestrKÚmodulerrÚsourcesÚextendrNr<r[ÚstrÚendswithrsrtrarJrLrMrZ)r‚ÚcodesZ    needs_f77Z    needs_f90Z    needs_pyfrQrrrÚ setup_methodZsX
 
 
 
 
 
 
 
 
 
 ú     ûzF2PyTest.setup_method) r-r€Ú __qualname__rNrˆrJrKrLr[r‡ÚpropertyrMrrrrrr{Ls
r{cGsttjjƒj ¡}|j|ŽSr)rÚnumpyZf2pyÚ__file__ÚparentÚresolveÚjoinpath)r$rOrrrÚgetpath–sr•c    cs.t ¡}t |¡z
dVW5t |¡XdSr)rrUr7r@)r ZcurpathrrrÚ    switchdirœs
 
 
r–)(Ú__doc__r7r
rCrrrrfrir†Ú
contextlibrÚpathlibrZ numpy.compatrrZ numpy.testingrrÚ    importlibrr    rrrr r.rZrarerprrrsrtrzr{r•Úcontextmanagerr–rrrrÚ<module>sR  
 :û >    
DJ