Skip to content

Commit 0021425

Browse files
Merge pull request #956 from douglasjacobsen/prevent-strip-expander
Move `lstrip` from expander to output capture suffix
2 parents 16d0393 + 6d6ee44 commit 0021425

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

lib/ramble/ramble/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ def _define_commands(
11431143
suffix_part = f"{redirect}{bg_cmd}"
11441144

11451145
expanded_cmd = self.expander.expand_var(command_part, exec_vars)
1146-
suffix_cmd = self.expander.expand_var(suffix_part, exec_vars)
1146+
suffix_cmd = self.expander.expand_var(suffix_part, exec_vars).lstrip()
11471147

11481148
self._command_list.append(expanded_cmd + " " + suffix_cmd)
11491149
self._command_list_without_logs.append(expanded_cmd)

lib/ramble/ramble/expander.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def expand_var(
597597
try:
598598
value = self._partial_expand(
599599
expansions, str(var), allow_passthrough=passthrough_setting
600-
).lstrip()
600+
)
601601
except RamblePassthroughError as e:
602602
if not passthrough_setting:
603603
raise RambleSyntaxError(

lib/ramble/ramble/test/end_to_end/formatted_executables.py

+89
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,92 @@ def test_object_formatted_executables(mock_modifiers, request):
190190
with open(exec_path) as f:
191191
data = f.read()
192192
assert ' FROM_MOD echo "Test formatted exec"' in data
193+
194+
195+
def test_nested_formatted_executables_are_properly_formatted(request):
196+
test_config = r"""
197+
ramble:
198+
variables:
199+
mpi_command: 'mpirun -n {n_ranks} -ppn {processes_per_node}'
200+
batch_submit: '{execute_experiment}'
201+
processes_per_node: '16'
202+
n_threads: '1'
203+
formatted_executables:
204+
level_one:
205+
prefix: 'test_l1 '
206+
indentation: 2
207+
join_separator: '\n'
208+
commands:
209+
- 'l1line1'
210+
- 'l1line2'
211+
- 'l1line3'
212+
level_two:
213+
prefix: 'test_l2 '
214+
join_separator: '\n'
215+
indentation: 2
216+
commands:
217+
- 'l2line1'
218+
- 'l2line2'
219+
- '{level_one}'
220+
level_three:
221+
prefix: 'test_l3 '
222+
join_separator: '\n'
223+
indentation: 2
224+
commands:
225+
- 'l3line1'
226+
- '{level_two}'
227+
applications:
228+
basic:
229+
workloads:
230+
working_wl:
231+
experiments:
232+
simple_test:
233+
variables:
234+
n_nodes: 1
235+
software:
236+
packages: {}
237+
environments: {}
238+
"""
239+
workspace_name = request.node.name
240+
with ramble.workspace.create(workspace_name) as ws:
241+
ws.write()
242+
243+
config_path = os.path.join(ws.config_dir, ramble.workspace.config_file_name)
244+
245+
with open(config_path, "w+") as f:
246+
f.write(test_config)
247+
248+
with open(os.path.join(ws.config_dir, "execute_experiment.tpl"), "w+") as f:
249+
f.write("{level_three}\n")
250+
f.write("\n\n {level_three}\n")
251+
ws._re_read()
252+
253+
workspace("setup", "--dry-run", global_args=["-w", workspace_name])
254+
255+
experiment_root = ws.experiment_dir
256+
exp_dir = os.path.join(experiment_root, "basic", "working_wl", "simple_test")
257+
exp_script = os.path.join(exp_dir, "execute_experiment")
258+
259+
import re
260+
261+
test_regexes = [
262+
re.compile(r"^ test_l3 l3line1$"),
263+
re.compile(r"^ test_l3 test_l2 l2line1$"),
264+
re.compile(r"^ test_l3 test_l2 test_l1 l1line1$"),
265+
re.compile(r"^ test_l3 l3line1$"),
266+
]
267+
268+
tests = [
269+
False,
270+
False,
271+
False,
272+
False,
273+
]
274+
275+
with open(exp_script) as f:
276+
for line in f.readlines():
277+
for idx, regex in enumerate(test_regexes):
278+
if regex.search(line):
279+
tests[idx] = True
280+
281+
assert all(tests)

0 commit comments

Comments
 (0)