Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions projects/hello-f2py/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions projects/hello-f2py/hello_f2py/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions projects/hello-f2py/hello_f2py/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._hello import hello

__all__ = ("hello",)
14 changes: 14 additions & 0 deletions projects/hello-f2py/hello_f2py/_hello.pyf
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions projects/hello-f2py/hello_f2py/hello.f90
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions projects/hello-f2py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions projects/hello-f2py/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from skbuild import setup

setup(packages=["hello_f2py"])
7 changes: 7 additions & 0 deletions projects/hello-f2py/tests/test_hello_f2py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from hello_f2py import hello


def test_hello(capfd):
hello("World")
captured = capfd.readouterr()
assert captured.out == "Hello, World!\n"