diff --git a/easybuild/framework/easyconfig/easyconfig.py b/easybuild/framework/easyconfig/easyconfig.py index 08505316a5..1d476c9868 100644 --- a/easybuild/framework/easyconfig/easyconfig.py +++ b/easybuild/framework/easyconfig/easyconfig.py @@ -428,7 +428,10 @@ def __init__(self, path, extra_options=None, build_specs=None, validate=True, hi :param local_var_naming_check: mode to use when checking if local variables use the recommended naming scheme """ self.template_values = None - self.enable_templating = True # a boolean to control templating + # a boolean to control templating, can be (temporarily) disabled in easyblocks + self.enable_templating = True + # boolean to control whether all template values must be resolvable, can be (temporarily) disabled in easyblocks + self.expect_resolved_template_values = True self.log = fancylogger.getLogger(self.__class__.__name__, fname=False) @@ -1773,7 +1776,7 @@ def resolve_template(self, value): """Resolve all templates in the given value using this easyconfig""" if not self.template_values: self.generate_template_values() - return resolve_template(value, self.template_values) + return resolve_template(value, self.template_values, expect_resolved=self.expect_resolved_template_values) @handle_deprecated_or_replaced_easyconfig_parameters def __contains__(self, key): diff --git a/test/framework/easyconfig.py b/test/framework/easyconfig.py index e8b1dd0cb7..b1eb2fc7db 100644 --- a/test/framework/easyconfig.py +++ b/test/framework/easyconfig.py @@ -1289,6 +1289,7 @@ def test_ec_method_resolve_template(self): homepage = "http://example.com" description = "test easyconfig %(name)s version %(version_major)s" toolchain = SYSTEM + installopts = "PREFIX=%(installdir)s" """) self.prep() ec = EasyConfig(self.eb_file, validate=False) @@ -1302,6 +1303,22 @@ def test_ec_method_resolve_template(self): self.assertIn('%', description, 'Description needs a template for the next test') self.assertEqual(ec.resolve_template(description), ec['description']) + val = "PREFIX=%(installdir)s" + + # by default unresolved template value triggers an error being raised + error_pattern = "Failed to resolve all templates" + self.assertErrorRegex(EasyBuildError, error_pattern, ec.resolve_template, val) + self.assertErrorRegex(EasyBuildError, error_pattern, ec.get, 'installopts') + + # this can be (temporarily) disabled via expect_resolved_template_values in EasyConfig instance + ec.expect_resolved_template_values = False + self.assertEqual(ec.resolve_template(val), val) + self.assertEqual(ec['installopts'], val) + + ec.expect_resolved_template_values = True + self.assertErrorRegex(EasyBuildError, error_pattern, ec.resolve_template, val) + self.assertErrorRegex(EasyBuildError, error_pattern, ec.get, 'installopts') + def test_templating_cuda_toolchain(self): """Test templates via toolchain component, like setting %(cudaver)s with fosscuda toolchain."""