Skip to content

Commit 01add89

Browse files
Merge pull request #948 from linsword13/variant-name
Tolerate some "none-looking" names in variant setting
2 parents 17e7b9a + 46a2c3f commit 01add89

File tree

4 files changed

+115
-8
lines changed

4 files changed

+115
-8
lines changed

lib/ramble/ramble/application.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from ramble.experiment_result import ExperimentResult
5252
from ramble.language.application_language import ApplicationMeta
5353
from ramble.language.shared_language import SharedMeta, register_builtin, register_phase
54+
from ramble.util import conversions
5455
from ramble.util.foms import FomType
5556
from ramble.util.logger import logger
5657
from ramble.util.naming import NS_SEPARATOR
@@ -59,7 +60,6 @@
5960
from ramble.workspace import namespace
6061

6162
import spack.util.compression
62-
import spack.util.environment
6363
import spack.util.executable
6464
import spack.util.spack_json
6565

@@ -280,8 +280,8 @@ def set_variants(self, variants):
280280

281281
def _set_package_manager(self):
282282
if namespace.package_manager in self.variants:
283-
pkgman_name = self.expander.expand_var(
284-
self.variants[namespace.package_manager], typed=True
283+
pkgman_name = conversions.canonical_none(
284+
self.expander.expand_var(self.variants[namespace.package_manager], typed=True)
285285
)
286286

287287
if pkgman_name is not None:
@@ -310,18 +310,18 @@ def _set_package_manager(self):
310310

311311
def _set_workflow_manager(self):
312312
if namespace.workflow_manager in self.variants:
313-
workflow_name = self.expander.expand_var(
314-
self.variants[namespace.workflow_manager], typed=True
313+
wm_name = conversions.canonical_none(
314+
self.expander.expand_var(self.variants[namespace.workflow_manager], typed=True)
315315
)
316316

317-
if workflow_name is not None:
317+
if wm_name is not None:
318318
try:
319319
wfman_type = ramble.repository.ObjectTypes.workflow_managers
320-
self.workflow_manager = ramble.repository.get(workflow_name, wfman_type).copy()
320+
self.workflow_manager = ramble.repository.get(wm_name, wfman_type).copy()
321321
self.workflow_manager.set_application(self)
322322
except ramble.repository.UnknownObjectError:
323323
logger.die(
324-
f"{workflow_name} is not a valid workflow manager. "
324+
f"{wm_name} is not a valid workflow manager. "
325325
"Valid workflow managers can be listed via:\n"
326326
"\tramble list --type workflow_managers"
327327
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2022-2025 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+
import os
10+
11+
import pytest
12+
13+
import ramble.workspace
14+
from ramble.main import RambleCommand, RambleCommandError
15+
16+
workspace = RambleCommand("workspace")
17+
18+
pytestmark = pytest.mark.usefixtures(
19+
"mutable_config",
20+
"mutable_mock_workspace_path",
21+
)
22+
23+
24+
@pytest.mark.maybeslow
25+
@pytest.mark.parametrize(
26+
"pkgman_name,expect_success_setup",
27+
[
28+
("none", True),
29+
(None, True),
30+
("", True),
31+
("spack", True),
32+
("non-existent-pkgman", False),
33+
],
34+
)
35+
def test_package_manager_names(pkgman_name, expect_success_setup):
36+
ws_name = f"test-{pkgman_name}"
37+
ws = ramble.workspace.create(ws_name)
38+
workspace(
39+
"manage",
40+
"experiments",
41+
"hostname",
42+
"-p",
43+
pkgman_name,
44+
"--wf",
45+
"local",
46+
"-v",
47+
"n_nodes=1",
48+
"-v",
49+
"processes_per_node=1",
50+
"-v",
51+
"mpi_command=''",
52+
"-v",
53+
"batch_submit=''",
54+
global_args=["-w", ws_name],
55+
)
56+
ws._re_read()
57+
if expect_success_setup:
58+
workspace("setup", "--dry-run", global_args=["-D", ws.root])
59+
assert os.path.isfile(os.path.join(ws.log_dir, "setup.latest.out"))
60+
else:
61+
with pytest.raises(RambleCommandError):
62+
workspace("setup", "--dry-run", global_args=["-D", ws.root])
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2022-2025 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+
import pytest
10+
11+
from ramble.util import conversions
12+
13+
14+
@pytest.mark.parametrize(
15+
"input,expect",
16+
[
17+
("not-a-list", "not-a-list"),
18+
("[1,2, 3, a, b, c]", ["1", "2", "3", "a", "b", "c"]),
19+
],
20+
)
21+
def test_list_str_to_list(input, expect):
22+
assert conversions.list_str_to_list(input) == expect
23+
24+
25+
@pytest.mark.parametrize(
26+
"input,expect",
27+
[
28+
(None, None),
29+
("none", None),
30+
("None", None),
31+
("", None),
32+
("other", "other"),
33+
],
34+
)
35+
def test_canonical_none(input, expect):
36+
assert conversions.canonical_none(input) == expect

lib/ramble/ramble/util/conversions.py

+9
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ def list_str_to_list(in_str):
2828
else:
2929
out_value.append(part)
3030
return out_value
31+
32+
33+
def canonical_none(maybe_none):
34+
"""Convert a small set of "none-looking" inputs to None"""
35+
if maybe_none == "":
36+
return None
37+
if isinstance(maybe_none, str) and maybe_none.lower() == "none":
38+
return None
39+
return maybe_none

0 commit comments

Comments
 (0)