Skip to content

Commit 7119e75

Browse files
committed
Fix version templates for filtered dependencies
When an architecture specific `None` version is used the check happens too late when we to a shallow/quick parsing of the easyconfig, e.g. in `list_software`.
1 parent bd89045 commit 7119e75

2 files changed

Lines changed: 41 additions & 46 deletions

File tree

easybuild/framework/easyconfig/templates.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,15 @@ def template_constant_dict(config, ignore=None, toolchain=None):
440440
if isinstance(dep_name, str) and dep_version:
441441
pref = name_to_prefix.get(dep_name.lower())
442442
if pref:
443+
# Resolve version if not already done
443444
dep_version = pick_dep_version(dep_version)
444-
template_values['%sver' % pref] = dep_version
445-
dep_version_parts = dep_version.split('.')
446-
template_values['%smajver' % pref] = dep_version_parts[0]
447-
if len(dep_version_parts) > 1:
448-
template_values['%sminver' % pref] = dep_version_parts[1]
449-
template_values['%sshortver' % pref] = '.'.join(dep_version_parts[:2])
445+
if dep_version:
446+
template_values['%sver' % pref] = dep_version
447+
dep_version_parts = dep_version.split('.')
448+
template_values['%smajver' % pref] = dep_version_parts[0]
449+
if len(dep_version_parts) > 1:
450+
template_values['%sminver' % pref] = dep_version_parts[1]
451+
template_values['%sshortver' % pref] = '.'.join(dep_version_parts[:2])
450452

451453
# step 2.1: CUDA templates in NVHPC
452454
if toolchain is not None and hasattr(toolchain, 'name') and toolchain.name in TEMPLATE_CUDA_VERSION_NVHPC:

test/framework/easyconfig.py

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,18 +3687,22 @@ def test_template_constant_dict(self):
36873687
my_arch = st.get_cpu_architecture()
36883688

36893689
# add Java dep with version specified using a dict value
3690-
toy_ec_txt += '\n'.join([
3691-
"dependencies += [",
3692-
" ('Python', '3.7.2'),"
3693-
" ('Java', {",
3694-
" 'arch=%s': '1.8.0_221'," % my_arch,
3695-
" 'arch=fooarch': '1.8.0-foo',",
3696-
" })",
3697-
"]",
3698-
"builddependencies = [",
3699-
" ('CMake', '3.18.4'),",
3700-
"]",
3701-
])
3690+
toy_ec_txt += textwrap.dedent("""
3691+
dependencies += [
3692+
('Python', '3.7.2'),
3693+
('Java', {
3694+
'arch=<arch>': '1.8.0_221',
3695+
'arch=fooarch': '1.8.0-foo',
3696+
}),
3697+
('Perl', {
3698+
'arch=<arch>': False,
3699+
'arch=fooarch': '1.42',
3700+
}),
3701+
]
3702+
builddependencies = [
3703+
('CMake', '3.18.4'),
3704+
]
3705+
""").replace('<arch>', my_arch)
37023706

37033707
test_ec = os.path.join(self.test_prefix, 'test.eb')
37043708
write_file(test_ec, toy_ec_txt)
@@ -3733,39 +3737,28 @@ def test_template_constant_dict(self):
37333737
}
37343738

37353739
# proper EasyConfig instance
3736-
ec = EasyConfig(test_ec)
3737-
3738-
# CMake should *not* be included, since it's a build-only dependency
3739-
dep_names = [x['name'] for x in ec['dependencies']]
3740-
self.assertFalse('CMake' in dep_names, "CMake should not be included in list of dependencies: %s" % dep_names)
3741-
res = template_constant_dict(ec)
3742-
dep_names = [x['name'] for x in ec['dependencies']]
3743-
self.assertFalse('CMake' in dep_names, "CMake should not be included in list of dependencies: %s" % dep_names)
3744-
3745-
self.assertIn('arch', res)
3746-
arch = res.pop('arch')
3747-
self.assertTrue(arch_regex.match(arch), "'%s' matches with pattern '%s'" % (arch, arch_regex.pattern))
3748-
3749-
self.assertEqual(res, expected)
3750-
3740+
full_ec = EasyConfig(test_ec)
3741+
expected_full = expected
37513742
# only perform shallow/quick parse (as is done in list_software function)
3752-
ec = EasyConfigParser(filename=test_ec).get_config_dict()
3753-
3754-
expected['module_name'] = None
3743+
shallow_ec = EasyConfigParser(filename=test_ec).get_config_dict()
3744+
expected_shallow = expected.copy()
3745+
expected_shallow['module_name'] = None
37553746
for key in ('bitbucket_account', 'github_account', 'versionprefix'):
3756-
del expected[key]
3747+
del expected_shallow[key]
37573748

3758-
dep_names = [x[0] for x in ec['dependencies']]
3759-
self.assertFalse('CMake' in dep_names, "CMake should not be included in list of dependencies: %s" % dep_names)
3760-
res = template_constant_dict(ec)
3761-
dep_names = [x[0] for x in ec['dependencies']]
3762-
self.assertFalse('CMake' in dep_names, "CMake should not be included in list of dependencies: %s" % dep_names)
3749+
for name, ec, expected in (('Full', full_ec, expected_full), ('Shallow', shallow_ec, expected_shallow)):
3750+
with self.subTest(f'{name} easyconfig'):
3751+
# CMake should *not* be included, since it's a build-only dependency
3752+
dep_names = [x['name'] if isinstance(x, dict) else x[0] for x in ec['dependencies']]
3753+
self.assertNotIn('CMake', dep_names)
37633754

3764-
self.assertIn('arch', res)
3765-
arch = res.pop('arch')
3766-
self.assertTrue(arch_regex.match(arch), "'%s' matches with pattern '%s'" % (arch, arch_regex.pattern))
3755+
res = template_constant_dict(ec)
3756+
self.assertIn('arch', res)
3757+
arch = res.pop('arch')
3758+
self.assertRegex(arch, arch_regex)
37673759

3768-
self.assertEqual(res, expected)
3760+
self.assertNotIn('perlver', res, "Perl should be filtered out")
3761+
self.assertEqual(res, expected)
37693762

37703763
# also check result of template_constant_dict when dict representing extension is passed
37713764
ext_dict = {

0 commit comments

Comments
 (0)