From da678f6cec288fc94b612c1fd5e1c8c64e94f228 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Sun, 10 Dec 2023 01:18:37 +0000 Subject: [PATCH 1/2] TST: Add one for gh-25337 Co-authored-by: andrea-bia --- numpy/f2py/tests/src/regression/gh25337/data.f90 | 8 ++++++++ numpy/f2py/tests/src/regression/gh25337/use_data.f90 | 6 ++++++ numpy/f2py/tests/test_regression.py | 11 +++++++++++ 3 files changed, 25 insertions(+) create mode 100644 numpy/f2py/tests/src/regression/gh25337/data.f90 create mode 100644 numpy/f2py/tests/src/regression/gh25337/use_data.f90 diff --git a/numpy/f2py/tests/src/regression/gh25337/data.f90 b/numpy/f2py/tests/src/regression/gh25337/data.f90 new file mode 100644 index 000000000000..483d13ceb95c --- /dev/null +++ b/numpy/f2py/tests/src/regression/gh25337/data.f90 @@ -0,0 +1,8 @@ +module data + real(8) :: shift +contains + subroutine set_shift(in_shift) + real(8), intent(in) :: in_shift + shift = in_shift + end subroutine set_shift +end module data diff --git a/numpy/f2py/tests/src/regression/gh25337/use_data.f90 b/numpy/f2py/tests/src/regression/gh25337/use_data.f90 new file mode 100644 index 000000000000..b3fae8b875d0 --- /dev/null +++ b/numpy/f2py/tests/src/regression/gh25337/use_data.f90 @@ -0,0 +1,6 @@ +subroutine shift_a(dim_a, a) + use data, only: shift + integer, intent(in) :: dim_a + real(8), intent(inout), dimension(dim_a) :: a + a = a + shift +end subroutine shift_a diff --git a/numpy/f2py/tests/test_regression.py b/numpy/f2py/tests/test_regression.py index 044f952f2268..1c1097830943 100644 --- a/numpy/f2py/tests/test_regression.py +++ b/numpy/f2py/tests/test_regression.py @@ -64,3 +64,14 @@ def test_include_path(): fnames_in_dir = os.listdir(incdir) for fname in ("fortranobject.c", "fortranobject.h"): assert fname in fnames_in_dir + + +class TestModuleAndSubroutine(util.F2PyTest): + module_name = "example" + sources = [util.getpath("tests", "src", "regression", "gh25337", "data.f90"), + util.getpath("tests", "src", "regression", "gh25337", "use_data.f90")] + + @pytest.mark.slow + def test_gh25337(self): + self.module.data.set_shift(3) + assert "data" in dir(self.module) From 0cbdf62de7db42e47ce69e3f26e1fefb39fc1911 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Sun, 10 Dec 2023 01:20:12 +0000 Subject: [PATCH 2/2] BUG: Fix gh-25337 [f2py] --- numpy/f2py/f90mod_rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/f2py/f90mod_rules.py b/numpy/f2py/f90mod_rules.py index f0074c56b56f..2f8a8dc1878a 100644 --- a/numpy/f2py/f90mod_rules.py +++ b/numpy/f2py/f90mod_rules.py @@ -112,7 +112,7 @@ def dadd(line, s=doc): mfargs.append(n) outmess('\t\tConstructing F90 module support for "%s"...\n' % (m['name'])) - if m['name'] in usenames: + if m['name'] in usenames and not onlyvars: outmess(f"\t\t\tSkipping {m['name']} since it is in 'use'...\n") continue if onlyvars: