Skip to content

Commit

Permalink
Merge pull request easybuilders#4726 from boegel/expect_resolved_temp…
Browse files Browse the repository at this point in the history
…late_values

add support for temporarily disabling requirement that all template values must resolve via `EasyConfig.expect_resolved_template_values`
  • Loading branch information
lexming authored Dec 19, 2024
2 parents d336035 + 2d49e8f commit 2fd30ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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."""

Expand Down

0 comments on commit 2fd30ae

Please sign in to comment.