Skip to content

Commit

Permalink
Merge pull request #121 from boutproject/fix-no-new-section
Browse files Browse the repository at this point in the history
Fix renaming in case a new section is needed
  • Loading branch information
ZedThree authored Dec 5, 2024
2 parents dfc8fab + e646571 commit 45b639d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/boutdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
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

0 comments on commit 45b639d

Please sign in to comment.