Skip to content

Commit ab3aee3

Browse files
committed
BUG: Fix handling of f2py directives with --lower
Closes numpygh-2547, numpygh-27697, numpygh-26681
1 parent bd1f606 commit ab3aee3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

numpy/f2py/crackfortran.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,14 @@ def readfortrancode(ffile, dowithline=show, istop=1):
425425
if l[-1] not in "\n\r\f":
426426
break
427427
l = l[:-1]
428+
# Do not lower for directives, gh-2547, gh-27697, gh-26681
429+
is_f2py_directive = False
428430
# Unconditionally remove comments
429431
(l, rl) = split_by_unquoted(l, '!')
430432
l += ' '
431433
if rl[:5].lower() == '!f2py': # f2py directive
432434
l, _ = split_by_unquoted(l + 4 * ' ' + rl[5:], '!')
435+
is_f2py_directive = True
433436
if l.strip() == '': # Skip empty line
434437
if sourcecodeform == 'free':
435438
# In free form, a statement continues in the next line
@@ -449,6 +452,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
449452
if l[0] in ['*', 'c', '!', 'C', '#']:
450453
if l[1:5].lower() == 'f2py': # f2py directive
451454
l = ' ' + l[5:]
455+
is_f2py_directive = True
452456
else: # Skip comment line
453457
cont = False
454458
continue
@@ -476,7 +480,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
476480
else:
477481
# clean up line beginning from possible digits.
478482
l = ' ' + l[5:]
479-
if localdolowercase:
483+
if localdolowercase and not is_f2py_directive:
480484
finalline = ll.lower()
481485
else:
482486
finalline = ll
@@ -504,7 +508,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
504508
finalline = ''
505509
origfinalline = ''
506510
else:
507-
if localdolowercase:
511+
if localdolowercase and not is_f2py_directive:
508512
finalline = ll.lower()
509513
else:
510514
finalline = ll
@@ -537,7 +541,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
537541
else:
538542
dowithline(finalline)
539543
l1 = ll
540-
if localdolowercase:
544+
if localdolowercase and not is_f2py_directive:
541545
finalline = ll.lower()
542546
else:
543547
finalline = ll

0 commit comments

Comments
 (0)