Skip to content

Commit 067a42f

Browse files
committed
Merge pull request #1595 from boegel/pyver_template
add support for %(pyver)s and %(pyshortver)s templates
2 parents 849bc83 + d2fcdef commit 067a42f

File tree

2 files changed

+62
-17
lines changed

2 files changed

+62
-17
lines changed

easybuild/framework/easyconfig/templates.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242

4343
# derived from easyconfig, but not from ._config directly
4444
TEMPLATE_NAMES_EASYCONFIG = [
45+
('nameletter', "First letter of software name"),
4546
('toolchain_name', "Toolchain name"),
4647
('toolchain_version', "Toolchain version"),
4748
('version_major_minor', "Major.Minor version"),
4849
('version_major', "Major version"),
4950
('version_minor', "Minor version"),
50-
('nameletter', "First letter of software name"),
5151
]
5252
# derived from EasyConfig._config
5353
TEMPLATE_NAMES_CONFIG = [
@@ -67,6 +67,13 @@
6767
('installdir', "Installation directory"),
6868
('builddir', "Build directory"),
6969
]
70+
# software names for which to define <pref>ver and <pref>shortver templates
71+
TEMPLATE_SOFTWARE_VERSIONS = [
72+
# software name, prefix for *ver and *shortver
73+
('Perl', 'perl'),
74+
('Python', 'py'),
75+
('R', 'r'),
76+
]
7077
# constant templates that can be used in easyconfigs
7178
TEMPLATE_CONSTANTS = [
7279
# source url constants
@@ -144,6 +151,11 @@ def template_constant_dict(config, ignore=None, skip_lower=True):
144151
for name in TEMPLATE_NAMES_EASYCONFIG:
145152
if name in ignore:
146153
continue
154+
155+
# check if this template name is already handled
156+
if template_values.get(name[0]) is not None:
157+
continue
158+
147159
if name[0].startswith('toolchain_'):
148160
tc = config.get('toolchain')[0]
149161
if tc is not None:
@@ -170,6 +182,7 @@ def template_constant_dict(config, ignore=None, skip_lower=True):
170182
pass
171183
# only go through this once
172184
ignore.extend(['version_major', 'version_minor', 'version_major_minor'])
185+
173186
elif name[0].endswith('letter'):
174187
# parse first letters
175188
if name[0].startswith('name'):
@@ -179,15 +192,23 @@ def template_constant_dict(config, ignore=None, skip_lower=True):
179192
else:
180193
raise EasyBuildError("Undefined name %s from TEMPLATE_NAMES_EASYCONFIG", name)
181194

182-
# step 2: add remaining from config
195+
# step 2: define *ver and *shortver templates
196+
for name, pref in TEMPLATE_SOFTWARE_VERSIONS:
197+
for dep in config['dependencies'][0]:
198+
if isinstance(dep['name'], basestring) and dep['name'].lower() == name.lower():
199+
template_values['%sver' % pref] = dep['version']
200+
template_values['%sshortver' % pref] = '.'.join(dep['version'].split('.')[:2])
201+
break
202+
203+
# step 3: add remaining from config
183204
for name in TEMPLATE_NAMES_CONFIG:
184205
if name in ignore:
185206
continue
186207
if name in config:
187208
template_values[name] = config[name][0]
188209
_log.debug('name: %s, config: %s', name, config[name][0])
189210

190-
# step 3. make lower variants if not skip_lower
211+
# step 4. make lower variants if not skip_lower
191212
if not skip_lower:
192213
for name in TEMPLATE_NAMES_LOWER:
193214
if name in ignore:
@@ -237,23 +258,29 @@ def template_documentation():
237258
# step 1: add TEMPLATE_NAMES_EASYCONFIG
238259
doc.append('Template names/values derived from easyconfig instance')
239260
for name in TEMPLATE_NAMES_EASYCONFIG:
240-
doc.append("%s%s: %s" % (indent_l1, name[0], name[1]))
261+
doc.append("%s%%(%s)s: %s" % (indent_l1, name[0], name[1]))
262+
263+
# step 2: add *ver/*shortver templates for software listed in TEMPLATE_SOFTWARE_VERSIONS
264+
doc.append("Template names/values for (short) software versions")
265+
for name, pref in TEMPLATE_SOFTWARE_VERSIONS:
266+
doc.append("%s%%(%sshortver)s: short version for %s (<major>.<minor>)" % (indent_l1, pref, name))
267+
doc.append("%s%%(%sver)s: full version for %s" % (indent_l1, pref, name))
241268

242-
# step 2: add remaining self._config
269+
# step 3: add remaining self._config
243270
doc.append('Template names/values as set in easyconfig')
244271
for name in TEMPLATE_NAMES_CONFIG:
245-
doc.append("%s%s" % (indent_l1, name))
272+
doc.append("%s%%(%s)s" % (indent_l1, name))
246273

247-
# step 3. make lower variants
274+
# step 4. make lower variants
248275
doc.append('Lowercase values of template values')
249276
for name in TEMPLATE_NAMES_LOWER:
250-
doc.append("%s%s: lower case of value of %s" % (indent_l1, TEMPLATE_NAMES_LOWER_TEMPLATE % {'name': name}, name))
277+
doc.append("%s%%(%s)s: lower case of value of %s" % (indent_l1, TEMPLATE_NAMES_LOWER_TEMPLATE % {'name': name}, name))
251278

252-
# step 4. self.template_values can/should be updated from outside easyconfig
279+
# step 5. self.template_values can/should be updated from outside easyconfig
253280
# (eg the run_setp code in EasyBlock)
254281
doc.append('Template values set outside EasyBlock runstep')
255282
for name in TEMPLATE_NAMES_EASYBLOCK_RUN_STEP:
256-
doc.append("%s%s: %s" % (indent_l1, name[0], name[1]))
283+
doc.append("%s%%(%s)s: %s" % (indent_l1, name[0], name[1]))
257284

258285
doc.append('Template constants that can be used in easyconfigs')
259286
for cst in TEMPLATE_CONSTANTS:

test/framework/easyconfig.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -740,12 +740,26 @@ def test_templating(self):
740740
'easyblock = "ConfigureMake"',
741741
'name = "%(name)s"',
742742
'version = "%(version)s"',
743+
'versionsuffix = "-Python-%%(pyver)s"',
743744
'homepage = "http://example.com/%%(nameletter)s/%%(nameletterlower)s"',
744745
'description = "test easyconfig %%(name)s"',
745746
'toolchain = {"name":"dummy", "version": "dummy2"}',
746747
'source_urls = [(GOOGLECODE_SOURCE)]',
747748
'sources = [SOURCE_TAR_GZ, (SOURCELOWER_TAR_GZ, "%(cmd)s")]',
748-
'sanity_check_paths = {"files": [], "dirs": ["libfoo.%%s" %% SHLIB_EXT]}',
749+
'sanity_check_paths = {',
750+
' "files": ["lib/python%%(pyshortver)s/site-packages"],',
751+
' "dirs": ["libfoo.%%s" %% SHLIB_EXT],',
752+
'}',
753+
'dependencies = [',
754+
' ("Perl", "5.22.0"),'
755+
' ("Python", "2.7.10"),'
756+
' ("R", "3.2.3"),'
757+
']',
758+
'modloadmsg = "%s"' % '; '.join([
759+
'Python: %%(pyver)s, %%(pyshortver)s',
760+
'Perl: %%(perlver)s, %%(perlshortver)s',
761+
'R: %%(rver)s, %%(rshortver)s',
762+
]),
749763
]) % inp
750764
self.prep()
751765
eb = EasyConfig(self.eb_file, validate=False)
@@ -758,8 +772,11 @@ def test_templating(self):
758772
self.assertEqual(eb['sources'][1][0], const_dict['SOURCELOWER_TAR_GZ'] % inp)
759773
self.assertEqual(eb['sources'][1][1], 'tar xfvz %s')
760774
self.assertEqual(eb['source_urls'][0], const_dict['GOOGLECODE_SOURCE'] % inp)
775+
self.assertEqual(eb['versionsuffix'], '-Python-2.7.10')
776+
self.assertEqual(eb['sanity_check_paths']['files'][0], 'lib/python2.7/site-packages')
761777
self.assertEqual(eb['sanity_check_paths']['dirs'][0], 'libfoo.%s' % get_shared_lib_ext())
762778
self.assertEqual(eb['homepage'], "http://example.com/P/p")
779+
self.assertEqual(eb['modloadmsg'], "Python: 2.7.10, 2.7; Perl: 5.22.0, 5.22; R: 3.2.3, 3.2")
763780

764781
# test the escaping insanity here (ie all the crap we allow in easyconfigs)
765782
eb['description'] = "test easyconfig % %% %s% %%% %(name)s %%(name)s %%%(name)s %%%%(name)s"
@@ -770,12 +787,13 @@ def test_templating_doc(self):
770787
doc = easyconfig.templates.template_documentation()
771788
# expected length: 1 per constant and 1 extra per constantgroup
772789
temps = [
773-
easyconfig.templates.TEMPLATE_NAMES_EASYCONFIG,
774-
easyconfig.templates.TEMPLATE_NAMES_CONFIG,
775-
easyconfig.templates.TEMPLATE_NAMES_LOWER,
776-
easyconfig.templates.TEMPLATE_NAMES_EASYBLOCK_RUN_STEP,
777-
easyconfig.templates.TEMPLATE_CONSTANTS,
778-
]
790+
easyconfig.templates.TEMPLATE_NAMES_EASYCONFIG,
791+
easyconfig.templates.TEMPLATE_SOFTWARE_VERSIONS * 2,
792+
easyconfig.templates.TEMPLATE_NAMES_CONFIG,
793+
easyconfig.templates.TEMPLATE_NAMES_LOWER,
794+
easyconfig.templates.TEMPLATE_NAMES_EASYBLOCK_RUN_STEP,
795+
easyconfig.templates.TEMPLATE_CONSTANTS,
796+
]
779797
self.assertEqual(len(doc.split('\n')), sum([len(temps)] + [len(x) for x in temps]))
780798

781799
def test_constant_doc(self):

0 commit comments

Comments
 (0)