-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #804 from linsword13/template
Add a `register_template` directive to objects
- Loading branch information
Showing
6 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2022-2025 The Ramble Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
import os | ||
import pytest | ||
|
||
import ramble.workspace | ||
from ramble.main import RambleCommand | ||
|
||
pytestmark = pytest.mark.usefixtures( | ||
"mutable_config", "mutable_mock_workspace_path", "mutable_mock_apps_repo" | ||
) | ||
|
||
workspace = RambleCommand("workspace") | ||
|
||
|
||
def test_template(): | ||
test_config = """ | ||
ramble: | ||
variables: | ||
mpi_command: mpirun -n {n_ranks} | ||
batch_submit: 'batch_submit {execute_experiment}' | ||
processes_per_node: 1 | ||
applications: | ||
template: | ||
workloads: | ||
test_template: | ||
experiments: | ||
test: | ||
variables: | ||
n_nodes: 1 | ||
hello_name: santa | ||
""" | ||
workspace_name = "test_template" | ||
ws = ramble.workspace.create(workspace_name) | ||
ws.write() | ||
config_path = os.path.join(ws.config_dir, ramble.workspace.config_file_name) | ||
with open(config_path, "w+") as f: | ||
f.write(test_config) | ||
ws._re_read() | ||
|
||
workspace("setup", "--dry-run", global_args=["-w", workspace_name]) | ||
run_dir = os.path.join(ws.experiment_dir, "template/test_template/test/") | ||
script_path = os.path.join(run_dir, "bar.sh") | ||
assert os.path.isfile(script_path) | ||
with open(script_path) as f: | ||
content = f.read() | ||
assert "echo hello santa" in content | ||
execute_path = os.path.join(run_dir, "execute_experiment") | ||
with open(execute_path) as f: | ||
content = f.read() | ||
assert script_path in content |
39 changes: 39 additions & 0 deletions
39
var/ramble/repos/builtin.mock/applications/template/application.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2022-2025 The Ramble Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
# option. This file may not be copied, modified, or distributed | ||
# except according to those terms. | ||
|
||
from ramble.appkit import * | ||
|
||
|
||
class Template(ExecutableApplication): | ||
"""An app for testing object templates.""" | ||
|
||
name = "template" | ||
|
||
executable("foo", template=["bash {bar}"]) | ||
|
||
workload("test_template", executable="foo") | ||
|
||
workload_variable( | ||
"hello_name", | ||
default="world", | ||
description="hello name", | ||
workload="test_template", | ||
) | ||
|
||
register_phase( | ||
"ingest_dynamic_variables", | ||
pipeline="setup", | ||
run_before=["make_experiments"], | ||
) | ||
|
||
def _ingest_dynamic_variables(self, workspace, app_inst): | ||
expander = self.expander | ||
val = expander.expand_var('"hello {hello_name}"') | ||
self.define_variable("dynamic_hello_world", val) | ||
|
||
register_template("bar", src_name="bar.tpl", dest_name="bar.sh") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
echo {dynamic_hello_world} |