From f2f9e7dd432f7ed45d79b63944a25e9c4c3766d2 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Thu, 19 Dec 2024 10:30:49 +0100 Subject: [PATCH 1/2] add support for temporarily disabling requirement that all template values must resolve via EasyConfig.expect_resolved_template_values --- easybuild/framework/easyconfig/easyconfig.py | 7 +++++-- test/framework/easyconfig.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/easybuild/framework/easyconfig/easyconfig.py b/easybuild/framework/easyconfig/easyconfig.py index 08505316a5..a61417575f 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) 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.""" From 2d49e8f0954a011db41d55040f19d6fc76df5e8b Mon Sep 17 00:00:00 2001 From: Alex Domingo Date: Thu, 19 Dec 2024 11:27:57 +0100 Subject: [PATCH 2/2] fix description comment of expect_resolved_template_values --- easybuild/framework/easyconfig/easyconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easybuild/framework/easyconfig/easyconfig.py b/easybuild/framework/easyconfig/easyconfig.py index a61417575f..1d476c9868 100644 --- a/easybuild/framework/easyconfig/easyconfig.py +++ b/easybuild/framework/easyconfig/easyconfig.py @@ -430,7 +430,7 @@ def __init__(self, path, extra_options=None, build_specs=None, validate=True, hi self.template_values = None # 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) in easyblocks + # 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)