Skip to content

Commit

Permalink
Add separator argument for variable modifications
Browse files Browse the repository at this point in the history
This commit adds the ability for variable modification directives to
define the separator between their modification value and the previous
value.

This argument is only used when the method is `append` or `prepend.
  • Loading branch information
douglasjacobsen committed Oct 18, 2024
1 parent 3fa2222 commit 0d1344a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 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 @@ -53,7 +53,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 @@ -64,6 +66,8 @@ def variable_modification(name, modification, method="set", mode=None, modes=Non
method: How the modification should be applied
mode: Single mode to group this modification into
modes: List of modes to group this modification into
separator: Optional separator to use when modifying with 'append' or
'prepend' methods.
Supported values are 'append', 'prepend', and 'set':
Expand Down Expand Up @@ -94,6 +98,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

0 comments on commit 0d1344a

Please sign in to comment.