Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello-f2py example #35

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

itcarroll
Copy link

Adds a sample project in the style of hello-cython, using the add_f2py_target function provided by scikit-build.

The example also demonstrates the minimal setup.py content when porting package metadata to pyproject.toml.

This would close #29, but so would #32. My goal was to keep it very simple.

@zerothi
Copy link

zerothi commented Apr 3, 2023

Would be great if you could add that the method to create the signature on the fly, something like this:

# The module file for the signatures
set(hello_module "_hello")

# generate the signature file
set(hello_sig "${CMAKE_CURRENT_BINARY_DIR}/_hello_signature.pyf")
add_custom_command(
  OUTPUT ${hello_sig}
  COMMAND ${F2PY_EXECUTABLE} -m ${hello_module} hello.f90 -h ${siesta_sig} --overwrite-signature
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  DEPENDS hello.f90
  COMMENT "Generating signature file files"
  )

then the signature need not be present.

@itcarroll
Copy link
Author

I can add @zerothi 's suggestion if a project maintainer agrees. But, because the F2PY docs suggest manual modifications to the signature after generation, I'm going to leave the example as-is for now.

I don't think the add_f2py_target command is capable of handling the "the quick and smart way", which would avoid signature files altogether.

@zerothi
Copy link

zerothi commented Apr 4, 2023

You are probably right. :)
In the simple cases it is just nice ;)

@itcarroll
Copy link
Author

Welp, this is now failing for me locally. Can't say what changed ... but now CMake claims to generate _hello-f2pywrappers2.f90 but does not, leading the subsequent build step to fail.

[3/13] Generating _hellomodule.c, _hello-f2pywrappers.f, _hello-f2pywrappers2.f90
      Reading fortran codes...
          Reading file '/home/icarroll/tmp/skb/projects/hello-f2py/hello_f2py/_hello.pyf' (format:free)
      Post-processing...
          Block: _hello
                          Block: hello
      Applying post-processing hooks...
        character_backward_compatibility_hook
      Post-processing (stage 2)...
      Building modules...
          Building module "_hello"...
          Generating possibly empty wrappers"
          Maybe empty "_hello-f2pywrappers.f"
              Constructing wrapper function "hello"...
                hello(a)
          Wrote C/API module "_hello" to file "./_hellomodule.c"
      [4/13] Building Fortran preprocessed hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90-pp.f90
      FAILED: hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90-pp.f90 hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90.o.ddi
      /usr/bin/gfortran -cpp -D_hello_EXPORTS -I../../../venv11/lib/python3.11/site-packages/numpy/f2py/src -I../../../venv11/lib/python3.11/site-packages/numpy/core/include -I/home/icarroll/miniconda3/include/python3.11 -O3 -DNDEBUG -O3 -Jhello_f2py -fPIC -E hello_f2py/_hello-f2pywrappers2.f90 -o hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90-pp.f90 && /usr/bin/cmake -E cmake_ninja_depends --tdi=hello_f2py/CMakeFiles/_hello.dir/FortranDependInfo.json --lang=Fortran --src=hello_f2py/_hello-f2pywrappers2.f90 --pp=hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90-pp.f90 --dep=hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90-pp.f90.d --obj=hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90.o --ddi=hello_f2py/CMakeFiles/_hello.dir/_hello-f2pywrappers2.f90.o.ddi
      gfortran: error: hello_f2py/_hello-f2pywrappers2.f90: No such file or directory
      gfortran: fatal error: no input files
      compilation terminated.

@henryiii henryiii mentioned this pull request May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a fortran and f2py example
2 participants