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
					George Hartzell
				
			
				
					committed by
					
						 Todd Gamblin
						Todd Gamblin
					
				
			
			
				
	
			
			
			 Todd Gamblin
						Todd Gamblin
					
				
			
						parent
						
							b28d8345ec
						
					
				
				
					commit
					c456dfb60f
				
			| @@ -438,13 +438,20 @@ def header(self): | ||||
|     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 @@ def remove(self): | ||||
|                 # 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') | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user