Skip to content

Commit

Permalink
Add input parser for v6
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwoerer committed Dec 2, 2024
1 parent a241feb commit dcefeb2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/boutupgrader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .bout_v5_physics_model_upgrader import add_parser as add_model_parser
from .bout_v5_xzinterpolation_upgrader import add_parser as add_xzinterp_parser
from .bout_v6_coordinates_upgrader import add_parser as add_v6_coordinates_parser
from .bout_v6_input_file_upgrader import add_parser as add_v6_input_parser

try:
# This gives the version if the boututils package was installed
Expand Down Expand Up @@ -71,6 +72,7 @@ def main():
add_model_parser(v5_subcommand, common_args, files_args)
add_xzinterp_parser(v5_subcommand, common_args, files_args)
add_v6_coordinates_parser(v6_subcommand, common_args, files_args)
add_v6_input_parser(v6_subcommand, common_args, files_args)

args = parser.parse_args()
args.func(args)
12 changes: 10 additions & 2 deletions src/boutupgrader/bout_v5_input_file_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def possibly_apply_patch(patch, options_file, quiet=False, force=False):
return make_change


def add_parser(subcommand, default_args, files_args):
def add_parser_general(subcommand, default_args, files_args, run):
parser = subcommand.add_parser(
"input",
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down Expand Up @@ -290,7 +290,7 @@ def add_parser(subcommand, default_args, files_args):
parser.set_defaults(func=run)


def run(args):
def run_general(REPLACEMENTS, DELETED, args):
from boutdata.data import BoutOptions, BoutOptionsFile

# Monkey-patch BoutOptions to make sure it's case sensitive
Expand Down Expand Up @@ -340,3 +340,11 @@ def run(args):
continue

possibly_apply_patch(patch, modified, args.quiet, args.force)


def run(args):
return run_general(REPLACEMENTS, DELETED, args)


def add_parser(subcommand, default_args, files_args):
return add_parser_general(subcommand, default_args, files_args, run)
22 changes: 22 additions & 0 deletions src/boutupgrader/bout_v6_input_file_upgrader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from .bout_v6_input_file_upgrader import run_general, add_parser_general

# This should be a list of dicts, each containing "old", "new" and optionally "new_values".

Check failure on line 3 in src/boutupgrader/bout_v6_input_file_upgrader.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

src/boutupgrader/bout_v6_input_file_upgrader.py:1:1: I001 Import block is un-sorted or un-formatted
# The values of "old"/"new" keys should be the old/new names of input file values or
# sections. The value of "new_values" is a dict containing replacements for values of the
# option. "old_type" optionally specifies the type of the old value of the option; for
# example this is needed for special handling of boolean values.
REPLACEMENTS = [
{"old": "timestep", "new": "solver:output_step"},
{"old": "nout", "new": "solver:nout"},
{"old": "grid", "new": "mesh:file"},
]

DELETED = []


def run(args):
return run_general(REPLACEMENTS, DELETED, args)


def add_parser(subcommand, default_args, files_args):
return add_parser_general(subcommand, default_args, files_args, run)

0 comments on commit dcefeb2

Please sign in to comment.