Skip to content

Commit

Permalink
Merge pull request numpy#25361 from HaoZeke/gh25337f2yregre
Browse files Browse the repository at this point in the history
BUG: Fix regression with `f2py` wrappers when modules and subroutines are present
  • Loading branch information
charris authored Dec 10, 2023
2 parents a5b67bb + 0cbdf62 commit 35c4319
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/f2py/f90mod_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions numpy/f2py/tests/src/regression/gh25337/data.f90
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions numpy/f2py/tests/src/regression/gh25337/use_data.f90
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions numpy/f2py/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 35c4319

Please sign in to comment.