Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading