diff --git a/projects/hello-f2py/CMakeLists.txt b/projects/hello-f2py/CMakeLists.txt new file mode 100644 index 0000000..cb89b1a --- /dev/null +++ b/projects/hello-f2py/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.5...3.22) + +project(hello LANGUAGES C Fortran) + +find_package(PythonExtensions REQUIRED) +find_package(NumPy REQUIRED) +find_package(F2PY REQUIRED) + +# see https://github.com/scikit-build/scikit-build/pull/495/ +set_target_properties(_f2py_runtime_library PROPERTIES POSITION_INDEPENDENT_CODE ON) + +add_subdirectory(hello_f2py) diff --git a/projects/hello-f2py/hello_f2py/CMakeLists.txt b/projects/hello-f2py/hello_f2py/CMakeLists.txt new file mode 100644 index 0000000..9e04a55 --- /dev/null +++ b/projects/hello-f2py/hello_f2py/CMakeLists.txt @@ -0,0 +1,7 @@ +add_f2py_target(_hello _hello.pyf) +add_library(_hello MODULE ${_hello} hello.f90) +target_link_libraries(_hello ${F2PY_LIBRARIES}) +target_include_directories(_hello PRIVATE ${F2PY_INCLUDE_DIRS}) +python_extension_module(_hello) + +install(TARGETS _hello LIBRARY DESTINATION hello_f2py) diff --git a/projects/hello-f2py/hello_f2py/__init__.py b/projects/hello-f2py/hello_f2py/__init__.py new file mode 100644 index 0000000..2aaf8a7 --- /dev/null +++ b/projects/hello-f2py/hello_f2py/__init__.py @@ -0,0 +1,3 @@ +from ._hello import hello + +__all__ = ("hello",) diff --git a/projects/hello-f2py/hello_f2py/_hello.pyf b/projects/hello-f2py/hello_f2py/_hello.pyf new file mode 100644 index 0000000..17b820a --- /dev/null +++ b/projects/hello-f2py/hello_f2py/_hello.pyf @@ -0,0 +1,14 @@ +! -*- f90 -*- +! Note: the context of this file is case sensitive. + +python module _hello ! in + interface ! in :_hello + subroutine hello(a) ! in :_hello:hello.f90 + character*(*) intent(in) :: a + end subroutine hello + end interface +end python module _hello + +! This file was auto-generated with f2py (version:1.24.2). +! See: +! https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e diff --git a/projects/hello-f2py/hello_f2py/hello.f90 b/projects/hello-f2py/hello_f2py/hello.f90 new file mode 100644 index 0000000..5fe6c29 --- /dev/null +++ b/projects/hello-f2py/hello_f2py/hello.f90 @@ -0,0 +1,9 @@ +! generate a signature file from this file with: +! $ python -m numpy.f2py hello.f90 -m _hello -h _hello.pyf +! and edit if helpful (see F2PY docs) +subroutine hello(a) + use, intrinsic :: iso_fortran_env + character(len=*) :: a + print '(A)', 'Hello, ' // a // '!' + flush(OUTPUT_UNIT) +end subroutine hello diff --git a/projects/hello-f2py/pyproject.toml b/projects/hello-f2py/pyproject.toml new file mode 100644 index 0000000..fb4afd1 --- /dev/null +++ b/projects/hello-f2py/pyproject.toml @@ -0,0 +1,23 @@ +[project] +name = "hello-f2py" +version = "1.2.3" +description = "a minimal example package (cython version)" +authors = [ + {name = "The scikit-build team"}, +] +license = {text = "MIT"} +requires-python = ">=3.7" +dependencies = [ + "numpy", +] + +[build-system] +requires = [ + "setuptools", + "scikit-build", + "cmake", + "ninja", + "cython", + "numpy", +] +build-backend = "setuptools.build_meta" diff --git a/projects/hello-f2py/setup.py b/projects/hello-f2py/setup.py new file mode 100644 index 0000000..0244e7b --- /dev/null +++ b/projects/hello-f2py/setup.py @@ -0,0 +1,3 @@ +from skbuild import setup + +setup(packages=["hello_f2py"]) diff --git a/projects/hello-f2py/tests/test_hello_f2py.py b/projects/hello-f2py/tests/test_hello_f2py.py new file mode 100644 index 0000000..5c88af2 --- /dev/null +++ b/projects/hello-f2py/tests/test_hello_f2py.py @@ -0,0 +1,7 @@ +from hello_f2py import hello + + +def test_hello(capfd): + hello("World") + captured = capfd.readouterr() + assert captured.out == "Hello, World!\n"