Skip to content

Commit 2ca5178

Browse files
committed
Tolerate some "none-looking" names in variant setting
With the change, all the following would point to the None pkgman: ``` package_manager: null package_manager: None package_manager: '' package_manager: 'None' package_manager: 'none' ```
1 parent 5d866b0 commit 2ca5178

File tree

2 files changed

+78
-7
lines changed

2 files changed

+78
-7
lines changed

lib/ramble/ramble/application.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ def _get_phase_func_wrapper(workspace, phase_func, phase_name):
130130
return profiler(phase_func)
131131

132132

133+
def _canonical_none(maybe_none):
134+
"""Convert a small set of "none-looking" inputs to None"""
135+
if maybe_none == "":
136+
return None
137+
if isinstance(maybe_none, str) and maybe_none.lower() == "none":
138+
return None
139+
return maybe_none
140+
141+
133142
class ApplicationBase(metaclass=ApplicationMeta):
134143
name = None
135144
_builtin_name = NS_SEPARATOR.join(("builtin", "{name}"))
@@ -280,8 +289,8 @@ def set_variants(self, variants):
280289

281290
def _set_package_manager(self):
282291
if namespace.package_manager in self.variants:
283-
pkgman_name = self.expander.expand_var(
284-
self.variants[namespace.package_manager], typed=True
292+
pkgman_name = _canonical_none(
293+
self.expander.expand_var(self.variants[namespace.package_manager], typed=True)
285294
)
286295

287296
if pkgman_name is not None:
@@ -310,18 +319,18 @@ def _set_package_manager(self):
310319

311320
def _set_workflow_manager(self):
312321
if namespace.workflow_manager in self.variants:
313-
workflow_name = self.expander.expand_var(
314-
self.variants[namespace.workflow_manager], typed=True
322+
wm_name = _canonical_none(
323+
self.expander.expand_var(self.variants[namespace.workflow_manager], typed=True)
315324
)
316325

317-
if workflow_name is not None:
326+
if wm_name is not None:
318327
try:
319328
wfman_type = ramble.repository.ObjectTypes.workflow_managers
320-
self.workflow_manager = ramble.repository.get(workflow_name, wfman_type).copy()
329+
self.workflow_manager = ramble.repository.get(wm_name, wfman_type).copy()
321330
self.workflow_manager.set_application(self)
322331
except ramble.repository.UnknownObjectError:
323332
logger.die(
324-
f"{workflow_name} is not a valid workflow manager. "
333+
f"{wm_name} is not a valid workflow manager. "
325334
"Valid workflow managers can be listed via:\n"
326335
"\tramble list --type workflow_managers"
327336
)
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])

0 commit comments

Comments
 (0)