Disable module generation during bootstrapping

This commit is contained in:
Massimiliano Culpo 2021-09-06 17:29:40 +02:00 committed by Todd Gamblin
parent c309adb4b3
commit 4033cc0250
5 changed files with 41 additions and 7 deletions

View File

@ -25,6 +25,7 @@
import spack.config
import spack.environment
import spack.main
import spack.modules
import spack.paths
import spack.repo
import spack.spec
@ -430,8 +431,9 @@ def ensure_bootstrap_configuration():
# and builtin but accounting for platform specific scopes
config_scopes = _bootstrap_config_scopes()
with spack.config.use_configuration(*config_scopes):
with spack_python_interpreter():
yield
with spack.modules.disable_modules():
with spack_python_interpreter():
yield
def store_path():

View File

@ -750,10 +750,11 @@ def override(path_or_scope, value=None):
config.push_scope(overrides)
config.set(path_or_scope, value, scope=scope_name)
yield config
scope = config.remove_scope(overrides.name)
assert scope is overrides
try:
yield config
finally:
scope = config.remove_scope(overrides.name)
assert scope is overrides
#: configuration scopes added on the command line

View File

@ -9,12 +9,14 @@
from __future__ import absolute_import
from .common import disable_modules
from .lmod import LmodModulefileWriter
from .tcl import TclModulefileWriter
__all__ = [
'TclModulefileWriter',
'LmodModulefileWriter'
'LmodModulefileWriter',
'disable_modules'
]
module_types = {

View File

@ -29,6 +29,7 @@
module type.
"""
import collections
import contextlib
import copy
import datetime
import inspect
@ -41,6 +42,7 @@
from llnl.util.lang import dedupe
import spack.build_environment as build_environment
import spack.config
import spack.environment as ev
import spack.error
import spack.paths
@ -905,6 +907,19 @@ def remove(self):
pass
@contextlib.contextmanager
def disable_modules():
"""Disable the generation of modulefiles within the context manager."""
data = {
'modules:': {
'enable': []
}
}
disable_scope = spack.config.InternalConfigScope('disable_modules', data=data)
with spack.config.override(disable_scope):
yield
class ModulesError(spack.error.SpackError):
"""Base error for modules."""

View File

@ -64,3 +64,17 @@ def test_bootstrap_deactivates_environments(active_mock_environment):
with spack.bootstrap.ensure_bootstrap_configuration():
assert spack.environment.active_environment() is None
assert spack.environment.active_environment() == active_mock_environment
@pytest.mark.regression('25805')
def test_bootstrap_disables_modulefile_generation(mutable_config):
# Be sure to enable both lmod and tcl in modules.yaml
spack.config.set('modules:enable', ['tcl', 'lmod'])
assert 'tcl' in spack.config.get('modules:enable')
assert 'lmod' in spack.config.get('modules:enable')
with spack.bootstrap.ensure_bootstrap_configuration():
assert 'tcl' not in spack.config.get('modules:enable')
assert 'lmod' not in spack.config.get('modules:enable')
assert 'tcl' in spack.config.get('modules:enable')
assert 'lmod' in spack.config.get('modules:enable')