10000 BUG: Fix multiple modules in F2PY and COMMON handling by HaoZeke · Pull Request #27695 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix multiple modules in F2PY and COMMON handling #27695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion numpy/f2py/auxfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'isunsigned_long_long', 'isunsigned_long_longarray', 'isunsigned_short',
'isunsigned_shortarray', 'l_and', 'l_not', 'l_or', 'outmess', 'replace',
'show', 'stripcomma', 'throw_error', 'isattr_value', 'getuseblocks',
'process_f2cmap_dict'
'process_f2cmap_dict', 'containscommon'
]


Expand Down
8 changes: 3 additions & 5 deletions numpy/f2py/f90mod_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ def dadd(line, s=doc):

usenames = getuseblocks(pymod)
for m in findf90modules(pymod):
contains_functions_or_subroutines = any(
item for item in m["body"] if item["block"] in ["function", "subroutine"]
)
sargs, fargs, efargs, modobjs, notvars, onlyvars = [], [], [], [], [
m['name']], []
sargsp = []
Expand All @@ -120,8 +117,9 @@ def dadd(line, s=doc):
outmess(f"\t\t\tSkipping {m['name']} since there are no public vars/func in this module...\n")
continue

if m['name'] in usenames and not contains_functions_or_subroutines:
outmess(f"\t\t\tSkipping {m['name']} since it is in 'use'...\n")
# gh-25186
if m['name'] in usenames and containscommon(m):
outmess(f"\t\t\tSkipping {m['name']} since it is in 'use' and contains a common block...\n")
continue
if onlyvars:
outmess('\t\t Variables: %s\n' % (' '.join(onlyvars)))
Expand Down
17 changes: 17 additions & 0 deletions numpy/f2py/tests/src/regression/datonly.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module datonly
implicit none
integer, parameter :: max_value = 100
real, dimension(:), allocatable :: data_array
end module datonly

module dat
implicit none
integer, parameter :: max_= 1009
end module dat

subroutine simple_subroutine(ain, aout)
use dat, only: max_
integer, intent(in) :: ain
integer, intent(out) :: aout
aout = ain + max_
end subroutine simple_subroutine
12 changes: 12 additions & 0 deletions numpy/f2py/tests/test_regression.py
< 528F /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def test_inout(self):
assert np.allclose(x, [3, 1, 2])


class TestDataOnlyMultiModule(util.F2PyTest):
# Check that modules without subroutines work
sources = [util.getpath("tests", "src", "regression", "datonly.f90")]

@pytest.mark.slow
def test_mdat(self):
assert self.module.datonly.max_value == 100
assert self.module.dat.max_ == 1009
int_in = 5
assert self.module.simple_subroutine(5) == 1014


class TestNegativeBounds(util.F2PyTest):
# Check that negative bounds work correctly
sources = [util.getpath("tests", "src", "negative_bounds", "issue_20853.f90")]
Expand Down
Loading
0