Skip to content

Commit 85d3f18

Browse files
MicketC3SE "c3-builder" bot
authored and
C3SE "c3-builder" bot
committed
Move conversion of paths as str to lists earlier removing duplicated code
1 parent 557f693 commit 85d3f18

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

easybuild/tools/module_generator.py

+9-20
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,10 @@ def _filter_paths(self, key, paths):
213213
return paths
214214

215215
added_paths = self.added_paths_per_key.setdefault(key, set())
216-
# paths can be a string
217-
if isinstance(paths, str):
218-
if paths in added_paths:
219-
filtered_paths = None
220-
else:
221-
added_paths.add(paths)
222-
filtered_paths = paths
223-
else:
224-
# Coerce any iterable/generator into a list
225-
if not isinstance(paths, list):
226-
paths = list(paths)
227-
filtered_paths = [x for x in paths if x not in added_paths and not added_paths.add(x)]
216+
# Coerce any iterable/generator into a list
217+
if not isinstance(paths, list):
218+
paths = list(paths)
219+
filtered_paths = [x for x in paths if x not in added_paths and not added_paths.add(x)]
228220
if filtered_paths != paths:
229221
removed_paths = paths if filtered_paths is None else [x for x in paths if x not in filtered_paths]
230222
print_warning("Suppressed adding the following path(s) to $%s of the module as they were already added: %s",
@@ -265,9 +257,14 @@ def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpath
265257
:param allow_abs: allow providing of absolute paths
266258
:param expand_relpaths: expand relative paths into absolute paths (by prefixing install dir)
267259
"""
260+
if isinstance(paths, str):
261+
self.log.debug("Wrapping %s into a list before using it for %s", paths, key)
262+
paths = [paths]
263+
268264
paths = self._filter_paths(key, paths)
269265
if paths is None:
270266
return ''
267+
271268
if key == 'PYTHONPATH':
272269
python_paths = [path for path in paths if re.match(r'lib/python\d+\.\d+/site-packages', path)]
273270
if len(python_paths) > 1:
@@ -997,10 +994,6 @@ def _update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpat
997994
self.log.info("Not including statement to %s environment variable $%s, as specified", update_type, key)
998995
return ''
999996

1000-
if isinstance(paths, str):
1001-
self.log.debug("Wrapping %s into a list before using it to %s path %s", paths, update_type, key)
1002-
paths = [paths]
1003-
1004997
abspaths = []
1005998
for path in paths:
1006999
if os.path.isabs(path) and not allow_abs:
@@ -1468,10 +1461,6 @@ def _update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpat
14681461
self.log.info("Not including statement to %s environment variable $%s, as specified", update_type, key)
14691462
return ''
14701463

1471-
if isinstance(paths, str):
1472-
self.log.debug("Wrapping %s into a list before using it to %s path %s", update_type, paths, key)
1473-
paths = [paths]
1474-
14751464
abspaths = []
14761465
for path in paths:
14771466
if os.path.isabs(path):

0 commit comments

Comments
 (0)