-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vars on separate lines in ternarysolvetrack and method types, draft f…
…ortran style check script
- Loading branch information
Showing
8 changed files
with
685 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import argparse | ||
from pathlib import Path | ||
from contextlib import nullcontext | ||
from warnings import warn | ||
|
||
|
||
def separate_lines(path, overwrite=False): | ||
"""Variables defined on separate lines""" | ||
lines = open(path, "r").read().splitlines() | ||
with (open(path, "w") if overwrite else nullcontext()) as f : | ||
for line in lines: | ||
rprt = line.rpartition("::") | ||
if len(rprt[0]) == 0 and len(rprt[1]) == 0: | ||
if overwrite: | ||
f.write(line + "\n") | ||
else: | ||
print(line) | ||
continue | ||
if "(" in rprt[2] or ")" in rprt[2]: | ||
if overwrite: | ||
f.write(line + "\n") | ||
else: | ||
print(line) | ||
continue | ||
typ = rprt[0].split(",")[0].strip() | ||
spl = rprt[2].split(",") | ||
if len(spl) == 1: | ||
if overwrite: | ||
f.write(line + "\n") | ||
else: | ||
print(line) | ||
continue | ||
prev = "" | ||
for s in spl: | ||
l = typ + " :: " + s.strip() | ||
prev += l if "(" in s else "" | ||
if prev: | ||
prev += "," | ||
continue | ||
if overwrite: | ||
f.write(prev + l + "\n") | ||
else: | ||
print(prev + l) | ||
prev = "" | ||
|
||
|
||
def no_return_statements(path, overwrite=False): | ||
"""Remove return statements at the end of routines""" | ||
# todo | ||
pass | ||
|
||
|
||
def no_empty_comments(path, overwrite=False): | ||
"""Remove comments on lines with only whitespace""" | ||
# todo | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
"MODFLOW 6 fortran format source code style checks" | ||
) | ||
parser.add_argument( | ||
"-i", | ||
"--input", | ||
help="path to input file" # todo: or directory | ||
) | ||
parser.add_argument( | ||
"-f", | ||
"--force", | ||
action="store_true", | ||
default=False, | ||
required=False, | ||
help="overwrite/reformat files", | ||
) | ||
parser.add_argument( | ||
"-v", | ||
"--verbose", | ||
action="store_true", | ||
default=False, | ||
required=False, | ||
help="show verbose output", | ||
) | ||
parser.add_argument( | ||
"--sep-lines", | ||
action="store_true", | ||
default=True, | ||
required=False, | ||
help="define variables on separate lines", | ||
) | ||
parser.add_argument( | ||
"--no-return", | ||
action="store_true", | ||
default=False, | ||
required=False, | ||
help="no return statements at the end of routines", | ||
) | ||
parser.add_argument( | ||
"--no-emptyc", | ||
action="store_true", | ||
default=False, | ||
required=False, | ||
help="no empty comments" | ||
) | ||
args = parser.parse_args() | ||
input_path = Path(args.input).expanduser().absolute() | ||
if args.sep_lines: | ||
separate_lines(input_path, overwrite=args.force) | ||
if args.no_return: | ||
no_return_statements(input_path, overwrite=args.force) | ||
warn("--no-return not implemented yet") | ||
if args.no_emptyc: | ||
no_empty_comments(input_path, overwrite=args.force) | ||
warn("--no-emptyc not implemented yet") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.