Skip to content

Commit dfd3553

Browse files
authored
Merge pull request #5028 from Flamefire/patch-version-template
Add templates for patch versions
2 parents 8385f40 + 8731fdc commit dfd3553

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

easybuild/framework/easyconfig/templates.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
'nameletter': 'First letter of software name',
5151
'toolchain_name': 'Toolchain name',
5252
'toolchain_version': 'Toolchain version',
53+
'version_major_minor_patch': "Major.Minor.Patch version",
5354
'version_major_minor': "Major.Minor version",
5455
'version_major': 'Major version',
56+
'version_minor_patch': 'Minor.Patch version',
5557
'version_minor': 'Minor version',
58+
'version_patch': 'Patch version',
5659
}
5760
# derived from EasyConfig._config
5861
TEMPLATE_NAMES_CONFIG = [
@@ -204,9 +207,12 @@
204207
'r_short_ver': 'rshortver',
205208
'r_ver': 'rver',
206209
'toolchain_ver': 'toolchain_version',
210+
'ver_maj_min_patch': 'version_major_minor_patch',
207211
'ver_maj_min': 'version_major_minor',
208212
'ver_maj': 'version_major',
213+
'ver_min_patch': 'version_minor_patch',
209214
'ver_min': 'version_minor',
215+
'ver_patch': 'version_patch',
210216
'version_prefix': 'versionprefix',
211217
'version_suffix': 'versionsuffix',
212218
}
@@ -343,11 +349,16 @@ def template_constant_dict(config, ignore=None, toolchain=None):
343349
minor = version[1]
344350
template_values['version_minor'] = minor
345351
template_values['version_major_minor'] = '.'.join([major, minor])
352+
if len(version) > 2:
353+
patch = version[2]
354+
template_values['version_patch'] = patch
355+
template_values['version_minor_patch'] = '.'.join([minor, patch])
356+
template_values['version_major_minor_patch'] = '.'.join([major, minor, patch])
346357
except IndexError:
347358
# if there is no minor version, skip it
348359
pass
349360
# only go through this once
350-
ignore.extend(['version_major', 'version_minor', 'version_major_minor'])
361+
ignore.extend(name for name in TEMPLATE_NAMES_EASYCONFIG if name.startswith('version_'))
351362

352363
elif name.endswith('letter'):
353364
# parse first letters

test/framework/easyconfig.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,16 @@ def test_extensions_templates(self):
566566
# bogus, but useful to check whether this get resolved
567567
'exts_default_options = {"source_urls": [PYPI_SOURCE]}',
568568
'exts_list = [',
569-
' ("toy", "0.0", {',
569+
' ("toy", "0.0.1", {',
570570
# %(name)s and %(version_major_minor)s should be resolved using name/version of extension (not parent)
571571
# %(pymajver)s should get resolved because Python is listed as a (runtime) dep
572572
# %(versionsuffix)s should get resolved with value of parent
573573
' "source_tmpl": "%(name)s-%(version_major_minor)s-py%(pymajver)s%(versionsuffix)s.tar.gz",',
574-
' "patches": ["%(name)s-%(version)s_fix-silly-typo-in-printf-statement.patch"],',
574+
' "patches": ["%(name)s-%(version_major_minor)s_fix-silly-typo-in-printf-statement.patch"],',
575575
# use hacky prebuildopts that is picked up by 'EB_Toy' easyblock, to check whether templates are resolved
576-
' "prebuildopts": "gcc -O2 %(name)s.c -o toy-%(version)s &&' +
577-
' mv toy-%(version)s toy # echo installdir is %(installdir)s #",',
576+
' "prebuildopts": "gcc -O2 %(name)s.c -o toy-%(version_minor_patch)s &&' +
577+
' mv toy-%(version_minor_patch)s toy # echo installdir is %(installdir)s #",',
578+
' "postbuildopts": "echo postbuild step for %(name)s-%(version)s",',
578579
' }),',
579580
']',
580581
])
@@ -597,16 +598,15 @@ def test_extensions_templates(self):
597598
# check whether template values were resolved correctly in Extension instances that were created/used
598599
toy_ext = eb.ext_instances[0]
599600
self.assertEqual(os.path.basename(toy_ext.src), 'toy-0.0-py3-test.tar.gz')
600-
patches = []
601-
for patch in toy_ext.patches:
602-
patches.append(patch['path'])
601+
patches = [patch['path'] for patch in toy_ext.patches]
603602
self.assertEqual(patches, [os.path.join(self.test_prefix, toy_patch_fn)])
604603
# define actual installation dir
605604
pi_installdir = os.path.join(self.test_installpath, 'software', 'pi', '3.14-test')
606-
expected_prebuildopts = 'gcc -O2 toy.c -o toy-0.0 && mv toy-0.0 toy # echo installdir is %s #' % pi_installdir
605+
expected_prebuildopts = 'gcc -O2 toy.c -o toy-0.1 && mv toy-0.1 toy # echo installdir is %s #' % pi_installdir
607606
expected = {
608607
'patches': ['toy-0.0_fix-silly-typo-in-printf-statement.patch'],
609608
'prebuildopts': expected_prebuildopts,
609+
'postbuildopts': "echo postbuild step for toy-0.0.1",
610610
'source_tmpl': 'toy-0.0-py3-test.tar.gz',
611611
'source_urls': ['https://pypi.python.org/packages/source/t/toy'],
612612
}
@@ -3723,7 +3723,7 @@ def test_template_constant_dict(self):
37233723
# also check result of template_constant_dict when dict representing extension is passed
37243724
ext_dict = {
37253725
'name': 'foo',
3726-
'version': '1.2.3',
3726+
'version': '1.2.3.42',
37273727
'options': {
37283728
'source_urls': ['https://example.com'],
37293729
'source_tmpl': '%(name)s-%(version)s.tar.gz',
@@ -3744,13 +3744,27 @@ def test_template_constant_dict(self):
37443744
'rpath_enabled': rpath,
37453745
'software_commit': '',
37463746
'sysroot': '',
3747-
'version': '1.2.3',
3747+
'version': '1.2.3.42',
37483748
'version_major': '1',
37493749
'version_major_minor': '1.2',
3750-
'version_minor': '2'
3750+
'version_major_minor_patch': '1.2.3',
3751+
'version_minor': '2',
3752+
'version_minor_patch': '2.3',
3753+
'version_patch': '3',
37513754
}
37523755
self.assertEqual(res, expected)
37533756

3757+
# No patch version makes the templates undefined
3758+
ext_dict['version'] = '1.2'
3759+
res = template_constant_dict(ext_dict)
3760+
res.pop('arch')
3761+
3762+
del expected['version_major_minor_patch']
3763+
del expected['version_minor_patch']
3764+
del expected['version_patch']
3765+
expected['version'] = '1.2'
3766+
self.assertEqual(res, expected)
3767+
37543768
def test_parse_deps_templates(self):
37553769
"""Test whether handling of templates defined by dependencies is done correctly."""
37563770
test_ecs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')

0 commit comments

Comments
 (0)