Skip to content
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

BUG: Fix module name bug in signature files [urgent] [f2py] #25267

Merged
merged 2 commits into from
Nov 30, 2023
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
14 changes: 11 additions & 3 deletions numpy/f2py/f2py2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,17 @@ def run_main(comline_list):
pyf_files, _ = filter_files("", "[.]pyf([.]src|)", comline_list)
# Checks that no existing modulename is defined in a pyf file
# TODO: Remove all this when scaninputline is replaced
if "-h" not in comline_list and args.module_name: # Can't check what doesn't exist yet, -h creates the pyf
modname = validate_modulename(pyf_files, args.module_name)
comline_list += ['-m', modname] # needed for the rest of scaninputline
modname = "untitled" # Default
if args.module_name:
if "-h" in comline_list:
modname = (
args.module_name
) # Directly use from args when -h is present
else:
modname = validate_modulename(
pyf_files, args.module_name
) # Validate modname when -h is not present
comline_list += ['-m', modname] # needed for the rest of scaninputline
# gh-22819 -- end
files, options = scaninputline(comline_list)
auxfuncs.options = options
Expand Down
16 changes: 16 additions & 0 deletions numpy/f2py/tests/test_f2py2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ def test_mod_gen_f77(capfd, hello_world_f90, monkeypatch):
assert Path.exists(foutl.wrap77)


def test_mod_gen_gh25263(capfd, hello_world_f77, monkeypatch):
"""Check that pyf files are correctly generated with module structure
CLI :: -m <name> -h pyf_file
BUG: numpy-gh #20520
"""
MNAME = "hi"
foutl = get_io_paths(hello_world_f77, mname=MNAME)
ipath = foutl.finp
monkeypatch.setattr(sys, "argv", f'f2py {ipath} -m {MNAME} -h hi.pyf'.split())
with util.switchdir(ipath.parent):
f2pycli()
with Path('hi.pyf').open() as hipyf:
pyfdat = hipyf.read()
assert "python module hi" in pyfdat


def test_lower_cmod(capfd, hello_world_f77, monkeypatch):
"""Lowers cases by flag or when -h is present

Expand Down