From c456dfb60fdcd24448140278f29f0e9d1de95800 Mon Sep 17 00:00:00 2001 From: George Hartzell Date: Fri, 3 Feb 2017 15:53:30 -0800 Subject: 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. --- lib/spack/spack/modules.py | 27 ++++++++++++++++++++++++--- 1 file 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') -- cgit v1.2.3-60-g2f50