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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
U
P±dqTã@s\ddlZddlZddlZddlZddlZddlmZddlmZddl    Z    ddl
m Z ddl m ZeddƒZdtd
d „Ze    jd d dd„ƒZe    jd d dd„ƒZe    jd d dd„ƒZe    jd d dd„ƒZdd„Zdd„Zdd„Ze    jjdd„ƒZdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Z d(d)„Z!d*d+„Z"d,d-„Z#d.d/„Z$d0d1„Z%d2d3„Z&d4d5„Z'd6d7„Z(e    jjd8d9d:d;„ƒZ)d<d=„Z*d>d?„Z+d@dA„Z,dBdC„Z-dDdE„Z.dFdG„Z/dHdI„Z0dJdK„Z1dLdM„Z2e    jjd8d9dNdO„ƒZ3dPdQ„Z4dRdS„Z5dTdU„Z6dVdW„Z7dXdY„Z8dZd[„Z9d\d]„Z:d^d_„Z;d`da„Z<dbdc„Z=ddde„Z>dfdg„Z?dhdi„Z@djdk„ZAdldm„ZBdndo„ZCdpdq„ZDdrds„ZEdS)uéN)ÚPath)Ú
namedtupleé)Úutil)ÚmainÚPPathsz(finp, f90inp, pyf, wrap77, wrap90, cmodfÚuntitledc
CsRt|ƒ}t| d¡| d¡| d¡| |›d¡| |›d¡| |›d¡dS)axTakes in a temporary file for testing and returns the expected output and input paths
 
    Here expected output is essentially one of any of the possible generated
    files.
 
    ..note::
 
         Since this does not actually run f2py, none of these are guaranteed to
         exist, and module names are typically incorrect
 
    Parameters
    ----------
    fname_inp : str
                The input filename
    mname : str, optional
                The name of the module, untitled by default
 
    Returns
    -------
    genp : NamedTuple PPaths
            The possible paths which are generated, not all of which exist
    z.fz.f90ú.pyfz-f2pywrappers.fz-f2pywrappers2.f90úmodule.c)ÚfinpÚf90inpÚpyfÚwrap77Zwrap90Úcmodf)rrÚ with_suffixÚ    with_name)Z    fname_inpÚmnameÚbpath©rúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/f2py/tests/test_f2py2e.pyÚ get_io_pathssúrÚsession)ZscopecCs2t dddd¡ ¡}| ¡d}|j|dd|S)ú'Generates a single f90 file for testingÚtestsÚsrcÚcliz hiworld.f90z    hello.f90Úascii©Úencoding©rZgetpathÚ    read_textZ getbasetempÚ
write_text©Útmpdir_factoryÚfdatÚfnrrrÚhello_world_f908s r&cCs2t dddd¡ ¡}| ¡d}|j|dd|S)ú'Generates a single f77 file for testingrrrzhi77.fzhello.frrrr"rrrÚhello_world_f77As r(cCs2t dddd¡ ¡}| ¡d}|j|dd|S)r'rrZ return_realzfoo77.fzfoo.frrrr"rrrÚ retreal_f77Js r)cCs`t dddd¡ ¡}t dddd¡ ¡}| ¡d}| ¡d}|j|dd    |j|dd    |S)
rrrÚf2cmapzisoFortranEnvMap.f90z .f2py_f2cmapz
f2cmap.f90Zmapfilerrr)r#r$r*r%ZfmaprrrÚ
f2cmap_f90Rs  r+c    Cs€t|ƒ}t|ƒjd}| tdd|›d|› ¡¡t |j¡6tƒ|     ¡\}}d|ks`t
‚t|›ƒ  ¡srt
‚W5QRXdS)zIEnsures that a signature file is generated via the CLI
    CLI :: -h
    r    Úargvzf2py -h ú úSaving signatures to fileN) rÚstemÚsetattrÚsysÚsplitrÚ    switchdirÚparentÚf2pycliÚ
readouterrÚAssertionErrorÚexists)Úcapfdr&Ú monkeypatchÚipathZopathÚoutÚ_rrrÚ test_gen_pyf^s  r>c    Csft|ƒ}| tdd|› ¡¡t |j¡0tƒ| ¡\}}d|ksLt    ‚d|ksXt    ‚W5QRXdS)zHEnsures that a signature file can be dumped to stdout
    CLI :: -h
    r,zf2py -h stdout r.zfunction hi() ! in N©
rr0r1r2rr3r4r5r6r7©r9r&r:r;r<r=rrrÚtest_gen_pyf_stdoutms  rAc
Cs‚t|ƒ}| tdd|› ¡¡t |j¡Ltdƒjdddt     t
¡$t ƒ|  ¡\}}d|ksjt ‚W5QRXW5QRXdS)    zjEnsures that the CLI refuses to overwrite signature files
    CLI :: -h without --overwrite-signature
    r,úf2py -h faker.pyf ú    faker.pyfú    Fake newsrrz&Use --overwrite-signature to overwriteN)rr0r1r2rr3r4r!ÚpytestÚraisesÚ
SystemExitr5r6r7)r9r&r:r;r=ÚerrrrrÚtest_gen_pyf_no_overwritezs  rIc     Csªt|dd}|j}d}d}| tdd|›d|› ¡¡t |j¡\tƒ|     ¡\}}| ¡D]}    d|    ›d    |ks`t
‚q`| ¡D]}
d
|
›d |ks‚t
‚q‚W5QRXd S) z9Tests that functions can be skipped
    CLI :: skip:
    Útest©rút0 t4 t8 sd s8 s4útd s0r,úf2py z -m test skip: z=buildmodule: Could not found the body of interfaced routine "ú ". Skipping.úConstructing wrapper function "ú"N© rr r0r1r2rr3r4r5r6r7) r9r)r:Úfoutlr;ÚtoskipÚ    remainingr<rHÚskeyÚrkeyrrrÚtest_f2py_skip‰s& þ  
ÿÿ rXc     Csªt|dd}|j}d}d}| tdd|›d|› ¡¡t |j¡\tƒ|     ¡\}}| ¡D]}    d|    ›d    |ks`t
‚q`| ¡D]}
d
|
›d |ks‚t
‚q‚W5QRXd S) z>Test that functions can be kept by only:
    CLI :: only:
    rJrKrLrMr,rNz -m test only: ú<buildmodule: Could not find the body of interfaced routine "rOrPrQNrR) r9r)r:rSr;rTÚtokeepr<rHrVrWrrrÚtest_f2py_only¡s& þ  
ÿÿ r[c CsÂt|dd}|j}d}t|ƒ}d}d}    | tdd|›d|    ›d    |›d
|› ¡¡t |j¡\t    ƒ| 
¡\}
} | ¡D]} d | ›d | ksxt ‚qx| ¡D]} d | ›d|
ksšt ‚qšW5QRXdS)zfTests that it is possible to return to file processing mode
    CLI :: :
    BUG: numpy-gh #20520
    rJrKrLztd s0 hiÚblahr,rNú -m z only: z : rYrOrPrQN) rr rr0r1r2rr3r4r5r6r7)r9r&r)r:rSr;rTZipath2rZrr<rHrVrWrrrÚtest_file_processing_switch¸s* ý  
ÿÿ r^c    Csvd}t||d}|j}| tdd|›d|› ¡¡t |j¡ tƒW5QRXt     
|j ¡sbt ‚t     
|j ¡srt ‚dS)zHChecks the generation of files based on a module name
    CLI :: -m
    ÚhirKr,rNr]N)rr r0r1r2rr3r4r5rr8rr7r)r9r&r:ZMNAMErSr;rrrÚtest_mod_gen_f77Ös r`c        Csút|dd}|j}t d¡}t d¡}| tdd|›d ¡¡t |j    ¡<t
ƒ|  ¡\}}|  |¡dk    srt ‚|  |¡dks„t ‚W5QRX| tdd|›d     ¡¡t |j    ¡<t
ƒ|  ¡\}}|  |¡dksÚt ‚|  |¡dk    sìt ‚W5QRXdS)
zHLowers cases by flag or when -h is present
 
    CLI :: --[no-]lower
    rJrKzHI\(\)zhi\(\)r,rNz -m test --lowerNz -m test --no-lower)rr ÚreÚcompiler0r1r2rr3r4r5r6Úsearchr7©    r9r(r:rSr;ZcapshiZcapslor<r=rrrÚtest_lower_cmodçs$ 
 
 ÿ rec        Cs
t|dd}|j}t d¡}t d¡}| tdd|›d|j›d ¡¡t     |j
¡<t ƒ|  ¡\}}|  |¡d    k    szt‚|  |¡d    ksŒt‚W5QRX| tdd|›d|j›d
 ¡¡t     |j
¡<t ƒ|  ¡\}}|  |¡d    ksêt‚|  |¡d    k    süt‚W5QRXd    S) z^Lowers cases in signature files by flag or when -h is present
 
    CLI :: --[no-]lower -h
    rJrKz    Block: HIz    Block: hir,rNz -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)rr rarbr0r1r r2rr3r4r5r6rcr7rdrrrÚtest_lower_sigs0 
 
ý ý rfc
Csvt|ƒ}d}d}| tdd|›d|›d|› ¡¡t |j¡,tƒ| ¡\}}d|›d|ksht    ‚W5QRXd    S)
zNEnsures that the build directory can be specified
 
    CLI :: --build-dir
    r\Ztttmpr,úf2py -m r-z  --build-dir zWrote C/API module "rQNr?)r9r&r:r;rZodirr<r=rrrÚtest_build_dir(sÿ rhc    Csnt|ƒ}| tdd|›d ¡¡t |j¡6tdƒjdddtƒ|     ¡\}}d|ks`t
‚W5QRXd    S)
zXEnsures that the build directory can be specified
 
    CLI :: --overwrite-signature
    r,rBz --overwrite-signaturerCrDrrr.N) rr0r1r2rr3r4r!r5r6r7r@rrrÚtest_overwrite9sþ ric
Cs”t|ƒ}d}| tdd|›d|›d ¡¡t |j¡Rtƒ| ¡\}}d|ksXt    ‚t|›dƒ 
¡}d|  ¡ks|t    ‚W5QRXW5QRXd    S)
zJEnsures that TeX documentation is written out
 
    CLI :: --latex-doc
    r\r,rgr-z  --latex-docúDocumentation is saved to fileú
module.texú\documentclassN© rr0r1r2rr3r4r5r6r7ÚopenÚread©r9r&r:r;rr<r=ZotexrrrÚ test_latexdocJsÿ  rqc    Csft|ƒ}d}| tdd|›d|›d ¡¡t |j¡$tƒ| ¡\}}d|ksXt    ‚W5QRXdS)zMEnsures that TeX documentation is written out
 
    CLI :: --no-latex-doc
    r\r,rgr-z --no-latex-docrjNr?©r9r&r:r;rr<r=rrrÚtest_nolatexdoc\sÿ rsc
Cs–t|ƒ}d}| tdd|›d|›d ¡¡t |j¡Ttƒ| ¡\}}d|ksXt    ‚td|›dƒ 
¡}d    |  ¡ks~t    ‚W5QRXW5QRXd
S) zžEnsures that truncated documentation is written out
 
    TODO: Test to ensure this has no effect without --latex-doc
    CLI :: --latex-doc --short-latex
    r\r,rgr-z --latex-doc --short-latexrjú./rkrlNrmrprrrÚtest_shortlatexlsý  ruc
Cs–t|ƒ}d}| tdd|›d|›d ¡¡t |j¡Ttƒ| ¡\}}d|ksXt    ‚td|›dƒ 
¡}d    |  ¡ks~t    ‚W5QRXW5QRXd
S) zIEnsures that RsT documentation is written out
 
    CLI :: --rest-doc
    r\r,rgr-z  --rest-docú#ReST Documentation is saved to filertz module.restz.. -*- rest -*-Nrm)r9r&r:r;rr<r=ZorstrrrÚ test_restdoc‚sÿ  rwc    Csft|ƒ}d}| tdd|›d|›d ¡¡t |j¡$tƒ| ¡\}}d|ksXt    ‚W5QRXdS)zLEnsures that TeX documentation is written out
 
    CLI :: --no-rest-doc
    r\r,rgr-z --no-rest-docrvNr?rrrrrÚtest_norestexdoc”sÿ rxc
Cs~t|ƒ}d}| tdd|›d|›d ¡¡t |j¡<tƒtd|›dƒ ¡}d|     ¡ksft
‚W5QRXW5QRXd    S)
zIEnsures that debugging wrappers are written
 
    CLI :: --debug-capi
    r\r,rgr-z  --debug-capirtr
z#define DEBUGCFUNCSN© rr0r1r2rr3r4r5rnror7)r9r&r:r;rÚocmodrrrÚtest_debugcapi¤sÿr{zConsistently fails on CI.)Úreasonc    Cs’t|ƒ}d}| tdd|›d|›d ¡¡t |j¡Ptƒt d¡}t    j
|ddd    }d
}t   d ¡}|j |ksvt‚|j|ks„t‚W5QRXd S) zEEnsures that debugging wrappers work
 
    CLI :: --debug-capi -c
    r\r,rgr-z -c --debug-capiz#python3 -c "import blah; blah.hi()"TúUTF-8©Úcapture_outputrú  Hello World
a debug-capi:Python C/API function blah.hi()
debug-capi:float hi=:output,hidden,scalar
debug-capi:hi=0
debug-capi:Fortran subroutine `f2pywraphi(&hi)'
debug-capi:hi=0
debug-capi:Building return value.
debug-capi:Python C/API function blah.hi: successful.
debug-capi:Freeing memory.
        N)rr0r1r2rr3r4r5ÚshlexÚ
subprocessÚrunÚtextwrapÚdedentÚstdoutr7Ústderr)r&r:r;rÚcmd_runÚroutÚeoutZeerrrrrÚtest_debugcapi_bld´sÿ
 
 
r‹c    Csºt|ƒ}d}| tdd|›d|› ¡¡t |j¡ tƒW5QRX| ¡\}}d|ks`t    ‚| tdd|›d|›d ¡¡t |j¡$tƒ| ¡\}}d|ks¬t    ‚W5QRXdS)zoEnsures that fortran subroutine wrappers for F77 are included by default
 
    CLI :: --[no]-wrap-functions
    r\r,rgr-ú Fortran 77 wrappers are saved toz --wrap-functionsNr?rrrrrÚtest_wrapfunc_defÒs  ÿ rc    Csft|ƒ}d}| tdd|›d|›d ¡¡t |j¡$tƒ| ¡\}}d|ksXt    ‚W5QRXdS)zeEnsures that fortran subroutine wrappers for F77 can be disabled
 
    CLI :: --no-wrap-functions
    r\r,rgr-z --no-wrap-functionsrŒNr?rrrrrÚtest_nowrapfuncësÿ rŽc
CsŽt|ƒ}d}| tdd|›d|›d ¡¡t |j¡Ltƒtd|›dƒ ¡&}|     ¡}d|ksjt
‚d    |ksvt
‚W5QRXW5QRXd
S) zcAdd to the include directories
 
    CLI :: -include
    TODO: Document this in the help string
    r\r,rgr-z' -include<stdbool.h> -include<stdio.h> rtr
z#include <stdbool.h>z#include <stdio.h>Nry)r9r&r:r;rrzZocmrrrrÚtest_inclheaderûsý rcCsdS)z?Add to the include directories
 
    CLI :: --include-paths
    NrrrrrÚ test_inclpathsrcCsdS)z;Add to the include directories
 
    CLI :: --help-link
    NrrrrrÚ
test_hlinksr‘c    CsŒt|ƒ}| tdd|›d ¡¡t |j¡Ttƒ| ¡\}}d|ksNt    ‚d|ksZt    ‚d|ksft    ‚d|ksrt    ‚d|ks~t    ‚W5QRXd    S)
zOCheck that Fortran-to-Python KIND specs can be passed
 
    CLI :: --f2cmap
    r,ú f2py -m blah z --f2cmap mapfilez!Reading f2cmap from 'mapfile' ...z&Mapping "real(kind=real32)" to "float"z'Mapping "real(kind=real64)" to "double"z,Mapping "integer(kind=int64)" to "long_long"z0Successfully applied user defined f2cmap changesNr?)r9r+r:r;r<r=rrrÚ test_f2cmap$s     r“c    Cs`t|ƒ}| tdd|›d ¡¡t |j¡(tƒ| ¡\}}t    |ƒdksRt
‚W5QRXdS)z)Reduce verbosity
 
    CLI :: --quiet
    r,r’z --quietrN) rr0r1r2rr3r4r5r6Úlenr7r@rrrÚ
test_quiet6s  r•c    Cs\t|ƒ}| tdd|›d ¡¡t |j¡$tƒ| ¡\}}d|ksNt    ‚W5QRXdS)z-Increase verbosity
 
    CLI :: --verbose
    r,r’z
 --verboseZ analyzelineNr?r@rrrÚ test_verboseDs  r–c    CsX| tdd ¡¡t t¡2tƒ| ¡\}}ddl}|j    | 
¡ksJt ‚W5QRXdS)z"Ensure version
 
    CLI :: -v
    r,zf2py -vrN) r0r1r2rErFrGr5r6ÚnumpyÚ __version__Ústripr7)r9r:r<r=ÚnprrrÚ test_versionRs   r›c    Cspt|ƒ}| tdd|›d ¡¡t |j¡8tƒt d¡}t    j
|ddd}d}|j |ksbt ‚W5QRXd    S)
z
    CLI :: -c
    r,r’z -cz"python -c "import blah; blah.hi()"Tr}r~r€N) rr0r1r2rr3r4r5rr‚rƒr†r7)r&r:r;rˆr‰rŠrrrÚ test_npdistop`s
rœcCsdS)z
    CLI :: -c --fcompiler
    NrrrrrÚtest_npd_fcompilertsrcCsdS)z
    CLI :: -c --compiler
    NrrrrrÚtest_npd_compiler|sržcCsdS)z$
    CLI :: -c --help-fcompiler
    NrrrrrÚtest_npd_help_fcompiler„srŸcCsdS)z
    CLI :: -c --f77exec
    NrrrrrÚtest_npd_f77execŒsr cCsdS)z
    CLI :: -c --f90exec
    NrrrrrÚtest_npd_f90exec”sr¡cCsdS)z
    CLI :: -c --f77flags
    NrrrrrÚtest_npd_f77flagsœsr¢cCsdS)z
    CLI :: -c --f90flags
    NrrrrrÚtest_npd_f90flags¤sr£cCsdS)z
    CLI :: -c --opt
    NrrrrrÚ test_npd_opt¬sr¤cCsdS)z
    CLI :: -c --arch
    NrrrrrÚ test_npd_arch´sr¥cCsdS)z
    CLI :: -c --noopt
    NrrrrrÚtest_npd_noopt¼sr¦cCsdS)z
    CLI :: -c --noarch
    NrrrrrÚtest_npd_noarchÄsr§cCsdS)z
    CLI :: -c --debug
    NrrrrrÚtest_npd_debugÌsr¨cCsdS)z%
    CLI :: -c --link-<resource>
    NrrrrrÚtest_npd_link_autoÔsr©cCsdS)z/
    CLI :: -c -L/path/to/lib/ -l<libname>
    NrrrrrÚ test_npd_libÜsrªcCsdS)z
    CLI :: -D<define>
    NrrrrrÚtest_npd_defineäsr«cCsdS)z
    CLI :: -U<name>
    NrrrrrÚtest_npd_undefineìsr¬cCsdS)z$
    CLI :: -I/path/to/include/
    NrrrrrÚ test_npd_inclôsr­cCsdS)z8
    CLI :: <filename>.o <filename>.so <filename>.a
    NrrrrrÚtest_npd_linkerüsr®)r)Fr„rar1r‚rÚpathlibrÚ collectionsrrEÚrZnumpy.f2py.f2py2err5rrZfixturer&r(r)r+r>rArIÚmarkZxfailrXr[r^r`rerfrhrirqrsrurwrxr{r‹rrŽrrr‘r“r•r–r›rœrržrŸr r¡r¢r£r¤r¥r¦r§r¨r©rªr«r¬r­r®rrrrÚ<module>s€(    
 
'
 
 
 
 
 
 
 
 
'