Skip to content

Commit

Permalink
honor specified easyblock for extensions (fixes easybuilders#3710)
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Jul 3, 2021
1 parent c32f8d9 commit da400e2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
20 changes: 16 additions & 4 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ def fetch_extension_sources(self, skip_checksums=False):
'options': ext_options,
}

# if a particular easyblock is specified, make sure it's used
# (this is picked up by init_ext_instances)
ext_src['easyblock'] = ext_options.get('easyblock', None)

# construct dictionary with template values;
# inherited from parent, except for name/version templates which are specific to this extension
template_values = copy.deepcopy(self.cfg.template_values)
Expand Down Expand Up @@ -2295,15 +2299,23 @@ def init_ext_instances(self):
ext_name = ext['name']
self.log.debug("Creating class instance for extension %s...", ext_name)

# if a specific easyblock is specified for this extension, honor it;
# just passing this to get_easyblock_class is sufficient
easyblock = ext.get('easyblock', None)
if easyblock:
class_name = easyblock
mod_path = get_module_path(class_name)
else:
class_name = encode_class_name(ext_name)
mod_path = get_module_path(class_name, generic=False)

cls, inst = None, None
class_name = encode_class_name(ext_name)
mod_path = get_module_path(class_name, generic=False)

# try instantiating extension-specific class
# try instantiating extension-specific class, or honor specified easyblock
try:
# no error when importing class fails, in case we run into an existing easyblock
# with a similar name (e.g., Perl Extension 'GO' vs 'Go' for which 'EB_Go' is available)
cls = get_easyblock_class(None, name=ext_name, error_on_failed_import=False,
cls = get_easyblock_class(easyblock, name=ext_name, error_on_failed_import=False,
error_on_missing_easyblock=False)
self.log.debug("Obtained class %s for extension %s", cls, ext_name)
if cls is not None:
Expand Down
19 changes: 19 additions & 0 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,25 @@ def test_extensions_step(self):
eb.close_log()
os.remove(eb.logfile)

def test_init_extensions(self):
"""Test creating extension instances."""

testdir = os.path.abspath(os.path.dirname(__file__))
toy_ec_file = os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0-gompi-2018a-test.eb')
ec = process_easyconfig(toy_ec_file)[0]
eb = get_easyblock_instance(ec)

eb.prepare_for_extensions()
eb.init_ext_instances()
ext_inst_class_names = [x.__class__.__name__ for x in eb.ext_instances]
expected = [
'Toy_Extension', # 'ls' extension
'Toy_Extension', # 'bar' extension
'DummyExtension', # 'barbar' extension
'EB_toy', # 'toy' extension
]
self.assertEqual(ext_inst_class_names, expected)

def test_skip_extensions_step(self):
"""Test the skip_extensions_step"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exts_list = [
'keepsymlinks': True,
}),
('barbar', '0.0', {
'easyblock': 'DummyExtension',
'start_dir': 'src',
}),
(name, version, {
Expand Down

0 comments on commit da400e2

Please sign in to comment.