Skip to content

Commit 6817c03

Browse files
committed
allow extensions to add text to the module file
Introduce `make_extension_module_extra` which gets called during module file creation for every extension similar to `make_module_extra`. This ensures it will also be called for parallel extension or --module-only builds. Fixes easybuilders#4647
1 parent f31790e commit 6817c03

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

easybuild/framework/easyblock.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,21 +1546,30 @@ def make_module_extra_extensions(self):
15461546
Sets optional variables for extensions.
15471547
"""
15481548
# add stuff specific to individual extensions
1549-
lines = [self.module_extra_extensions]
1549+
txt = self.module_extra_extensions
1550+
1551+
if not self.ext_instances:
1552+
self.prepare_for_extensions()
1553+
self.init_ext_instances()
1554+
1555+
for ext in self.ext_instances:
1556+
ext_txt = ext.make_extension_module_extra()
1557+
if ext_txt:
1558+
txt += ext_txt
15501559

15511560
# set environment variable that specifies list of extensions
15521561
# We need only name and version, so don't resolve templates
15531562
exts_list = self.make_extension_string(ext_sep=',', sort=False)
15541563
env_var_name = 'EBEXTSLIST' + convert_name(self.name, upper=True)
1555-
lines.append(self.module_generator.set_environment(env_var_name, exts_list))
1564+
txt += self.module_generator.set_environment(env_var_name, exts_list)
15561565

1557-
return ''.join(lines)
1566+
return txt
15581567

15591568
def make_module_footer(self):
15601569
"""
15611570
Insert a footer section in the module file, primarily meant for contextual information
15621571
"""
1563-
footer = [self.module_generator.comment("Built with EasyBuild version %s" % VERBOSE_VERSION).rstrip('\n')]
1572+
footer = []
15641573

15651574
# add extra stuff for extensions (if any)
15661575
if self.cfg.get_ref('exts_list'):
@@ -1587,6 +1596,7 @@ def make_module_footer(self):
15871596
self.log.warning("Not including footer in Lua syntax in non-Lua module file: %s",
15881597
self.cfg['modluafooter'])
15891598

1599+
footer.append(self.module_generator.comment("Built with EasyBuild version %s" % VERBOSE_VERSION))
15901600
return '\n'.join(footer)
15911601

15921602
def make_module_extend_modpath(self):

easybuild/framework/extension.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def toolchain(self):
287287
"""
288288
return self.master.toolchain
289289

290+
def make_extension_module_extra(self):
291+
"""Similar to make_module_extra but only called for extensions"""
292+
return ''
293+
290294
def sanity_check_step(self):
291295
"""
292296
Sanity check to run after installing extension

easybuild/framework/extensioneasyblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,6 @@ def make_module_extra(self, *args, **kwargs):
226226
self.log.deprecated("Passing the parameter 'extra' to make_module_extra should be "
227227
"replaced by concatenating the result", '6.0')
228228
txt = super().make_module_extra(*args, **kwargs)
229-
if extra is not None:
229+
if extra:
230230
txt += extra
231231
return txt

test/framework/easyconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ def test_exts_list(self):
482482
homepage = "http://example.com"
483483
description = "test easyconfig"
484484
toolchain = SYSTEM
485+
exts_defaultclass = "DummyExtension"
485486
exts_default_options = {
486487
"source_tmpl": "gzip-1.4.eb", # dummy source template to avoid download fail
487488
"source_urls": ["http://example.com/%(name)s/%(version)s"]

test/framework/sandbox/easybuild/easyblocks/generic/toy_extension.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ def post_install_extension(self):
103103

104104
EB_toy.install_step(self.master, name=self.name)
105105

106+
def make_extension_module_extra(self):
107+
"""Extra stuff for toy extensions"""
108+
txt = super(Toy_Extension, self).make_extension_module_extra()
109+
value = self.name
110+
if self.version:
111+
value += '-' + self.version
112+
txt += self.module_generator.set_environment('TOY_EXT_VAR', value)
113+
return txt
114+
106115
def sanity_check_step(self, *args, **kwargs):
107116
"""Custom sanity check for toy extensions."""
108117
self.log.info("Loaded modules: %s", self.modules_tool.list())

test/framework/toy_build.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,8 @@ def test_toy_advanced(self):
12161216
# set by ToyExtension easyblock used to install extensions
12171217
'^setenv.*TOY_EXT_BAR.*bar',
12181218
'^setenv.*TOY_EXT_BARBAR.*barbar',
1219+
'^setenv.*TOY_EXT_VAR.*bar',
1220+
'^setenv.*TOY_EXT_VAR.*barbar',
12191221
]
12201222
for pattern in patterns:
12211223
self.assertTrue(re.search(pattern, toy_mod_txt, re.M), "Pattern '%s' found in: %s" % (pattern, toy_mod_txt))
@@ -1663,8 +1665,8 @@ def test_toy_module_fulltxt(self):
16631665
] + modloadmsg_lua + [
16641666
r'end',
16651667
r'setenv\("TOY", "toy-0.0"\)',
1666-
r'-- Built with EasyBuild version .*',
16671668
r'io.stderr:write\("oh hai\!"\)',
1669+
r'-- Built with EasyBuild version .*',
16681670
])
16691671
elif get_module_syntax() == 'Tcl':
16701672
mod_txt_regex_pattern = '\n'.join([
@@ -1705,8 +1707,8 @@ def test_toy_module_fulltxt(self):
17051707
] + modloadmsg_tcl + [
17061708
r'}',
17071709
r'setenv TOY "toy-0.0"',
1708-
r'# Built with EasyBuild version .*',
17091710
r'puts stderr "oh hai\!"',
1711+
r'# Built with EasyBuild version .*',
17101712
])
17111713
else:
17121714
self.fail("Unknown module syntax: %s" % get_module_syntax())
@@ -1951,6 +1953,8 @@ def test_module_only_extensions(self):
19511953
with self.mocked_stdout_stderr():
19521954
self.eb_main([test_ec, '--module-only'], do_build=True, raise_error=True)
19531955
self.assertExists(toy_mod)
1956+
# Extra stuff from extension(s) is included
1957+
self.assertRegex(read_file(toy_mod), 'TOY_EXT_VAR.*barbar-0.0')
19541958
remove_file(toy_mod)
19551959

19561960
# rename file required for barbar extension, so we can check whether sanity check catches it
@@ -2008,6 +2012,13 @@ def test_toy_exts_parallel(self):
20082012
stdout, stderr = self.run_test_toy_build_with_output(ec_file=test_ec, extra_args=args, raise_error=True)
20092013
self.assertEqual(stderr, '')
20102014

2015+
# Extra stuff from extension(s) should be included
2016+
ext_var_patterns = [
2017+
'TOY_EXT_VAR.*ls',
2018+
'TOY_EXT_VAR.*bar-0.0',
2019+
'TOY_EXT_VAR.*barbar-0.0',
2020+
]
2021+
20112022
# take into account that each of these lines may appear multiple times,
20122023
# in case no progress was made between checks
20132024
patterns = [
@@ -2022,6 +2033,10 @@ def test_toy_exts_parallel(self):
20222033
error_msg = "Expected pattern '%s' should be found in %s'" % (regex.pattern, stdout)
20232034
self.assertRegex(stdout, regex)
20242035

2036+
module_contents = read_file(toy_mod)
2037+
for pattern in ext_var_patterns:
2038+
self.assertRegex(module_contents, pattern)
2039+
20252040
# also test skipping of extensions in parallel
20262041
args.append('--skip')
20272042
stdout, stderr = self.run_test_toy_build_with_output(ec_file=test_ec, extra_args=args, raise_error=True)
@@ -2040,6 +2055,10 @@ def test_toy_exts_parallel(self):
20402055
error_msg = "Expected pattern '%s' should be found in %s'" % (regex.pattern, stdout)
20412056
self.assertTrue(regex.search(stdout), error_msg)
20422057

2058+
module_contents = read_file(toy_mod)
2059+
for pattern in ext_var_patterns:
2060+
self.assertRegex(module_contents, pattern)
2061+
20432062
# check behaviour when using Toy_Extension easyblock that doesn't implement required_deps method;
20442063
# framework should fall back to installing extensions sequentially
20452064
toy_ext_eb = os.path.join(topdir, 'sandbox', 'easybuild', 'easyblocks', 'generic', 'toy_extension.py')
@@ -2067,6 +2086,10 @@ def test_toy_exts_parallel(self):
20672086
error_msg = "Expected pattern '%s' should be found in %s'" % (regex.pattern, stdout)
20682087
self.assertTrue(regex.search(stdout), error_msg)
20692088

2089+
module_contents = read_file(toy_mod)
2090+
for pattern in ext_var_patterns:
2091+
self.assertRegex(module_contents, pattern)
2092+
20702093
def test_backup_modules(self):
20712094
"""Test use of backing up of modules with --module-only."""
20722095

0 commit comments

Comments
 (0)