summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-09-10 17:29:46 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-31 13:48:01 -0800
commit9cc013cc0fbff030be386ed3af5f6a826b97ca5f (patch)
treeb1e87f0fcc6f891b687ba75969929ee0aaf55f1d /lib
parent58cb4e5241dc5f1f707e4fbaad59759d4b982535 (diff)
downloadspack-9cc013cc0fbff030be386ed3af5f6a826b97ca5f.tar.gz
spack-9cc013cc0fbff030be386ed3af5f6a826b97ca5f.tar.bz2
spack-9cc013cc0fbff030be386ed3af5f6a826b97ca5f.tar.xz
spack-9cc013cc0fbff030be386ed3af5f6a826b97ca5f.zip
modules: make the module hook more robust
The module hook would previously fail if there were no enabled module types. - Instead of looking for a `KeyError`, default to empty list when the config variable is not present. - Convert lambdas to real functions for clarity.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/hooks/module_file_generation.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/spack/spack/hooks/module_file_generation.py b/lib/spack/spack/hooks/module_file_generation.py
index e448cbc550..ba30561d86 100644
--- a/lib/spack/spack/hooks/module_file_generation.py
+++ b/lib/spack/spack/hooks/module_file_generation.py
@@ -3,19 +3,19 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import spack.config
import spack.modules
import spack.modules.common
import llnl.util.tty as tty
-try:
- enabled = spack.config.get('modules:enable')
-except KeyError:
- tty.debug('NO MODULE WRITTEN: list of enabled module files is empty')
- enabled = []
-
def _for_each_enabled(spec, method_name):
"""Calls a method for each enabled module"""
+ enabled = spack.config.get('modules:enable')
+ if not enabled:
+ tty.debug('NO MODULE WRITTEN: list of enabled module files is empty')
+ return
+
for name in enabled:
generator = spack.modules.module_types[name](spec)
try:
@@ -26,5 +26,9 @@ def _for_each_enabled(spec, method_name):
tty.warn(msg.format(method_name, str(e)))
-post_install = lambda spec: _for_each_enabled(spec, 'write')
-post_uninstall = lambda spec: _for_each_enabled(spec, 'remove')
+def post_install(spec):
+ _for_each_enabled(spec, 'write')
+
+
+def post_uninstall(spec):
+ _for_each_enabled(spec, 'remove')