-
Notifications
You must be signed in to change notification settings - Fork 220
Add module load time env var to user module path #2395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2c65cee
0a6e4fe
07e6b3f
18b4de3
7b92aaf
4d2369b
e95c965
fb88ba5
a17c9e0
04a1620
6f6789c
b6e491b
bece493
f38846a
9b8fd37
3fdb798
4c5579f
a7202dc
018508b
98f4498
73c5180
71d0100
81a59a5
ece102f
674b52f
1d205c5
7c147c5
3a7c641
4dc5f56
af293a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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: | ||
|
|
@@ -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]) | ||
|
||
| sub_paths = [] | ||
|
||
| expanded_user_modpath.extend(['os.getenv(%s)' % quote_str(matched_re.group(1))]) | ||
|
||
| else: | ||
|
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent