Skip to content

Commit

Permalink
Merge pull request #4479 from jfgrimm/fix-easyconfig-parameter-deprec…
Browse files Browse the repository at this point in the history
…ation

fix easyconfig parameter deprecation
  • Loading branch information
boegel committed Mar 8, 2024
2 parents 27aab7c + 5c4fd2f commit 5e51cb4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
4 changes: 2 additions & 2 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def triage_easyconfig_params(variables, ec):

for key in variables:
# validations are skipped, just set in the config
if key in ec:
if key in ec or key in DEPRECATED_PARAMETERS.keys():
ec_params[key] = variables[key]
_log.debug("setting config option %s: value %s (type: %s)", key, ec_params[key], type(ec_params[key]))
elif key in REPLACED_PARAMETERS:
Expand Down Expand Up @@ -658,7 +658,7 @@ def set_keys(self, params):
with self.disable_templating():
for key in sorted(params.keys()):
# validations are skipped, just set in the config
if key in self._config.keys():
if key in self._config.keys() or key in DEPRECATED_PARAMETERS.keys():
self[key] = params[key]
self.log.info("setting easyconfig parameter %s: value %s (type: %s)",
key, self[key], type(self[key]))
Expand Down
46 changes: 41 additions & 5 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ def foo(key):
self.assertErrorRegex(EasyBuildError, error_regex, foo, key)

def test_deprecated_easyconfig_parameters(self):
"""Test handling of replaced easyconfig parameters."""
"""Test handling of deprecated easyconfig parameters."""
os.environ.pop('EASYBUILD_DEPRECATED')
easybuild.tools.build_log.CURRENT_VERSION = self.orig_current_version
init_config()
Expand All @@ -1744,10 +1744,13 @@ def test_deprecated_easyconfig_parameters(self):
orig_deprecated_parameters = copy.deepcopy(easyconfig.parser.DEPRECATED_PARAMETERS)
easyconfig.parser.DEPRECATED_PARAMETERS.update({
'foobar': ('barfoo', '0.0'), # deprecated since forever
'foobarbarfoo': ('barfoofoobar', '1000000000'), # won't be actually deprecated for a while
# won't be actually deprecated for a while;
# note that we should map foobarbarfoo to a valid easyconfig parameter here,
# or we'll hit errors when parsing an easyconfig file that uses it
'foobarbarfoo': ('required_linked_shared_libs', '1000000000'),
})

# copy classes before reloading, so we can restore them (other isinstance checks fail)
# copy classes before reloading, so we can restore them (otherwise isinstance checks fail)
orig_EasyConfig = copy.deepcopy(easyconfig.easyconfig.EasyConfig)
orig_ActiveMNS = copy.deepcopy(easyconfig.easyconfig.ActiveMNS)
reload(easyconfig.parser)
Expand All @@ -1772,6 +1775,35 @@ def foo(key):
self.assertEqual(ec[newkey], '123test')
self.assertEqual(ec[key], '123test')

variables = {
'name': 'example',
'version': '1.2.3',
'foobar': 'foobar',
'local_var': 'test',
}
ec = {
'name': None,
'version': None,
'homepage': None,
'toolchain': None,
}
ec_params, unknown_keys = triage_easyconfig_params(variables, ec)
# deprecated easyconfig parameter 'foobar' is retained as easyconfig parameter;
# only local_var is not retained, since that's a local variable
self.assertEqual(unknown_keys, [])
expected = {'name': 'example', 'version': '1.2.3', 'foobar': 'foobar'}
self.assertEqual(ec_params, expected)

# try parsing an easyconfig file that defines a deprecated easyconfig parameter
toy_ec = os.path.join(test_ecs_dir, 't', 'toy', 'toy-0.0.eb')
test_ec = os.path.join(self.test_prefix, 'test.eb')
write_file(test_ec, read_file(toy_ec))
write_file(test_ec, "\nfoobarbarfoo = 'foobarbarfoo'", append=True)

with self.mocked_stdout_stderr():
ec = EasyConfig(test_ec)
self.assertEqual(ec['required_linked_shared_libs'], 'foobarbarfoo')

easyconfig.parser.DEPRECATED_PARAMETERS = orig_deprecated_parameters
reload(easyconfig.parser)
reload(easyconfig.easyconfig)
Expand Down Expand Up @@ -4288,15 +4320,19 @@ def test_triage_easyconfig_params(self):
self.assertEqual(sorted(unknown_keys), ['bleh', 'foobar'])

# check behaviour when easyconfig parameters that use a name indicating a local variable were defined
ec.update({
local_vars = {
'x': None,
'local_foo': None,
'_foo': None,
'_': None,
})
}
ec.update(local_vars)
error = "Found 4 easyconfig parameters that are considered local variables: _, _foo, local_foo, x"
self.assertErrorRegex(EasyBuildError, error, triage_easyconfig_params, variables, ec)

for key in local_vars:
del ec[key]

def test_local_vars_detection(self):
"""Test detection of using unknown easyconfig parameters that are likely local variables."""

Expand Down

0 comments on commit 5e51cb4

Please sign in to comment.