@@ -425,11 +425,14 @@ def readfortrancode(ffile, dowithline=show, istop=1):
425
425
if l [- 1 ] not in "\n \r \f " :
426
426
break
427
427
l = l [:- 1 ]
428
+ # Do not lower for directives, gh-2547, gh-27697, gh-26681
429
+ is_f2py_directive = False
428
430
# Unconditionally remove comments
429
431
(l , rl ) = split_by_unquoted (l , '!' )
430
432
l += ' '
431
433
if rl [:5 ].lower () == '!f2py' : # f2py directive
432
434
l , _ = split_by_unquoted (l + 4 * ' ' + rl [5 :], '!' )
435
+ is_f2py_directive = True
433
436
if l .strip () == '' : # Skip empty line
434
437
if sourcecodeform == 'free' :
435
438
# In free form, a statement continues in the next line
@@ -449,6 +452,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
449
452
if l [0 ] in ['*' , 'c' , '!' , 'C' , '#' ]:
450
453
if l [1 :5 ].lower () == 'f2py' : # f2py directive
451
454
l = ' ' + l [5 :]
455
+ is_f2py_directive = True
452
456
else : # Skip comment line
453
457
cont = False
454
458
continue
@@ -476,7 +480,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
476
480
else :
477
481
# clean up line beginning from possible digits.
478
482
l = ' ' + l [5 :]
479
- if localdolowercase :
483
+ if localdolowercase and not is_f2py_directive :
480
484
finalline = ll .lower ()
481
485
else :
482
486
finalline = ll
@@ -504,7 +508,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
504
508
finalline = ''
505
509
origfinalline = ''
506
510
else :
507
- if localdolowercase :
511
+ if localdolowercase and not is_f2py_directive :
508
512
finalline = ll .lower ()
509
513
else :
510
514
finalline = ll
@@ -537,7 +541,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
537
541
else :
538
542
dowithline (finalline )
539
543
l1 = ll
540
- if localdolowercase :
544
+ if localdolowercase and not is_f2py_directive :
541
545
finalline = ll .lower ()
542
546
else :
543
547
finalline = ll
0 commit comments