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.
This commit is contained in:
parent
58cb4e5241
commit
9cc013cc0f
@ -3,19 +3,19 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
|
||||||
|
import spack.config
|
||||||
import spack.modules
|
import spack.modules
|
||||||
import spack.modules.common
|
import spack.modules.common
|
||||||
import llnl.util.tty as tty
|
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):
|
def _for_each_enabled(spec, method_name):
|
||||||
"""Calls a method for each enabled module"""
|
"""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:
|
for name in enabled:
|
||||||
generator = spack.modules.module_types[name](spec)
|
generator = spack.modules.module_types[name](spec)
|
||||||
try:
|
try:
|
||||||
@ -26,5 +26,9 @@ def _for_each_enabled(spec, method_name):
|
|||||||
tty.warn(msg.format(method_name, str(e)))
|
tty.warn(msg.format(method_name, str(e)))
|
||||||
|
|
||||||
|
|
||||||
post_install = lambda spec: _for_each_enabled(spec, 'write')
|
def post_install(spec):
|
||||||
post_uninstall = lambda spec: _for_each_enabled(spec, 'remove')
|
_for_each_enabled(spec, 'write')
|
||||||
|
|
||||||
|
|
||||||
|
def post_uninstall(spec):
|
||||||
|
_for_each_enabled(spec, 'remove')
|
||||||
|
Loading…
Reference in New Issue
Block a user