Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2c65cee
Add a architecture env variable to the user subdir module path.
akesandgren Oct 21, 2017
0a6e4fe
Use {RUNTIME_ENV::SOME_ENV_VAR} instead of subdir_arch_env.
akesandgren Feb 7, 2018
07e6b3f
Simplify the code for handling {RUNTIME_ENV::SOME_ENV_VAR} in user_mo…
akesandgren Feb 7, 2018
18b4de3
Merge branch 'develop' into add-module-load-time-env-var-to-user-modu…
akesandgren Jul 3, 2018
7b92aaf
Change tabs to spaces.
akesandgren Jul 3, 2018
4d2369b
Increase indentation for visual indent as per houndci-bot.
akesandgren Jul 3, 2018
e95c965
Adjust test for Lua modpath extension to match new code in module_gen…
akesandgren Jul 3, 2018
fb88ba5
Adjust line length as per houndci-bot.
akesandgren Jul 3, 2018
a17c9e0
Increase indentation more since houndci is still complaining.
akesandgren Jul 3, 2018
04a1620
Clumsily got tabs into the code, changed to spaces.
akesandgren Jul 3, 2018
6f6789c
Forgot the extra pathJoin (in the test regex) that the module generat…
akesandgren Jul 4, 2018
b6e491b
Missing \ protection for ( causing misbalanced ()
akesandgren Jul 4, 2018
bece493
Add Tcl support for {RUNTIME_ENV::SOME_ENV_VAR} in subdir-user-modules.
akesandgren Jul 4, 2018
f38846a
Fix "'" position typo.
akesandgren Jul 4, 2018
9b8fd37
Update test for Tcl style of the "{RUNTIME_ENV::SOME_ENV_VAR} in subd…
akesandgren Jul 4, 2018
3fdb798
Fix long line and increase indentation again since houndci is complai…
akesandgren Jul 4, 2018
4c5579f
One more too long line, and increase indentation alot this time.
akesandgren Jul 4, 2018
a7202dc
minor cleanup in test_make_module_extend_modpath
boegel Jul 5, 2018
018508b
flesh out duplicate code in implementation of use methods in module_g…
boegel Jul 5, 2018
98f4498
add test for test_det_user_modpath method
boegel Jul 5, 2018
73c5180
use $::env rather than to access environment variables in Tcl syntax
boegel Jul 5, 2018
71d0100
Merge pull request #8 from boegel/add-module-load-time-env-var-to-use…
akesandgren Jul 5, 2018
81a59a5
Tcl and Lua differs in argument separator for their respective
akesandgren Jul 5, 2018
ece102f
Use self.SYNTAX to determine string to use in join of expanded_user_m…
akesandgren Jul 6, 2018
674b52f
Fix incorrect Tcl syntax in expected strings from det_user_modpath.
akesandgren Jul 6, 2018
1d205c5
Fix tabs to spaces
akesandgren Jul 6, 2018
7c147c5
flesh out common part of det_user_modpath into _det_user_modpath_comm…
boegel Jul 6, 2018
3a7c641
Merge pull request #9 from boegel/add-module-load-time-env-var-to-use…
akesandgren Jul 6, 2018
4dc5f56
fix check for $env(HOME) in test_make_module_extend_modpath, should b…
boegel Jul 6, 2018
af293a8
Merge pull request #10 from boegel/add-module-load-time-env-var-to-us…
akesandgren Jul 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,10 @@ def make_module_extend_modpath(self):
if user_modpath:
# If a mod_path_suffix is being used, we should respect it
mod_path_suffix = build_option('suffix_modules_path')
user_modpath = os.path.join(user_modpath, mod_path_suffix)
user_modpath_exts = ActiveMNS().det_user_modpath_extensions(self.cfg)
user_modpath_exts = [os.path.join(user_modpath, e) for e in user_modpath_exts]
self.log.debug("Including user module path extensions returned by naming scheme: %s", user_modpath_exts)
txt += self.module_generator.use(user_modpath_exts, prefix=self.module_generator.getenv_cmd('HOME'),
guarded=True)
guarded=True, user_modpath=user_modpath, mod_path_suffix=mod_path_suffix)
else:
self.log.debug("Not including module path extensions, as specified.")
return txt
Expand Down
36 changes: 33 additions & 3 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ def update_paths(self, key, paths, prepend=True, allow_abs=False, expand_relpath
"""
raise NotImplementedError

def use(self, paths, prefix=None, guarded=False):
def use(self, paths, prefix=None, guarded=False, user_modpath=None, mod_path_suffix=None):
"""
Generate module use statements for given list of module paths.
:param paths: list of module path extensions to generate use statements for; paths will be quoted
:param prefix: optional path prefix; not quoted, i.e., can be a statement
:param guarded: use statements will be guarded to only apply if path exists
:param user_modpath: optional user subdir
:param mod_path_suffix: optional path suffix
"""
raise NotImplementedError

Expand Down Expand Up @@ -643,12 +645,14 @@ def unload_module(self, mod_name):
"""
return '\n'.join(['', "module unload %s" % mod_name])

def use(self, paths, prefix=None, guarded=False):
def use(self, paths, prefix=None, guarded=False, user_modpath=None, mod_path_suffix=None):
"""
Generate module use statements for given list of module paths.
:param paths: list of module path extensions to generate use statements for; paths will be quoted
:param prefix: optional path prefix; not quoted, i.e., can be a statement
:param guarded: use statements will be guarded to only apply if path exists
:param user_modpath: optional user subdir
:param mod_path_suffix: optional path suffix
"""
use_statements = []
for path in paths:
Expand Down Expand Up @@ -954,20 +958,46 @@ def unload_module(self, mod_name):
"""
return '\n'.join(['', 'unload("%s")' % mod_name])

def use(self, paths, prefix=None, guarded=False):
def use(self, paths, prefix=None, guarded=False, user_modpath=None, mod_path_suffix=None):
"""
Generate module use statements for given list of module paths.
:param paths: list of module path extensions to generate use statements for; paths will be quoted
:param prefix: optional path prefix; not quoted, i.e., can be a statement
:param guarded: use statements will be guarded to only apply if path exists
:param user_modpath: optional user subdir path
:param mod_path_suffix: optional path suffix, only used with user_modpath
"""
use_statements = []
if user_modpath:
# Check for occurenses of {RUNTIME_ENV::SOME_ENV_VAR}
# SOME_ENV_VAR will be expanded at module load time.
runtime_env_re = re.compile(r'{RUNTIME_ENV::(\w+)}')
sub_paths = []
expanded_user_modpath = []
for sub_path in re.split(os.path.sep, user_modpath):
matched_re = runtime_env_re.match(sub_path)
if matched_re:
if sub_paths:
path = quote_str(os.path.join(*sub_paths))
expanded_user_modpath.extend([path])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation contains mixed spaces and tabs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation contains mixed spaces and tabs

sub_paths = []
expanded_user_modpath.extend(['os.getenv(%s)' % quote_str(matched_re.group(1))])
else:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation contains mixed spaces and tabs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation contains mixed spaces and tabs

sub_paths.append(sub_path)
if sub_paths:
expanded_user_modpath.extend([quote_str(os.path.join(*sub_paths))])
if mod_path_suffix:
expanded_user_modpath.extend([quote_str(mod_path_suffix)])
user_modpath = ', '.join(expanded_user_modpath)
for path in paths:
quoted_path = quote_str(path)
if user_modpath:
quoted_path = 'pathJoin(%s, %s)' % (user_modpath, quoted_path)
if prefix:
full_path = 'pathJoin(%s, %s)' % (prefix, quoted_path)
else:
full_path = quoted_path

prepend_modulepath = self.UPDATE_PATH_TEMPLATE % ('prepend', 'MODULEPATH', full_path)
if guarded:
cond_statement = self.conditional_statement('isDir(%s)' % full_path, prepend_modulepath)
Expand Down
4 changes: 2 additions & 2 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ def test_make_module_extend_modpath(self):
home = r'os.getenv\("HOME"\)'
regexs.extend([
# extension for user modules is guarded
r'if isDir\(pathJoin\(%s, "%s/funky/Compiler/pi/3.14"\)\) then' % (home, usermodsdir),
r'if isDir\(pathJoin\(%s, "%s", "funky", "Compiler/pi/3.14"\)\) then' % (home, usermodsdir),
# no per-moduleclass extension for user modules
r'\s+prepend_path\("MODULEPATH", pathJoin\(%s, "%s/funky/Compiler/pi/3.14"\)\)' % (home, usermodsdir),
r'\s+prepend_path\("MODULEPATH", pathJoin\(%s, "%s", "funky", "Compiler/pi/3.14"\)\)' % (home, usermodsdir),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (124 > 120 characters)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (124 > 120 characters)

])
else:
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
Expand Down