From 4a18ffb98fd70dee12a86927bac0a44e978b3592 Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 2 Dec 2024 14:53:43 +0100 Subject: [PATCH 1/2] Fix renaming in case a new section is needed Fixes #120 --- src/boutdata/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boutdata/data.py b/src/boutdata/data.py index 20171e7..247dc3d 100644 --- a/src/boutdata/data.py +++ b/src/boutdata/data.py @@ -359,7 +359,7 @@ def get_immediate_parent_and_child(path): # Renaming a child key just within the same parent section, we can preserve # the order - if new_parent is old_parent: + if new_parent is old_parent and ":" not in new_name: new_parent._keys = rename_key(new_parent._keys, new_child, old_child) new_parent.comments = rename_key( new_parent.comments, new_child, old_child From e64657104e9f558fdc486520d2b8d8c6935058a7 Mon Sep 17 00:00:00 2001 From: dschwoerer Date: Mon, 2 Dec 2024 14:02:29 +0000 Subject: [PATCH 2/2] [skip ci] Apply black/isort changes --- src/boutupgrader/bout_v5_factory_upgrader.py | 20 +++++-------------- .../bout_v6_coordinates_upgrader.py | 5 ----- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/boutupgrader/bout_v5_factory_upgrader.py b/src/boutupgrader/bout_v5_factory_upgrader.py index 1558fae..ddb7157 100644 --- a/src/boutupgrader/bout_v5_factory_upgrader.py +++ b/src/boutupgrader/bout_v5_factory_upgrader.py @@ -59,9 +59,7 @@ def find_factory_calls(factory, source): \s*=\s* {factory_name}:: .*{create_method}.* - """.format( - **factory - ), + """.format(**factory), source, re.VERBOSE, ) @@ -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, ) @@ -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, @@ -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, @@ -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, diff --git a/src/boutupgrader/bout_v6_coordinates_upgrader.py b/src/boutupgrader/bout_v6_coordinates_upgrader.py index 4dda8f5..8c9feff 100644 --- a/src/boutupgrader/bout_v6_coordinates_upgrader.py +++ b/src/boutupgrader/bout_v6_coordinates_upgrader.py @@ -27,7 +27,6 @@ def add_parser(subcommand, default_args, files_args): - help_text = textwrap.dedent( """\ Upgrade files to use the refactored Coordinates class. @@ -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) @@ -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?(.+)(?=;)" @@ -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): @@ -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]"