Skip to content

Commit

Permalink
prettify: fix uninentional fprettify skip on Fypp directives
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero committed Jan 23, 2020
1 parent 7ea03aa commit edd8f97
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tools/prettify/prettify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import argparse
import errno
import traceback
import contextlib

try:
from hashlib import md5
Expand Down Expand Up @@ -116,6 +117,14 @@
)


@contextlib.contextmanager
def rewind(fhandle):
try:
yield fhandle
finally:
fhandle.seek(0)


def upcaseStringKeywords(line):
"""Upcases the fortran keywords, operators and intrinsic routines
in line"""
Expand Down Expand Up @@ -322,12 +331,13 @@ def is_fypp(infile):
FYPP_RE = re.compile(r"(" + FYPP_LINE + r"|" + FYPP_INLINE + r")")

infile.seek(0)
for line in infile.readlines():
if FYPP_RE.search(line):
return True

infile.seek(0)
return False
with rewind(infile) as fhandle:
for line in fhandle.readlines():
if FYPP_RE.search(line):
return True

return False


# based on https://stackoverflow.com/a/31347222
Expand Down

0 comments on commit edd8f97

Please sign in to comment.