8000 BUG: Fix gh-25867 for used functions and subroutines by HaoZeke · Pull Request #25881 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix gh-25867 for used functions and subroutines #25881

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 3 commits into from
Feb 25, 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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ numpy/version.py linguist-generated
# F2py
./doc/source/f2py/*.pyf text
./doc/source/f2py/*.dat text
./numpy/f2py/tests/src/module_data/mod.mod binary

# Documents
*.md text diff=markdown
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GTAGS
*.o.d
*.py[ocd]
*.so
*.mod

# Packages #
############
Expand Down
5 changes: 4 additions & 1 deletion numpy/f2py/f90mod_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ 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 @@ -112,7 +115,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 and not onlyvars:
if m['name'] in usenames and not contains_functions_or_subroutines:
outmess(f"\t\t\tSkipping {m['name']} since it is in 'use'...\n")
continue
if onlyvars:
Expand Down
Binary file removed numpy/f2py/tests/src/module_data/mod.mod
Binary file not shown.
20 changes: 20 additions & 0 deletions numpy/f2py/tests/src/modules/use_modules.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module mathops
implicit none
contains
function add(a, b) result(c)
integer, intent(in) :: a, b
integer :: c
c = a + b
end function add
end module mathops

module useops
use mathops, only: add
implicit none
contains
function sum_and_double(a, b) result(d)
integer, intent(in) :: a, b
integer :: d
d = 2 * add(a, b)
end function sum_and_double
end module useops
28 changes: 0 additions & 28 deletions numpy/f2py/tests/test_module_doc.py

This file was deleted.

50 changes: 50 additions & 0 deletions numpy/f2py/tests/test_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
import textwrap

from . import util
from numpy.testing import IS_PYPY


@pytest.mark.slow
class TestModuleDocString(util.F2PyTest):
sources = [util.getpath("tests", "src", "modules", "module_data_docstring.f90")]

@pytest.mark.xfail(IS_PYPY, reason="PyPy cannot modify tp_doc after PyType_Ready")
def test_module_docstring(self):
assert self.module.mod.__doc__ == textwrap.dedent(
"""\
i : 'i'-scalar
x : 'i'-array(4)
a : 'f'-array(2,3)
b : 'f'-array(-1,-1), not allocated\x00
foo()\n
Wrapper for ``foo``.\n\n"""
)


@pytest.mark.slow
class TestModuleAndSubroutine(util.F2PyTest):
module_name = "example"
sources = [
util.getpath("tests", "src", "modules", "gh25337", "data.f90"),
util.getpath("tests", "src", "modules", "gh25337", "use_data.f90"),
]

def test_gh25337(self):
self.module.data.set_shift(3)
assert "data" in dir(self.module)


@pytest.mark.slow
class TestUsedModule(util.F2PyTest):
module_name = "fmath"
sources = [
util.getpath("tests", "src", "modules", "use_modules.f90"),
]

def test_gh25867(self):
compiled_mods = [x for x in dir(self.module) if "__" not in x]
assert "useops" in compiled_mods
assert self.module.useops.sum_and_double(3, 7) == 20
assert "mathops" in compiled_mods
assert self.module.mathops.add(3, 7) == 10
11 changes: 0 additions & 11 deletions numpy/f2py/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ def test_include_path():
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)


class TestIncludeFiles(util.F2PyTest):
sources = [util.getpath("tests", "src", "regression", "incfile.f90")]
options = [f"-I{util.getpath('tests', 'src', 'regression')}",
Expand Down
0