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.
This commit is contained in:
George Hartzell 2017-02-03 15:53:30 -08:00 committed by Todd Gamblin
parent b28d8345ec
commit c456dfb60f

View file

@ -438,13 +438,20 @@ def header(self):
def module_specific_content(self, configuration): def module_specific_content(self, configuration):
return tuple() 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): def autoload(self, spec):
if not isinstance(spec, str): if not isinstance(spec, str):
m = type(self)(spec) m = type(self)(spec)
module_file = m.use_name module_file = m.use_name
else: else:
module_file = spec 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): def prerequisite(self, spec):
m = type(self)(spec) m = type(self)(spec)
@ -486,6 +493,10 @@ def remove(self):
# removedirs throws OSError on first non-empty directory found # removedirs throws OSError on first non-empty directory found
pass pass
def verbose_autoload(self):
configuration = _module_config.get(self.name, {})
return configuration.get('verbose_autoload', True)
class Dotkit(EnvModule): class Dotkit(EnvModule):
name = 'dotkit' name = 'dotkit'
@ -537,8 +548,13 @@ class TclModule(EnvModule):
path = canonicalize_path( path = canonicalize_path(
_roots.get(name, join_path(spack.share_path, 'modules'))) _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' autoload_format = ('if ![ is-loaded {module_file} ] {{\n'
' puts stderr "Autoloading {module_file}"\n' ' {warner}'
' module load {module_file}\n' ' module load {module_file}\n'
'}}\n\n') '}}\n\n')
@ -665,8 +681,13 @@ class LmodModule(EnvModule):
UnsetEnv: 'unsetenv("{name}")\n' 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' autoload_format = ('if not isloaded("{module_file}") then\n'
' LmodMessage("Autoloading {module_file}")\n' ' {warner}'
' load("{module_file}")\n' ' load("{module_file}")\n'
'end\n\n') 'end\n\n')