Skip to content

Commit

Permalink
Merge pull request #4720 from Flamefire/range-len-to-enumerate
Browse files Browse the repository at this point in the history
use `enumerate` where applicable fixing `_generate_multi_deps_list`
  • Loading branch information
boegel authored Jan 29, 2025
2 parents 8bad618 + 153de8c commit 3272aa0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
3 changes: 1 addition & 2 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,7 @@ def make_module_dep(self, unload_info=None):
multi_dep_mod_names = {}
for deplist in self.cfg.multi_deps:
for dep in deplist:
multi_dep_mod_names.setdefault(dep['name'], [])
multi_dep_mod_names[dep['name']].append(dep['short_mod_name'])
multi_dep_mod_names.setdefault(dep['name'], []).append(dep['short_mod_name'])

multi_dep_load_defaults = []
for _, depmods in sorted(multi_dep_mod_names.items()):
Expand Down
4 changes: 2 additions & 2 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,13 +1501,13 @@ def get_parsed_multi_deps(self):
# all multi_deps entries should be listed in builddependencies (if not, something is very wrong)
if isinstance(builddeps, list) and all(isinstance(x, list) for x in builddeps):

for iter_id in range(len(builddeps)):
for iter_id, current_builddeps in enumerate(builddeps):

# only build dependencies that correspond to multi_deps entries should be loaded as extra modules
# (other build dependencies should not be required to make sanity check pass for this iteration)
iter_deps = []
for key in self['multi_deps']:
hits = [d for d in builddeps[iter_id] if d['name'] == key]
hits = [d for d in current_builddeps if d['name'] == key]
if len(hits) == 1:
iter_deps.append(hits[0])
else:
Expand Down
19 changes: 6 additions & 13 deletions easybuild/tools/configobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,31 +876,24 @@ def walk(self, function, raise_errors=True,
"""
out = {}
# scalars first
for i in range(len(self.scalars)):
entry = self.scalars[i]
for i, entry in enumerate(self.scalars):
try:
val = function(self, entry, **keywargs)
# bound again in case name has changed
entry = self.scalars[i]
out[entry] = val
except Exception:
if raise_errors:
raise
else:
entry = self.scalars[i]
out[entry] = False
val = False
# bound again in case name has changed
entry = self.scalars[i]
out[entry] = val
# then sections
for i in range(len(self.sections)):
entry = self.sections[i]
for i, entry in enumerate(self.sections):
if call_on_sections:
try:
function(self, entry, **keywargs)
except Exception:
if raise_errors:
raise
else:
entry = self.sections[i]
out[entry] = False
# bound again in case name has changed
entry = self.sections[i]
# previous result is discarded
Expand Down
25 changes: 9 additions & 16 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
* Damian Alvarez (Forschungszentrum Juelich GmbH)
"""
import copy
import itertools
import os
import re
import tempfile
from collections import defaultdict
from contextlib import contextmanager
from easybuild.tools import LooseVersion
from textwrap import wrap

from easybuild.base import fancylogger
from easybuild.tools import LooseVersion
from easybuild.tools.build_log import EasyBuildError, print_warning
from easybuild.tools.config import build_option, get_module_syntax, install_path
from easybuild.tools.filetools import convert_name, mkdir, read_file, remove_file, resolve_path, symlink, write_file
Expand Down Expand Up @@ -680,21 +681,13 @@ def _generate_multi_deps_list(self):
"""
multi_deps = []
if self.app.cfg['multi_deps']:
for key in sorted(self.app.cfg['multi_deps'].keys()):
mod_list = []
txt = ''
vlist = self.app.cfg['multi_deps'].get(key)
for idx, version in enumerate(vlist):
for deplist in self.app.cfg.multi_deps:
for dep in deplist:
if dep['name'] == key and dep['version'] == version:
modname = dep['short_mod_name']
# indicate which version is loaded by default (unless that's disabled)
if idx == 0 and self.app.cfg['multi_deps_load_default']:
modname += ' (default)'
mod_list.append(modname)
txt += ', '.join(mod_list)
multi_deps.append(txt)
for name in sorted(self.app.cfg['multi_deps']):
mod_list = [dep['short_mod_name'] for dep in itertools.chain.from_iterable(self.app.cfg.multi_deps)
if dep['name'] == name]
# indicate that the first version is loaded by default if enabled
if self.app.cfg['multi_deps_load_default']:
mod_list[0] += ' (default)'
multi_deps.append(', '.join(mod_list))

return multi_deps

Expand Down

0 comments on commit 3272aa0

Please sign in to comment.