Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
minghangli-uni committed Aug 2, 2024
1 parent 457037d commit 9275e1b
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions om3utils/MOM6InputParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def __init__(self):
self.current_var = None
self.current_value = []
self.current_comment = []
self.block_pattern = re.compile(
r"|".join(re.escape(i) for i in self.block_list)
)
self.block_pattern = re.compile(r"|".join(re.escape(i) for i in self.block_list))

def read_input(self, MOM_input_read_path):
with open(MOM_input_read_path, "r") as f:
Expand Down Expand Up @@ -67,9 +65,7 @@ def _parse_params(self, line):
param = param.strip()
# separate value and inline comment
tmp_value = value.split("!")[0].strip() # value
tmp_commt = (
value.split("!")[1].strip() if "!" in value else ""
) # inline comment
tmp_commt = value.split("!")[1].strip() if "!" in value else "" # inline comment
self.current_var = param
self.current_value = [tmp_value]
self.current_comment = [tmp_commt]
Expand All @@ -89,22 +85,16 @@ def writefile_MOM_input(self, MOM_input_write_path, total_width=32):
"""
with open(MOM_input_write_path, "w") as f:
f.write("! This file was written by the script xxx \n")
f.write(
"! and records the non-default parameters used at run-time.\n"
)
f.write("! and records the non-default parameters used at run-time.\n")
f.write("\n")
for var, value in self.param_dict.items():
comment = self.commt_dict.get(var, "")
if comment:
comment_lines = comment.split("\n")
param_str = f"{var} = {value}"
f.write(
f"{param_str:<{total_width}} ! {comment_lines[0].strip()}\n"
)
f.write(f"{param_str:<{total_width}} ! {comment_lines[0].strip()}\n")
for comment_line in comment_lines[1:]:
f.write(
f"{'':<{total_width}} {comment_line.strip()}\n"
)
f.write(f"{'':<{total_width}} {comment_line.strip()}\n")
elif var in self.block_list:
f.write(f"{var}\n")
else:
Expand Down

0 comments on commit 9275e1b

Please sign in to comment.