Skip to content

Commit 87b3d9d

Browse files
authored
Merge pull request #4913 from Flamefire/get_cuda_cc_template_value-default
Add `required` argument to `get_cuda_cc_template_value`
2 parents b2b9c54 + e5b3e64 commit 87b3d9d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

easybuild/framework/easyconfig/easyconfig.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,17 +1968,22 @@ def asdict(self):
19681968
res[key] = value
19691969
return res
19701970

1971-
def get_cuda_cc_template_value(self, key):
1971+
def get_cuda_cc_template_value(self, key, required=True):
19721972
"""
19731973
Get template value based on --cuda-compute-capabilities EasyBuild configuration option
19741974
and cuda_compute_capabilities easyconfig parameter.
19751975
Returns user-friendly error message in case neither are defined,
19761976
or if an unknown key is used.
1977+
1978+
:param required: If False and the key is not found, return an empty string instead of raising an error.
19771979
"""
19781980
if key.startswith('cuda_') and any(x == key for x in TEMPLATE_NAMES_DYNAMIC):
19791981
try:
19801982
return self.template_values[key]
19811983
except KeyError:
1984+
if not required:
1985+
self.log.debug(f'Key {key} not found in template values, returning empty value')
1986+
return ''
19821987
error_msg = "Template value '%s' is not defined!\n"
19831988
error_msg += "Make sure that either the --cuda-compute-capabilities EasyBuild configuration "
19841989
error_msg += "option is set, or that the cuda_compute_capabilities easyconfig parameter is defined."

test/framework/easyconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5090,6 +5090,7 @@ def test_get_cuda_cc_template_value(self):
50905090
}
50915091
for key in cuda_template_values:
50925092
self.assertErrorRegex(EasyBuildError, error_pattern % key, ec.get_cuda_cc_template_value, key)
5093+
self.assertEqual(ec.get_cuda_cc_template_value(key, required=False), '')
50935094

50945095
update_build_option('cuda_compute_capabilities', ['6.5', '7.0'])
50955096
ec = EasyConfig(self.eb_file)

0 commit comments

Comments
 (0)