Skip to content

Commit

Permalink
Merge pull request #704 from douglasjacobsen/variable-mod-separator
Browse files Browse the repository at this point in the history
Add separator functionality to variable modification directives
  • Loading branch information
rfbgo authored Oct 23, 2024
2 parents 18a8f5d + bb6e0b3 commit 753c5e5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/ramble/ramble/language/modifier_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def _execute_default_mode(mod):


@modifier_directive("variable_modifications")
def variable_modification(name, modification, method="set", mode=None, modes=None, **kwargs):
def variable_modification(
name, modification, method="set", mode=None, modes=None, separator=" ", **kwargs
):
"""Define a new variable modification for a mode in this modifier.
A variable modification will apply a change to a defined variable within an experiment.
Expand All @@ -72,6 +74,8 @@ def variable_modification(name, modification, method="set", mode=None, modes=Non
method (str): How the modification should be applied
mode (str): Single mode to group this modification into
modes (str): List of modes to group this modification into
separator (str): Optional separator to use when modifying with 'append' or
'prepend' methods.
Supported values are 'append', 'prepend', and 'set':
'append' will add the modification to the end of 'name'
Expand All @@ -98,6 +102,7 @@ def _execute_variable_modification(mod):
mod.variable_modifications[mode_name][name] = {
"modification": modification,
"method": method,
"separator": separator,
}

return _execute_variable_modification
Expand Down
9 changes: 7 additions & 2 deletions lib/ramble/ramble/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,15 @@ def modded_variables(self, app, extra_vars={}):
else:
prev_val = ""

if prev_val != "" and prev_val is not None:
sep = var_mod["separator"]
else:
sep = ""

if var_mod["method"] == "append":
mods[var] = f'{prev_val}{var_mod["modification"]}'
mods[var] = f'{prev_val}{sep}{var_mod["modification"]}'
else: # method == prepend
mods[var] = f'{var_mod["modification"]}{prev_val}'
mods[var] = f'{var_mod["modification"]}{sep}{prev_val}'
else: # method == set
mods[var] = var_mod["modification"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestMod2(BasicModifier):

variable_modification(
"test_var_mod",
" test-mod-2-append",
"test-mod-2-append",
method="append",
modes=["test"],
)
4 changes: 2 additions & 2 deletions var/ramble/repos/builtin.mock/modifiers/test-mod/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class TestMod(BasicModifier):

variable_modification(
"test_var_mod",
" test-mod-append",
"test-mod-append",
method="append",
modes=["test"],
)

variable_modification(
"mpi_command",
'echo "prefix_mpi_command" >> {log_file}; ',
'echo "prefix_mpi_command" >> {log_file};',
method="prepend",
modes=["test"],
)
Expand Down
2 changes: 1 addition & 1 deletion var/ramble/repos/builtin/modifiers/intel-aps/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class IntelAps(BasicModifier):
"aps_flags", "-c mpi -r {aps_log_dir}", method="set", modes=["mpi"]
)
variable_modification(
"mpi_command", " aps {aps_flags} ", method="append", modes=["mpi"]
"mpi_command", "aps {aps_flags} ", method="append", modes=["mpi"]
)

modifier_variable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def extract_names(itr, name_set=set()):
"container_mounts",
modification=prefix + exp_mount,
method="append",
separator=",",
mode=self._usage_mode,
)

Expand Down

0 comments on commit 753c5e5

Please sign in to comment.