Skip to content

Commit

Permalink
Make new safe module abstraction for update_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Micket committed Apr 3, 2024
1 parent 5dac63e commit 4e57013
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,23 @@ def append_paths(self, key, paths, allow_abs=False, expand_relpaths=True):
:param allow_abs: allow providing of absolute paths
:param expand_relpaths: expand relative paths into absolute paths (by prefixing install dir)
"""
paths = self._filter_paths(key, paths)
if paths is None:
return ''
return self.update_paths(key, paths, prepend=False, allow_abs=allow_abs, expand_relpaths=expand_relpaths)
return self._update_paths(key, paths, prepend=False, allow_abs=allow_abs, expand_relpaths=expand_relpaths)

def prepend_paths(self, key, paths, allow_abs=False, expand_relpaths=True):
"""
Generate prepend-path statements for the given list of paths.
:param key: environment variable to append paths to
:param paths: list of paths to append
:param allow_abs: allow providing of absolute paths
:param expand_relpaths: expand relative paths into absolute paths (by prefixing install dir)
"""
return self._update_paths(key, paths, prepend=True, allow_abs=allow_abs, expand_relpaths=expand_relpaths)

def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
"""
Generate append/prepend-path statements for the given list of paths.
:param key: environment variable to append paths to
:param paths: list of paths to append
:param allow_abs: allow providing of absolute paths
Expand All @@ -260,7 +268,7 @@ def prepend_paths(self, key, paths, allow_abs=False, expand_relpaths=True):
paths = self._filter_paths(key, paths)
if paths is None:
return ''
return self.update_paths(key, paths, prepend=True, allow_abs=allow_abs, expand_relpaths=expand_relpaths)
return self._update_paths(key, paths, prepend, allow_abs, expand_relpaths)

def _modulerc_check_module_version(self, module_version):
"""
Expand Down Expand Up @@ -551,7 +559,7 @@ def unload_module(self, mod_name):
"""
raise NotImplementedError

def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
def _update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
"""
Generate prepend-path or append-path statements for the given list of paths.
Expand Down Expand Up @@ -955,7 +963,7 @@ def msg_on_unload(self, msg):
print_cmd = "puts stderr %s" % quote_str(msg, tcl=True)
return '\n'.join(['', self.conditional_statement("module-info mode unload", print_cmd, indent=False)])

def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
def _update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
"""
Generate prepend-path or append-path statements for the given list of paths.
Expand All @@ -981,7 +989,7 @@ def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpath
abspaths = []
for path in paths:
if os.path.isabs(path) and not allow_abs:
raise EasyBuildError("Absolute path %s passed to update_paths which only expects relative paths.",
raise EasyBuildError("Absolute path %s passed to _update_paths which only expects relative paths.",
path)
elif not os.path.isabs(path):
# prepend/append $root (= installdir) for (non-empty) relative paths
Expand Down Expand Up @@ -1426,7 +1434,7 @@ def modulerc(self, module_version=None, filepath=None, modulerc_txt=None):
return super(ModuleGeneratorLua, self).modulerc(module_version=module_version, filepath=filepath,
modulerc_txt=modulerc_txt)

def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
def _update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpaths=True):
"""
Generate prepend_path or append_path statements for the given list of paths
Expand Down Expand Up @@ -1455,7 +1463,7 @@ def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpath
if allow_abs:
abspaths.append(quote_str(path))
else:
raise EasyBuildError("Absolute path %s passed to update_paths which only expects relative paths.",
raise EasyBuildError("Absolute path %s passed to _update_paths which only expects relative paths.",
path)
else:
# use pathJoin for (non-empty) relative paths
Expand Down

0 comments on commit 4e57013

Please sign in to comment.