Skip to content

Commit bc4a89a

Browse files
workspace concretize: define missing variables and expand software specs
Fixes an issue where running 'ramble workspace concretize' failed with a schema ValidationError (CommentedMap is not of type 'string') when compiler or software specs contained variable templates (e.g., {system_compiler_spec}). Key changes: - Call app_inst.define_missing_variables() during concretize to ensure system, platform, and modifier variables are registered in app_inst.variables. - Add _expand_software_spec() to expand template variables in SoftwareSpec instances (pkg_spec, compiler_spec, compiler) for both compilers and specs. - Add regression unit tests with mock application and modifier in workspace_concretize.py. Signed-off-by: Ching-Lung Hsu <chinglunghsu@google.com>
1 parent b311f41 commit bc4a89a

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

lib/ramble/ramble/test/cmd/workspace_concretize.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,41 @@ def test_workspace_concretize_populated_env_no_warning(workspace_name, capsys):
136136
workspace("concretize", global_args=global_args)
137137
captured = capsys.readouterr()
138138
assert "was auto-constructed" not in captured.err
139+
140+
141+
def test_workspace_concretize_expand_software_spec_variables(
142+
workspace_name, mock_applications, mock_modifiers
143+
):
144+
ws = ramble.workspace.create(workspace_name)
145+
global_args = ["-w", workspace_name]
146+
147+
workspace(
148+
"manage",
149+
"experiments",
150+
"var-compiler-app",
151+
"-V",
152+
"package_manager=spack",
153+
global_args=global_args,
154+
)
155+
workspace(
156+
"manage",
157+
"modifiers",
158+
"--add",
159+
"--name",
160+
"var-compiler-mod",
161+
"--scope",
162+
"workspace",
163+
global_args=global_args,
164+
)
165+
workspace("concretize", global_args=global_args)
166+
167+
with open(ws.config_file_path, encoding="utf-8") as f:
168+
content = f.read()
169+
assert "var-compiler" in content
170+
assert "gcc@12.2.0" in content
171+
assert "{my_compiler_spec}" not in content
172+
assert "var-pkg" in content
173+
assert "zlib@1.2.13" in content
174+
assert "mod-compiler" in content
175+
assert "gcc@13.1.0" in content
176+
assert "{mod_compiler_spec}" not in content

lib/ramble/ramble/workspace/workspace.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,19 @@ def concretize(self, force=False, quiet=False):
15151515

15161516
force_prefix = force_prefix or len(pkgman_prefixes) > 1
15171517

1518+
def _expand_software_spec(spec, expander):
1519+
"""Expand template variables in a SoftwareSpec instance."""
1520+
if spec.pkg_spec:
1521+
spec.pkg_spec = expander.expand_var(spec.pkg_spec)
1522+
if spec.compiler_spec:
1523+
spec.compiler_spec = expander.expand_var(spec.compiler_spec)
1524+
if spec.compiler:
1525+
spec.compiler = expander.expand_var(spec.compiler)
1526+
15181527
for _, app_inst, _ in experiment_set.all_experiments():
15191528
app_inst.build_modifier_instances()
15201529
app_inst.define_variables_for_template_path()
1530+
app_inst.define_missing_variables()
15211531
env_name_str = app_inst.expander.expansion_str(ramble.keywords.keywords.env_name)
15221532
env_name = app_inst.expander.expand_var(env_name_str)
15231533

@@ -1529,6 +1539,8 @@ def concretize(self, force=False, quiet=False):
15291539
)
15301540
for comp, definitions in compiler_packages.items():
15311541
for info in definitions:
1542+
_expand_software_spec(info, app_inst.expander)
1543+
15321544
if (
15331545
not quiet
15341546
and comp in packages_dict
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2022-2026 The Ramble Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
# option. This file may not be copied, modified, or distributed
7+
# except according to those terms.
8+
9+
from ramble.appkit import *
10+
11+
12+
class VarCompilerApp(ExecutableApplication):
13+
"""Test application to verify concretize variable expansion in specs"""
14+
15+
name = "var-compiler-app"
16+
17+
executable("echo", "echo", use_mpi=False)
18+
workload("test_wl", executable="echo")
19+
20+
workload_variable(
21+
"my_compiler_spec",
22+
default="gcc@12.2.0",
23+
description="Compiler spec variable",
24+
workloads=["test_wl"],
25+
)
26+
27+
define_compiler(
28+
"var-compiler",
29+
pkg_spec="{my_compiler_spec}",
30+
compiler_spec="{my_compiler_spec}",
31+
)
32+
33+
software_spec(
34+
"var-pkg",
35+
pkg_spec="zlib@1.2.13",
36+
compiler="var-compiler",
37+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2022-2026 The Ramble Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6+
# option. This file may not be copied, modified, or distributed
7+
# except according to those terms.
8+
9+
from ramble.modkit import *
10+
11+
12+
class VarCompilerMod(BasicModifier):
13+
"""Mock modifier to test concretize variable expansion in compiler specs"""
14+
15+
name = "var-compiler-mod"
16+
tags("test")
17+
18+
mode("test_mode", description="A test mode")
19+
default_mode("test_mode")
20+
21+
variable(
22+
"mod_compiler_spec",
23+
default="gcc@13.1.0",
24+
description="Compiler spec defined in modifier",
25+
modes=["test_mode"],
26+
)
27+
28+
with when("package_manager_family=spack"):
29+
define_compiler(
30+
"mod-compiler",
31+
pkg_spec="{mod_compiler_spec}",
32+
compiler_spec="{mod_compiler_spec}",
33+
)

0 commit comments

Comments
 (0)