summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hartzell <hartzell@alerce.com>2017-02-03 15:53:30 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2017-02-03 15:53:30 -0800
commitc456dfb60fdcd24448140278f29f0e9d1de95800 (patch)
treec6c7a3ebf6626301033bca4e54af7b83a5e6ceac
parentb28d8345ec1fbc07493f42cb784a2bd28c7ddde8 (diff)
downloadspack-c456dfb60fdcd24448140278f29f0e9d1de95800.tar.gz
spack-c456dfb60fdcd24448140278f29f0e9d1de95800.tar.bz2
spack-c456dfb60fdcd24448140278f29f0e9d1de95800.tar.xz
spack-c456dfb60fdcd24448140278f29f0e9d1de95800.zip
Make module autoload warnings configurable (#2763)
Modules generated by the module creation machinery currently print out a notice that warnts the user that things are being autoloaded. In some situations those warnings are problematic. See #2754 for discussion. This is a first cut at optionally disabling the warning messages: - adds a helper tothe EnvModule base class that encapsulates the config file variable; - adds a method to the base class that provides a default (empty) code fragment for generating a warning message; - passes the warning fragment into the bit that formats the autoload string; - adds specialized autload_warner() methods in the tcl and lmod subclasses;; and finally - touches up the autoload_format strings in the specialized classes.
-rw-r--r--lib/spack/spack/modules.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py
index ba220291a0..885f2197ef 100644
--- a/lib/spack/spack/modules.py
+++ b/lib/spack/spack/modules.py
@@ -438,13 +438,20 @@ class EnvModule(object):
def module_specific_content(self, configuration):
return tuple()
+ # Subclasses can return a fragment of module code that prints out
+ # a warning that modules are being autoloaded.
+ def autoload_warner(self):
+ return ''
+
def autoload(self, spec):
if not isinstance(spec, str):
m = type(self)(spec)
module_file = m.use_name
else:
module_file = spec
- return self.autoload_format.format(module_file=module_file)
+ return self.autoload_format.format(
+ module_file=module_file,
+ warner=self.autoload_warner().format(module_file=module_file))
def prerequisite(self, spec):
m = type(self)(spec)
@@ -486,6 +493,10 @@ class EnvModule(object):
# removedirs throws OSError on first non-empty directory found
pass
+ def verbose_autoload(self):
+ configuration = _module_config.get(self.name, {})
+ return configuration.get('verbose_autoload', True)
+
class Dotkit(EnvModule):
name = 'dotkit'
@@ -537,8 +548,13 @@ class TclModule(EnvModule):
path = canonicalize_path(
_roots.get(name, join_path(spack.share_path, 'modules')))
+ def autoload_warner(self):
+ if self.verbose_autoload():
+ return 'puts stderr "Autoloading {module_file}"\n'
+ return ''
+
autoload_format = ('if ![ is-loaded {module_file} ] {{\n'
- ' puts stderr "Autoloading {module_file}"\n'
+ ' {warner}'
' module load {module_file}\n'
'}}\n\n')
@@ -665,8 +681,13 @@ class LmodModule(EnvModule):
UnsetEnv: 'unsetenv("{name}")\n'
}
+ def autoload_warner(self):
+ if self.verbose_autoload():
+ return 'LmodMessage("Autoloading {module_file}")\n'
+ return ''
+
autoload_format = ('if not isloaded("{module_file}") then\n'
- ' LmodMessage("Autoloading {module_file}")\n'
+ ' {warner}'
' load("{module_file}")\n'
'end\n\n')