Skip to content
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

Add support for arbitrary commands in formatted executables #634

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: 2 additions & 0 deletions etc/ramble/defaults/formatted_executables.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
formatted_executables:
command:
join_separator: '\n'
commands:
- '{unformatted_command}'
20 changes: 13 additions & 7 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,8 @@ def _define_formatted_executables(self):
based on the formatting requested.
"""

self.variables[self.keywords.unformatted_command] = "\n".join(self._command_list)

for var_name, formatted_conf in self._formatted_executables.items():
if var_name in self.variables:
raise FormattedExecutableError(
Expand All @@ -1159,13 +1161,17 @@ def _define_formatted_executables(self):

indentation = " " * n_indentation

formatted_str = ""
for cmd in self._command_list:
if formatted_str:
formatted_str += join_separator
formatted_str += indentation + prefix + cmd
commands_to_format = self._command_list
if namespace.commands in formatted_conf:
commands_to_format = formatted_conf[namespace.commands].copy()

formatted_lines = []
for command in commands_to_format:
expanded = self.expander.expand_var(command)
for out_line in expanded.split("\n"):
formatted_lines.append(indentation + prefix + out_line)

self.variables[var_name] = formatted_str
self.variables[var_name] = join_separator.join(formatted_lines)

def _derive_variables_for_template_path(self, workspace):
"""Define variables for template paths (for add_expand_vars)"""
Expand Down Expand Up @@ -2135,7 +2141,7 @@ def _copy_files(obj_inst, obj_type, repo_root):

repo_path = os.path.join(workspace.named_deployment, "object_repo")

repo_lock = lk.Lock(repo_path)
repo_lock = lk.Lock(os.path.join(repo_path, ".ramble-obj-repo.lock"))

with lk.WriteTransaction(repo_lock):
_copy_files(self, ramble.repository.ObjectTypes.applications, repo_path)
Expand Down
1 change: 1 addition & 0 deletions lib/ramble/ramble/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"batch_submit": {"type": key_type.required, "level": output_level.variable},
"mpi_command": {"type": key_type.required, "level": output_level.variable},
"experiment_template_name": {"type": key_type.reserved, "level": output_level.key},
"unformatted_command": {"type": key_type.reserved, "level": output_level.variable},
}


Expand Down
1 change: 1 addition & 0 deletions lib/ramble/ramble/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class namespace:
indentation = "indentation"
prefix = "prefix"
join_separator = "join_separator"
commands = "commands"

# For variants
package_manager = "package_manager"
7 changes: 7 additions & 0 deletions lib/ramble/ramble/schema/formatted_executables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"prefix": {"type": "string", "default": ""},
"indentation": {"type": "number", "default": 0},
"join_separator": {"type": "string", "default": "\n"},
"commands": {
"type": "array",
"default": ["{unformatted_command}"],
"items": {
"type": "string",
},
},
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ramble/ramble/test/data/config/formatted_executables.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
formatted_executables:
command:
join_separator: '\n'
commands:
- '{unformatted_command}'
7 changes: 7 additions & 0 deletions lib/ramble/ramble/test/end_to_end/formatted_executables.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def test_formatted_executables(mutable_config, mutable_mock_workspace_path, mock
prefix: 'from_ws '
indentation: 9
join_separator: ';'
ws_test_def:
prefix: 'test_from_ws '
indentation: 2
commands:
- '{mpi_command} test'
applications:
basic:
formatted_executables:
Expand Down Expand Up @@ -74,6 +79,7 @@ def test_formatted_executables(mutable_config, mutable_mock_workspace_path, mock
f.write("{app_exec_def}\n")
f.write("{wl_exec_def}\n")
f.write("{exp_exec_def}\n")
f.write("{ws_test_def}\n")
ws._re_read()

workspace("setup", "--dry-run", global_args=["-w", workspace_name])
Expand All @@ -88,6 +94,7 @@ def test_formatted_executables(mutable_config, mutable_mock_workspace_path, mock
assert ";" + " " * 9 + "from_ws echo" in data
assert "\n" + " " * 11 + "from_wl echo" in data
assert "\n" + " " * 10 + "from_exp echo" in data
assert "\n" + " " * 2 + "test_from_ws mpirun -n 16 -ppn 16 test" in data


def test_redefined_executable_errors(
Expand Down