Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate options that only use as default for other options #118

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
20 changes: 5 additions & 15 deletions src/boutupgrader/bout_v5_factory_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def find_factory_calls(factory, source):
\s*=\s*
{factory_name}::
.*{create_method}.*
""".format(
**factory
),
""".format(**factory),
source,
re.VERBOSE,
)
Expand All @@ -72,9 +70,7 @@ def find_type_pointers(factory, source):
r"""
\b{type_name}\s*\*\s* # Type name and pointer
([\w_]+)\s*; # Variable name
""".format(
**factory
),
""".format(**factory),
source,
re.VERBOSE,
)
Expand Down Expand Up @@ -104,9 +100,7 @@ def fix_declarations(factory, variables, source):
(.*?)(class\s*)? # optional "class" keyword
\b({type_name})\s*\*\s* # Type-pointer
({variable_name})\s*; # Variable
""".format(
type_name=factory["type_name"], variable_name=variable
),
""".format(type_name=factory["type_name"], variable_name=variable),
r"\1std::unique_ptr<\3> \4{nullptr};",
source,
flags=re.VERBOSE,
Expand All @@ -120,9 +114,7 @@ def fix_declarations(factory, variables, source):
({variable_name})\s* # Variable
=\s* # Assignment from factory
({factory_name}::.*{create_method}.*);
""".format(
variable_name=variable, **factory
),
""".format(variable_name=variable, **factory),
r"\1auto \4 = \5;",
source,
flags=re.VERBOSE,
Expand All @@ -136,9 +128,7 @@ def fix_declarations(factory, variables, source):
({variable_name})\s* # Variable
=\s* # Assignment
(0|nullptr|NULL);
""".format(
variable_name=variable, **factory
),
""".format(variable_name=variable, **factory),
r"\1std::unique_ptr<\2> \3{nullptr};",
source,
flags=re.VERBOSE,
Expand Down
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)
5 changes: 0 additions & 5 deletions src/boutupgrader/bout_v6_coordinates_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


def add_parser(subcommand, default_args, files_args):

help_text = textwrap.dedent(
"""\
Upgrade files to use the refactored Coordinates class.
Expand Down Expand Up @@ -85,7 +84,6 @@ def indices_of_matching_lines(pattern, lines):


def use_metric_accessors(original_string):

lines = original_string.splitlines()

line_matches = SETTING_METRIC_COMPONENT_REGEX.findall(original_string)
Expand Down Expand Up @@ -138,7 +136,6 @@ def remove_geometry_calls(lines):


def assignment_regex_pairs(var):

arrow_or_dot = r"\b.+\-\>|\."
not_followed_by_equals = r"(?!\s?=)"
equals_something = r"\=\s?(.+)(?=;)"
Expand Down Expand Up @@ -174,7 +171,6 @@ def replacement_for_division_assignment(match):


def mesh_get_pattern_and_replacement():

# Convert `mesh->get(coord->dx(), "dx")` to `coord->setDx(mesh->get("dx"));`, etc

def replacement_for_assignment_with_mesh_get(match):
Expand All @@ -196,7 +192,6 @@ def replacement_for_assignment_with_mesh_get(match):

# Deal with the basic find-and-replace cases that do not involve multiple lines
def replace_one_line_cases(modified):

metric_component = r"g_?\d\d"
mesh_spacing = r"d[xyz]"

Expand Down
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_v5_input_file_upgrader import add_parser_general, run_general

# This should be a list of dicts, each containing "old", "new" and optionally "new_values".
# 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)