Skip to content

Commit

Permalink
Bundle: make implementation more efficient
Browse files Browse the repository at this point in the history
Instead of zipping bundles and configs every time, use a single instance list.
Also, do not check for the type when building the module requirements and
catch the exception instead.

Signed-off-by: Jan André Reuter <[email protected]>
  • Loading branch information
Thyre committed Nov 8, 2024
1 parent b13db46 commit 8247d63
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions easybuild/easyblocks/generic/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ def __init__(self, *args, **kwargs):
self.altroot = None
self.altversion = None

# list of EasyConfig instances for components
self.comp_cfgs = []

# list of EasyBlocks for components
self.comp_blocks = []
# list of EasyConfig instances and their EasyBlocks for components
self.comp_instances = []

# list of EasyConfig instances of components for which to run sanity checks
self.comp_cfgs_sanity_check = []
Expand Down Expand Up @@ -201,8 +198,7 @@ def __init__(self, *args, **kwargs):
if comp_cfg['patches']:
self.cfg.update('patches', comp_cfg['patches'])

self.comp_cfgs.append(comp_cfg)
self.comp_blocks.append(comp_cfg.easyblock(comp_cfg))
self.comp_instances.append((comp_cfg, comp_cfg.easyblock(comp_cfg)))

self.cfg.update('checksums', checksums_patches)

Expand All @@ -221,7 +217,7 @@ def check_checksums(self):
"""
checksum_issues = super(Bundle, self).check_checksums()

for comp in self.comp_cfgs:
for comp, _ in self.comp_instances:
checksum_issues.extend(self.check_checksums_for(comp, sub="of component %s" % comp['name']))

return checksum_issues
Expand Down Expand Up @@ -251,7 +247,7 @@ def build_step(self):
def install_step(self):
"""Install components, if specified."""
comp_cnt = len(self.cfg['components'])
for idx, (cfg, comp) in enumerate(zip(self.comp_cfgs, self.comp_blocks)):
for idx, (cfg, comp) in enumerate(self.comp_instances):

print_msg("installing bundle component %s v%s (%d/%d)..." %
(cfg['name'], cfg['version'], idx + 1, comp_cnt))
Expand Down Expand Up @@ -342,22 +338,20 @@ def make_module_req_guess(self):
# If not added here, they might be missing entirely and fail sanity checks.
final_reqs = super(Bundle, self).make_module_req_guess()

for cfg, comp in zip(self.comp_cfgs, self.comp_blocks):
for cfg, comp in self.comp_instances:
self.log.info("Gathering module paths for component %s v%s", cfg['name'], cfg['version'])
reqs = comp.make_module_req_guess()

if not reqs or not isinstance(reqs, dict):
self.log.warning("Expected requirements to be a dict but is not. Therefore, this component is skipped.")
continue

for key, value in sorted(reqs.items()):
if isinstance(reqs, string_type):
self.log.warning("Hoisting string value %s into a list before iterating over it", value)
value = [value]
if key not in final_reqs:
final_reqs[key] = value
else:
try:
for key, value in sorted(reqs.items()):
if isinstance(reqs, string_type):
self.log.warning("Hoisting string value %s into a list before iterating over it", value)
value = [value]

final_reqs.setdefault(key, [])
final_reqs[key] += value
except AttributeError:
self.log.warning("Expected requirements to be a dict but is not. Therefore, this component is skipped.")

return final_reqs

Expand Down

0 comments on commit 8247d63

Please sign in to comment.