diff options
-rw-r--r-- | lib/spack/spack/modules/common.py | 19 | ||||
-rw-r--r-- | lib/spack/spack/modules/lmod.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/modules/tcl.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/test/conftest.py | 10 |
4 files changed, 27 insertions, 16 deletions
diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py index 6cf44c4190..9ecee48810 100644 --- a/lib/spack/spack/modules/common.py +++ b/lib/spack/spack/modules/common.py @@ -49,14 +49,11 @@ import spack.error import spack.util.spack_yaml as syaml import spack.util.file_permissions as fp -#: config section for this file -configuration = spack.config.get('modules') -#: Root folders where the various module files should be written -roots = spack.config.get('config:module_roots', {}) +#: config section for this file +def configuration(): + return spack.config.get('modules', {}) -#: Inspections that needs to be done on spec prefixes -prefix_inspections = spack.config.get('modules:prefix_inspections', {}) #: Valid tokens for naming scheme and env variable names _valid_tokens = ( @@ -219,6 +216,8 @@ def root_path(name): Returns: root folder for module file installation """ + # Root folders where the various module files should be written + roots = spack.config.get('config:module_roots', {}) path = roots.get(name, os.path.join(spack.paths.share_path, name)) return spack.util.path.canonicalize_path(path) @@ -387,12 +386,12 @@ class BaseConfiguration(object): self.spec = spec # Dictionary of configuration options that should be applied # to the spec - self.conf = merge_config_rules(self.module.configuration, self.spec) + self.conf = merge_config_rules(self.module.configuration(), self.spec) @property def naming_scheme(self): """Naming scheme suitable for non-hierarchical layouts""" - scheme = self.module.configuration.get( + scheme = self.module.configuration().get( 'naming_scheme', '{name}-{version}-{compiler.name}-{compiler.version}' ) @@ -461,7 +460,7 @@ class BaseConfiguration(object): """ # A few variables for convenience of writing the method spec = self.spec - conf = self.module.configuration + conf = self.module.configuration() # Compute the list of whitelist rules that match wlrules = conf.get('whitelist', []) @@ -662,7 +661,7 @@ class BaseContext(tengine.Context): # Modifications guessed inspecting the spec prefix env = spack.util.environment.inspect_path( self.spec.prefix, - prefix_inspections, + spack.config.get('modules:prefix_inspections', {}), exclude=spack.util.environment.is_system_path ) diff --git a/lib/spack/spack/modules/lmod.py b/lib/spack/spack/modules/lmod.py index 814303a54f..a9ebb0bba9 100644 --- a/lib/spack/spack/modules/lmod.py +++ b/lib/spack/spack/modules/lmod.py @@ -18,8 +18,11 @@ import spack.tengine as tengine from .common import BaseConfiguration, BaseFileLayout from .common import BaseContext, BaseModuleFileWriter + #: lmod specific part of the configuration -configuration = spack.config.get('modules:lmod', {}) +def configuration(): + return spack.config.get('modules:lmod', {}) + #: Caches the configuration {spec_hash: configuration} configuration_registry = {} @@ -98,7 +101,7 @@ class LmodConfiguration(BaseConfiguration): specified in the configuration file or the sequence is empty """ - value = configuration.get( + value = configuration().get( 'core_compilers' ) or guess_core_compilers(store=True) @@ -112,7 +115,7 @@ class LmodConfiguration(BaseConfiguration): """Returns the list of tokens that are part of the modulefile hierarchy. 'compiler' is always present. """ - tokens = configuration.get('hierarchy', []) + tokens = configuration().get('hierarchy', []) # Check if all the tokens in the hierarchy are virtual specs. # If not warn the user and raise an error. diff --git a/lib/spack/spack/modules/tcl.py b/lib/spack/spack/modules/tcl.py index 96ecdc8293..ec8032a0e1 100644 --- a/lib/spack/spack/modules/tcl.py +++ b/lib/spack/spack/modules/tcl.py @@ -16,8 +16,11 @@ import spack.tengine as tengine from .common import BaseConfiguration, BaseFileLayout from .common import BaseContext, BaseModuleFileWriter + #: TCL specific part of the configuration -configuration = spack.config.get('modules:tcl', {}) +def configuration(): + return spack.config.get('modules:tcl', {}) + #: Caches the configuration {spec_hash: configuration} configuration_registry = {} diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index 156ad80fb5..572a38c225 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -654,15 +654,21 @@ def module_configuration(monkeypatch, request): with open(file) as f: configuration = yaml.load(f) + def mock_config_function(): + return configuration + + def writer_key_function(): + return mock_config_function()[writer_key] + monkeypatch.setattr( spack.modules.common, 'configuration', - configuration + mock_config_function ) monkeypatch.setattr( writer_mod, 'configuration', - configuration[writer_key] + writer_key_function ) monkeypatch.setattr( writer_mod, |