Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be0589e

Browse files
HaoZekejmrohwer
andauthored
BUG: Fix module name bug in signature files [urgent] [f2py] (#25267)
* TST: Add one for gh-25263 Co-authored-by: jmrohwer <[email protected]> * BUG: Handle modules correctly for F77 Closes gh-25263 --------- Co-authored-by: jmrohwer <[email protected]>
1 parent fa27a66 commit be0589e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

numpy/f2py/f2py2e.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,17 @@ def run_main(comline_list):
455455
pyf_files, _ = filter_files("", "[.]pyf([.]src|)", comline_list)
456456
# Checks that no existing modulename is defined in a pyf file
457457
# TODO: Remove all this when scaninputline is replaced
458-
if "-h" not in comline_list and args.module_name: # Can't check what doesn't exist yet, -h creates the pyf
459-
modname = validate_modulename(pyf_files, args.module_name)
460-
comline_list += ['-m', modname] # needed for the rest of scaninputline
458+
modname = "untitled" # Default
459+
if args.module_name:
460+
if "-h" in comline_list:
461+
modname = (
462+
args.module_name
463+
) # Directly use from args when -h is present
464+
else:
465+
modname = validate_modulename(
466+
pyf_files, args.module_name
467+
) # Validate modname when -h is not present
468+
comline_list += ['-m', modname] # needed for the rest of scaninputline
461469
# gh-22819 -- end
462470
files, options = scaninputline(comline_list)
463471
auxfuncs.options = options

numpy/f2py/tests/test_f2py2e.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ def test_mod_gen_f77(capfd, hello_world_f90, monkeypatch):
339339
assert Path.exists(foutl.wrap77)
340340

341341

342+
def test_mod_gen_gh25263(capfd, hello_world_f77, monkeypatch):
343+
"""Check that pyf files are correctly generated with module structure
344+
CLI :: -m <name> -h pyf_file
345+
BUG: numpy-gh #20520
346+
"""
347+
MNAME = "hi"
348+
foutl = get_io_paths(hello_world_f77, mname=MNAME)
349+
ipath = foutl.finp
350+
monkeypatch.setattr(sys, "argv", f'f2py {ipath} -m {MNAME} -h hi.pyf'.split())
351+
with util.switchdir(ipath.parent):
352+
f2pycli()
353+
with Path('hi.pyf').open() as hipyf:
354+
pyfdat = hipyf.read()
355+
assert "python module hi" in pyfdat
356+
357+
342358
def test_lower_cmod(capfd, hello_world_f77, monkeypatch):
343359
"""Lowers cases by flag or when -h is present
344360

0 commit comments

Comments
 (0)