Skip to content

Fix renaming in case a new section is needed #121

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

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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: 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