Skip to content

Commit 753c5e5

Browse files
authored
Merge pull request #704 from douglasjacobsen/variable-mod-separator
Add separator functionality to variable modification directives
2 parents 18a8f5d + bb6e0b3 commit 753c5e5

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

lib/ramble/ramble/language/modifier_language.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ def _execute_default_mode(mod):
6161

6262

6363
@modifier_directive("variable_modifications")
64-
def variable_modification(name, modification, method="set", mode=None, modes=None, **kwargs):
64+
def variable_modification(
65+
name, modification, method="set", mode=None, modes=None, separator=" ", **kwargs
66+
):
6567
"""Define a new variable modification for a mode in this modifier.
6668
6769
A variable modification will apply a change to a defined variable within an experiment.
@@ -72,6 +74,8 @@ def variable_modification(name, modification, method="set", mode=None, modes=Non
7274
method (str): How the modification should be applied
7375
mode (str): Single mode to group this modification into
7476
modes (str): List of modes to group this modification into
77+
separator (str): Optional separator to use when modifying with 'append' or
78+
'prepend' methods.
7579
7680
Supported values are 'append', 'prepend', and 'set':
7781
'append' will add the modification to the end of 'name'
@@ -98,6 +102,7 @@ def _execute_variable_modification(mod):
98102
mod.variable_modifications[mode_name][name] = {
99103
"modification": modification,
100104
"method": method,
105+
"separator": separator,
101106
}
102107

103108
return _execute_variable_modification

lib/ramble/ramble/modifier.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,15 @@ def modded_variables(self, app, extra_vars={}):
150150
else:
151151
prev_val = ""
152152

153+
if prev_val != "" and prev_val is not None:
154+
sep = var_mod["separator"]
155+
else:
156+
sep = ""
157+
153158
if var_mod["method"] == "append":
154-
mods[var] = f'{prev_val}{var_mod["modification"]}'
159+
mods[var] = f'{prev_val}{sep}{var_mod["modification"]}'
155160
else: # method == prepend
156-
mods[var] = f'{var_mod["modification"]}{prev_val}'
161+
mods[var] = f'{var_mod["modification"]}{sep}{prev_val}'
157162
else: # method == set
158163
mods[var] = var_mod["modification"]
159164

var/ramble/repos/builtin.mock/modifiers/test-mod-2/modifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TestMod2(BasicModifier):
2525

2626
variable_modification(
2727
"test_var_mod",
28-
" test-mod-2-append",
28+
"test-mod-2-append",
2929
method="append",
3030
modes=["test"],
3131
)

var/ramble/repos/builtin.mock/modifiers/test-mod/modifier.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class TestMod(BasicModifier):
3434

3535
variable_modification(
3636
"test_var_mod",
37-
" test-mod-append",
37+
"test-mod-append",
3838
method="append",
3939
modes=["test"],
4040
)
4141

4242
variable_modification(
4343
"mpi_command",
44-
'echo "prefix_mpi_command" >> {log_file}; ',
44+
'echo "prefix_mpi_command" >> {log_file};',
4545
method="prepend",
4646
modes=["test"],
4747
)

var/ramble/repos/builtin/modifiers/intel-aps/modifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class IntelAps(BasicModifier):
5454
"aps_flags", "-c mpi -r {aps_log_dir}", method="set", modes=["mpi"]
5555
)
5656
variable_modification(
57-
"mpi_command", " aps {aps_flags} ", method="append", modes=["mpi"]
57+
"mpi_command", "aps {aps_flags} ", method="append", modes=["mpi"]
5858
)
5959

6060
modifier_variable(

var/ramble/repos/builtin/modifiers/pyxis-enroot/modifier.py

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def extract_names(itr, name_set=set()):
192192
"container_mounts",
193193
modification=prefix + exp_mount,
194194
method="append",
195+
separator=",",
195196
mode=self._usage_mode,
196197
)
197198

0 commit comments

Comments
 (0)