From 0bf54d3a01c3e93a346611f2140b8423b83ff3dd Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Mon, 20 Mar 2023 03:32:26 +0000 Subject: [PATCH 1/7] incorrect hello-f2py --- projects/hello-f2py/CMakeLists.txt | 9 +++++++++ projects/hello-f2py/hello/CMakeLists.txt | 8 ++++++++ projects/hello-f2py/hello/__init__.py | 1 + projects/hello-f2py/hello/_hello.pyf | 14 ++++++++++++++ projects/hello-f2py/hello/hello.f90 | 7 +++++++ projects/hello-f2py/pyproject.toml | 20 ++++++++++++++++++++ projects/hello-f2py/setup.py | 3 +++ 7 files changed, 62 insertions(+) create mode 100644 projects/hello-f2py/CMakeLists.txt create mode 100644 projects/hello-f2py/hello/CMakeLists.txt create mode 100644 projects/hello-f2py/hello/__init__.py create mode 100644 projects/hello-f2py/hello/_hello.pyf create mode 100644 projects/hello-f2py/hello/hello.f90 create mode 100644 projects/hello-f2py/pyproject.toml create mode 100644 projects/hello-f2py/setup.py diff --git a/projects/hello-f2py/CMakeLists.txt b/projects/hello-f2py/CMakeLists.txt new file mode 100644 index 0000000..f41fe26 --- /dev/null +++ b/projects/hello-f2py/CMakeLists.txt @@ -0,0 +1,9 @@ +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) + +add_subdirectory(hello) diff --git a/projects/hello-f2py/hello/CMakeLists.txt b/projects/hello-f2py/hello/CMakeLists.txt new file mode 100644 index 0000000..0011470 --- /dev/null +++ b/projects/hello-f2py/hello/CMakeLists.txt @@ -0,0 +1,8 @@ +add_f2py_target(_hello _hello.pyf hello.f90) +add_library(_hello STATIC ${_hello}) +python_extension_module(_hello) + +target_link_libraries(_hello ${F2PY_LIBRARIES}) +target_include_directories(_hello PRIVATE ${F2PY_INCLUDE_DIRS}) + +install(TARGETS _hello LIBRARY DESTINATION hello) diff --git a/projects/hello-f2py/hello/__init__.py b/projects/hello-f2py/hello/__init__.py new file mode 100644 index 0000000..f24756e --- /dev/null +++ b/projects/hello-f2py/hello/__init__.py @@ -0,0 +1 @@ +from ._hello import hello diff --git a/projects/hello-f2py/hello/_hello.pyf b/projects/hello-f2py/hello/_hello.pyf new file mode 100644 index 0000000..82a939e --- /dev/null +++ b/projects/hello-f2py/hello/_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*(*) :: 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/hello.f90 b/projects/hello-f2py/hello/hello.f90 new file mode 100644 index 0000000..835d4ce --- /dev/null +++ b/projects/hello-f2py/hello/hello.f90 @@ -0,0 +1,7 @@ +! 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) + character(len=*) :: a + print *,"Hello, " // a // "!" +end subroutine hello diff --git a/projects/hello-f2py/pyproject.toml b/projects/hello-f2py/pyproject.toml new file mode 100644 index 0000000..84fad21 --- /dev/null +++ b/projects/hello-f2py/pyproject.toml @@ -0,0 +1,20 @@ +[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" + +[build-system] +requires = [ + "setuptools>=42", + "scikit-build>=0.13", + "cmake>=3.18", + "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..f01a0b7 --- /dev/null +++ b/projects/hello-f2py/setup.py @@ -0,0 +1,3 @@ +from skbuild import setup + +setup(packages=["hello"]) From a65845ee73321b91a477b728ba591b86a9ac81f4 Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Mon, 20 Mar 2023 12:43:20 +0000 Subject: [PATCH 2/7] tried MODULE and STATIC --- projects/hello-f2py/hello/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/hello-f2py/hello/CMakeLists.txt b/projects/hello-f2py/hello/CMakeLists.txt index 0011470..d64cc99 100644 --- a/projects/hello-f2py/hello/CMakeLists.txt +++ b/projects/hello-f2py/hello/CMakeLists.txt @@ -1,5 +1,5 @@ add_f2py_target(_hello _hello.pyf hello.f90) -add_library(_hello STATIC ${_hello}) +add_library(_hello MODULE ${_hello}) python_extension_module(_hello) target_link_libraries(_hello ${F2PY_LIBRARIES}) From 5c11213b25797ff5df22a6f2801fe7e9c8977032 Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Mon, 20 Mar 2023 13:34:48 +0000 Subject: [PATCH 3/7] distinct import; working test --- projects/hello-f2py/CMakeLists.txt | 2 +- projects/hello-f2py/{hello => hello_f2py}/CMakeLists.txt | 0 projects/hello-f2py/{hello => hello_f2py}/__init__.py | 0 projects/hello-f2py/{hello => hello_f2py}/_hello.pyf | 2 +- projects/hello-f2py/{hello => hello_f2py}/hello.f90 | 2 +- projects/hello-f2py/setup.py | 2 +- projects/hello-f2py/tests/test_hello_f2py.py | 7 +++++++ 7 files changed, 11 insertions(+), 4 deletions(-) rename projects/hello-f2py/{hello => hello_f2py}/CMakeLists.txt (100%) rename projects/hello-f2py/{hello => hello_f2py}/__init__.py (100%) rename projects/hello-f2py/{hello => hello_f2py}/_hello.pyf (90%) rename projects/hello-f2py/{hello => hello_f2py}/hello.f90 (84%) create mode 100644 projects/hello-f2py/tests/test_hello_f2py.py diff --git a/projects/hello-f2py/CMakeLists.txt b/projects/hello-f2py/CMakeLists.txt index f41fe26..d2e6975 100644 --- a/projects/hello-f2py/CMakeLists.txt +++ b/projects/hello-f2py/CMakeLists.txt @@ -6,4 +6,4 @@ find_package(PythonExtensions REQUIRED) find_package(NumPy REQUIRED) find_package(F2PY REQUIRED) -add_subdirectory(hello) +add_subdirectory(hello_f2py) diff --git a/projects/hello-f2py/hello/CMakeLists.txt b/projects/hello-f2py/hello_f2py/CMakeLists.txt similarity index 100% rename from projects/hello-f2py/hello/CMakeLists.txt rename to projects/hello-f2py/hello_f2py/CMakeLists.txt diff --git a/projects/hello-f2py/hello/__init__.py b/projects/hello-f2py/hello_f2py/__init__.py similarity index 100% rename from projects/hello-f2py/hello/__init__.py rename to projects/hello-f2py/hello_f2py/__init__.py diff --git a/projects/hello-f2py/hello/_hello.pyf b/projects/hello-f2py/hello_f2py/_hello.pyf similarity index 90% rename from projects/hello-f2py/hello/_hello.pyf rename to projects/hello-f2py/hello_f2py/_hello.pyf index 82a939e..bfe250f 100644 --- a/projects/hello-f2py/hello/_hello.pyf +++ b/projects/hello-f2py/hello_f2py/_hello.pyf @@ -4,7 +4,7 @@ python module _hello ! in interface ! in :_hello subroutine hello(a) ! in :_hello:hello.f90 - character*(*) :: a + character*(*) intent(in) :: a end subroutine hello end interface end python module _hello diff --git a/projects/hello-f2py/hello/hello.f90 b/projects/hello-f2py/hello_f2py/hello.f90 similarity index 84% rename from projects/hello-f2py/hello/hello.f90 rename to projects/hello-f2py/hello_f2py/hello.f90 index 835d4ce..3f5aa88 100644 --- a/projects/hello-f2py/hello/hello.f90 +++ b/projects/hello-f2py/hello_f2py/hello.f90 @@ -3,5 +3,5 @@ ! and edit if helpful (see F2PY docs) subroutine hello(a) character(len=*) :: a - print *,"Hello, " // a // "!" + print "(a)", "Hello, " // a // "!" end subroutine hello diff --git a/projects/hello-f2py/setup.py b/projects/hello-f2py/setup.py index f01a0b7..0244e7b 100644 --- a/projects/hello-f2py/setup.py +++ b/projects/hello-f2py/setup.py @@ -1,3 +1,3 @@ from skbuild import setup -setup(packages=["hello"]) +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..afe33e5 --- /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") + print('Hello, World!') + captured = capfd.readouterr() + assert captured.out == "Hello, World!\n" From dec78ae7721bc10b1c5ee7e132eec245981f80f7 Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Mon, 20 Mar 2023 14:57:58 +0000 Subject: [PATCH 4/7] fix install path, apply fPIC flag --- projects/hello-f2py/CMakeLists.txt | 3 +++ projects/hello-f2py/hello_f2py/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/hello-f2py/CMakeLists.txt b/projects/hello-f2py/CMakeLists.txt index d2e6975..cb89b1a 100644 --- a/projects/hello-f2py/CMakeLists.txt +++ b/projects/hello-f2py/CMakeLists.txt @@ -6,4 +6,7 @@ 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 index d64cc99..8c75559 100644 --- a/projects/hello-f2py/hello_f2py/CMakeLists.txt +++ b/projects/hello-f2py/hello_f2py/CMakeLists.txt @@ -5,4 +5,4 @@ python_extension_module(_hello) target_link_libraries(_hello ${F2PY_LIBRARIES}) target_include_directories(_hello PRIVATE ${F2PY_INCLUDE_DIRS}) -install(TARGETS _hello LIBRARY DESTINATION hello) +install(TARGETS _hello LIBRARY DESTINATION hello_f2py) From 6afe07f4e8e26575e608378a7e34cfc26f3e5ef8 Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Mon, 20 Mar 2023 20:13:42 +0000 Subject: [PATCH 5/7] hello-f2py passing pytest --- projects/hello-f2py/hello_f2py/CMakeLists.txt | 7 +++---- projects/hello-f2py/hello_f2py/hello.f90 | 4 +++- projects/hello-f2py/pyproject.toml | 9 ++++++--- projects/hello-f2py/tests/test_hello_f2py.py | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/projects/hello-f2py/hello_f2py/CMakeLists.txt b/projects/hello-f2py/hello_f2py/CMakeLists.txt index 8c75559..9e04a55 100644 --- a/projects/hello-f2py/hello_f2py/CMakeLists.txt +++ b/projects/hello-f2py/hello_f2py/CMakeLists.txt @@ -1,8 +1,7 @@ -add_f2py_target(_hello _hello.pyf hello.f90) -add_library(_hello MODULE ${_hello}) -python_extension_module(_hello) - +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/hello.f90 b/projects/hello-f2py/hello_f2py/hello.f90 index 3f5aa88..5fe6c29 100644 --- a/projects/hello-f2py/hello_f2py/hello.f90 +++ b/projects/hello-f2py/hello_f2py/hello.f90 @@ -2,6 +2,8 @@ ! $ 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 // "!" + print '(A)', 'Hello, ' // a // '!' + flush(OUTPUT_UNIT) end subroutine hello diff --git a/projects/hello-f2py/pyproject.toml b/projects/hello-f2py/pyproject.toml index 84fad21..fb4afd1 100644 --- a/projects/hello-f2py/pyproject.toml +++ b/projects/hello-f2py/pyproject.toml @@ -7,12 +7,15 @@ authors = [ ] license = {text = "MIT"} requires-python = ">=3.7" +dependencies = [ + "numpy", +] [build-system] requires = [ - "setuptools>=42", - "scikit-build>=0.13", - "cmake>=3.18", + "setuptools", + "scikit-build", + "cmake", "ninja", "cython", "numpy", diff --git a/projects/hello-f2py/tests/test_hello_f2py.py b/projects/hello-f2py/tests/test_hello_f2py.py index afe33e5..5bf6d44 100644 --- a/projects/hello-f2py/tests/test_hello_f2py.py +++ b/projects/hello-f2py/tests/test_hello_f2py.py @@ -1,7 +1,7 @@ from hello_f2py import hello + def test_hello(capfd): - #hello("World") - print('Hello, World!') + hello('World') captured = capfd.readouterr() - assert captured.out == "Hello, World!\n" + assert captured.out == 'Hello, World!\n' From d756a5397d813698a32d1631239b35562dd33cd7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 03:56:24 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- projects/hello-f2py/hello_f2py/__init__.py | 1 - projects/hello-f2py/hello_f2py/_hello.pyf | 4 ++-- projects/hello-f2py/tests/test_hello_f2py.py | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/projects/hello-f2py/hello_f2py/__init__.py b/projects/hello-f2py/hello_f2py/__init__.py index f24756e..e69de29 100644 --- a/projects/hello-f2py/hello_f2py/__init__.py +++ b/projects/hello-f2py/hello_f2py/__init__.py @@ -1 +0,0 @@ -from ._hello import hello diff --git a/projects/hello-f2py/hello_f2py/_hello.pyf b/projects/hello-f2py/hello_f2py/_hello.pyf index bfe250f..17b820a 100644 --- a/projects/hello-f2py/hello_f2py/_hello.pyf +++ b/projects/hello-f2py/hello_f2py/_hello.pyf @@ -1,12 +1,12 @@ ! -*- f90 -*- ! Note: the context of this file is case sensitive. -python module _hello ! in +python module _hello ! in interface ! in :_hello subroutine hello(a) ! in :_hello:hello.f90 character*(*) intent(in) :: a end subroutine hello - end interface + end interface end python module _hello ! This file was auto-generated with f2py (version:1.24.2). diff --git a/projects/hello-f2py/tests/test_hello_f2py.py b/projects/hello-f2py/tests/test_hello_f2py.py index 5bf6d44..5c88af2 100644 --- a/projects/hello-f2py/tests/test_hello_f2py.py +++ b/projects/hello-f2py/tests/test_hello_f2py.py @@ -2,6 +2,6 @@ def test_hello(capfd): - hello('World') + hello("World") captured = capfd.readouterr() - assert captured.out == 'Hello, World!\n' + assert captured.out == "Hello, World!\n" From c4d48e8f366356f860d12798926321b7daa3795e Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Wed, 22 Mar 2023 00:03:19 -0400 Subject: [PATCH 7/7] thanks, pre-commit bot --- projects/hello-f2py/hello_f2py/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/hello-f2py/hello_f2py/__init__.py b/projects/hello-f2py/hello_f2py/__init__.py index e69de29..2aaf8a7 100644 --- a/projects/hello-f2py/hello_f2py/__init__.py +++ b/projects/hello-f2py/hello_f2py/__init__.py @@ -0,0 +1,3 @@ +from ._hello import hello + +__all__ = ("hello",)