pythonunit-testingfortranf2py

Tell f2py to skip a function


I am using f2py to compile a Fortran library such that I can import it in python so that I can easily create unit tests. However, one of the functions in the module uses an allocatable array to read a matrix from a file (the size of the matrix is not know until it is read). Unfortunately, f2py does not support allocatable arrays so compilation fails.

Can I tell f2py to ignore only the problematic function using a comment in the module?

I know it is possible to skip a list of functions specified at compile time, but I was hoping there was a solution that could be implemented in the source file, like the !f2py comments that modify how parameters are treated by f2py.


Solution

  • In the f2py docs here it says that you can skip a function by doing this:

      f2py -h <filename.pyf> <options> <fortran files>   \
          [[ only: <fortran functions>  : ]                \
           [ skip: <fortran functions>  : ]]...            \
          [<fortran files> ...]
    

    where skip:"" can be used to skip any function you dont want to execute.