Skip to content

Commit e6530dc

Browse files
Micketlexming
andauthored
Use exceptions to check which type is used
Co-authored-by: Alex Domingo <[email protected]>
1 parent ee628d9 commit e6530dc

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

easybuild/framework/easyblock.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,30 +1469,27 @@ def make_module_extra(self, altroot=None, altversion=None):
14691469
for (key, value) in self.cfg['modextravars'].items():
14701470
lines.append(self.module_generator.set_environment(key, value))
14711471

1472-
for name, prepend in [('modextrapaths', True), ('modextrapaths_append', False)]:
1472+
for extrapaths_type, prepend in [('modextrapaths', True), ('modextrapaths_append', False)]:
14731473
allow_abs = self.cfg['allow_prepend_abs_path'] if prepend else self.cfg['allow_append_abs_path']
14741474

1475-
for (key, value) in self.cfg[name].items():
1475+
for (key, value) in self.cfg[extrapaths_type].items():
14761476
if not isinstance(value, (tuple, list, dict, str)):
1477-
raise EasyBuildError(f'{name} dict value "{value}" (type {type(value)}) is not a '
1478-
'list, dict or str')
1479-
elif isinstance(value, dict):
1480-
if 'paths' not in value or 'delimiter' not in value:
1481-
raise EasyBuildError(f'{name} dict value "{value}" must contain "paths" and "delimiter"')
1477+
raise EasyBuildError(
1478+
f"{extrapaths_type} dict value '{value}' (type {type(value)}) is not a 'list, dict or str'"
1479+
)
14821480

1481+
try:
14831482
paths = value['paths']
14841483
delim = value['delimiter']
1485-
if not isinstance(paths, (list, str)):
1486-
raise EasyBuildError('modextrapaths dict value "{value}" paths must be list or str')
1487-
if not isinstance(delim, str):
1488-
raise EasyBuildError('modextrapaths dict value "{value}" delimiter must be a str')
1489-
lines.append(self.module_generator.update_paths(key, paths, prepend=prepend, delim=delim,
1490-
allow_abs=allow_abs))
1491-
else:
1492-
if isinstance(value, str):
1493-
value = [value]
1494-
lines.append(self.module_generator.update_paths(key, value, prepend=prepend, allow_abs=allow_abs))
1495-
1484+
except KeyError:
1485+
raise EasyBuildError(f'{extrapaths_type} dict "{value}" lacks "paths" or "delimiter" items')
1486+
except TypeError:
1487+
paths = value
1488+
delim = ':'
1489+
1490+
lines.append(
1491+
self.module_generator.update_paths(key, paths, prepend=prepend, delim=delim, allow_abs=allow_abs)
1492+
)
14961493
# add lines to update $PYTHONPATH or $EBPYTHONPREFIXES
14971494
lines.extend(self.make_module_pythonpath())
14981495

0 commit comments

Comments
 (0)