# F2PY CLI tests study Path - https://github.com/HaoZeke/numpy/blob/f2py2eTests/numpy/f2py/tests/test_f2py2e.py - Used to test the frontend CLI of F2PY - Tests use [`hello_world_f90`, `hello_world_f77`, `retreal_f77`] fixtures that return `tmpdir` file paths. - `monkeypatch` fixture patches the command line input (for eg - it changes `pytest runtests.py` to `f2py -h fibfortran.py`). - `f2pycli()`function when executed reads the patched command line and executes F2PY. - **[get_io_paths()](https://github.com/HaoZeke/numpy/blob/f9ee4527726df63d4bedcb14d349dc9e67f84367/numpy/f2py/tests/test_f2py2e.py#L17)** - Returns expected path of output files generated by F2PY after parsing input fortran file. (any of [`hello_world_f90`, `hello_world_f77`, `retreal_f77`] for ex) - Output files generated by F2PY might include pyf, f77 or f90 wrappers and C API module file ### Doubts - **[test_gen_pyf_stdout](https://github.com/HaoZeke/numpy/blob/f9ee4527726df63d4bedcb14d349dc9e67f84367/numpy/f2py/tests/test_f2py2e.py#L98)** - L99. Why are we not testing if pyf file has been written to the stdout. In `test_gen_pyf` we tested that output pyf file was indeed generated? - **[test_inclpath](https://github.com/HaoZeke/numpy/blob/f9ee4527726df63d4bedcb14d349dc9e67f84367/numpy/f2py/tests/test_f2py2e.py#L518)** - Need help understanding --include-paths usage. - Determine how to test this flag. - **-c -help-fcompiler** - Why is `-c` flag necessary to invoke `--help-fcompiler` ### Testing Plans: - [test_f2cmap](https://github.com/HaoZeke/numpy/blob/f9ee4527726df63d4bedcb14d349dc9e67f84367/numpy/f2py/tests/test_f2py2e.py#L536) - --f2cmap flag lacks [documentation](https://numpy.org/doc/stable/f2py/usage.html) - Create a temp file .f2py_f2cmap. Write test f2cmap config and test the generate C API module. - [test_hlink](https://github.com/HaoZeke/numpy/blob/f2py2eTests/numpy/f2py/tests/test_f2py2e.py#L527) 1. Output result of `f2py --help-link` to stdout or a tempfile. 2. Search for various terms like - `fft_opt_info, C compiler, fftw_info,...` etc. ## distutils Flag Meson alternatives | Flag | Alternative | | -------- | -------- | | `--help-fcompiler` | No alternative found | | `--fcompiler` | [Set FC Flag](https://mesonbuild.com/Reference-tables.html#compiler-and-linker-selection-variables) | | `--compiler` | Set CC Flag | **Native File reference Meson** Native files can be used to specify compiler Paths and Flags - [Native Files - Meson](https://mesonbuild.com/Machine-files.html) - Study the meson build system this weekend and understand [NumPy, Meson and F2PY](https://rgoswami.me/posts/numpy-meson-f2py/) - Native file examples show C program compilation, find out Fortran compilationg using Native file ### Interactive F2PY development - Get the environment setup ```bash micromamba create -f environment.yml micromamba activate numpy-dev pip install -e . # EDITABLE MODE ``` Now somewhere in `f2py` sources (only works for the `.py` sources, full rebuilds needed for `.{c,h}` changes): ```python # Add a breakpoint anywhere breakpoint() ``` Finally, run some code, any code which is expected to go over the breakpoint. This will drop you into an interactive `pdb` session. ### Test case ```fortran subroutine foo() print*, "Hello" end subroutine foo ``` ^ Given this - We want to have `f2py -c hello.f90 -m blah` generate a `cpython` module which works (but is built with `meson`) - We want to have `f2py -m blah hello.f90` generate a `build` directory which contains `meson.build` which code generated Basically automating this [part of the documentation](https://numpy.org/doc/stable/f2py/buildtools/meson.html) ### Helpful things - `nm` --> https://en.wikipedia.org/wiki/Nm_%28Unix%29