config: remove all module-scope calls to spack.config.get()

This avoids parsing modules.yaml on startup.
This commit is contained in:
Todd Gamblin 2019-12-27 23:37:09 -08:00
parent 9cc013cc0f
commit 3017584c48
4 changed files with 27 additions and 16 deletions

View File

@ -49,14 +49,11 @@
import spack.util.spack_yaml as syaml import spack.util.spack_yaml as syaml
import spack.util.file_permissions as fp import spack.util.file_permissions as fp
#: config section for this file #: config section for this file
configuration = spack.config.get('modules') def configuration():
return spack.config.get('modules', {})
#: Root folders where the various module files should be written
roots = spack.config.get('config:module_roots', {})
#: 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 for naming scheme and env variable names
_valid_tokens = ( _valid_tokens = (
@ -219,6 +216,8 @@ def root_path(name):
Returns: Returns:
root folder for module file installation 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)) path = roots.get(name, os.path.join(spack.paths.share_path, name))
return spack.util.path.canonicalize_path(path) return spack.util.path.canonicalize_path(path)
@ -387,12 +386,12 @@ def __init__(self, spec):
self.spec = spec self.spec = spec
# Dictionary of configuration options that should be applied # Dictionary of configuration options that should be applied
# to the spec # to the spec
self.conf = merge_config_rules(self.module.configuration, self.spec) self.conf = merge_config_rules(self.module.configuration(), self.spec)
@property @property
def naming_scheme(self): def naming_scheme(self):
"""Naming scheme suitable for non-hierarchical layouts""" """Naming scheme suitable for non-hierarchical layouts"""
scheme = self.module.configuration.get( scheme = self.module.configuration().get(
'naming_scheme', 'naming_scheme',
'{name}-{version}-{compiler.name}-{compiler.version}' '{name}-{version}-{compiler.name}-{compiler.version}'
) )
@ -461,7 +460,7 @@ def blacklisted(self):
""" """
# A few variables for convenience of writing the method # A few variables for convenience of writing the method
spec = self.spec spec = self.spec
conf = self.module.configuration conf = self.module.configuration()
# Compute the list of whitelist rules that match # Compute the list of whitelist rules that match
wlrules = conf.get('whitelist', []) wlrules = conf.get('whitelist', [])
@ -662,7 +661,7 @@ def environment_modifications(self):
# Modifications guessed inspecting the spec prefix # Modifications guessed inspecting the spec prefix
env = spack.util.environment.inspect_path( env = spack.util.environment.inspect_path(
self.spec.prefix, self.spec.prefix,
prefix_inspections, spack.config.get('modules:prefix_inspections', {}),
exclude=spack.util.environment.is_system_path exclude=spack.util.environment.is_system_path
) )

View File

@ -18,8 +18,11 @@
from .common import BaseConfiguration, BaseFileLayout from .common import BaseConfiguration, BaseFileLayout
from .common import BaseContext, BaseModuleFileWriter from .common import BaseContext, BaseModuleFileWriter
#: lmod specific part of the configuration #: 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} #: Caches the configuration {spec_hash: configuration}
configuration_registry = {} configuration_registry = {}
@ -98,7 +101,7 @@ def core_compilers(self):
specified in the configuration file or the sequence specified in the configuration file or the sequence
is empty is empty
""" """
value = configuration.get( value = configuration().get(
'core_compilers' 'core_compilers'
) or guess_core_compilers(store=True) ) or guess_core_compilers(store=True)
@ -112,7 +115,7 @@ def hierarchy_tokens(self):
"""Returns the list of tokens that are part of the modulefile """Returns the list of tokens that are part of the modulefile
hierarchy. 'compiler' is always present. hierarchy. 'compiler' is always present.
""" """
tokens = configuration.get('hierarchy', []) tokens = configuration().get('hierarchy', [])
# Check if all the tokens in the hierarchy are virtual specs. # Check if all the tokens in the hierarchy are virtual specs.
# If not warn the user and raise an error. # If not warn the user and raise an error.

View File

@ -16,8 +16,11 @@
from .common import BaseConfiguration, BaseFileLayout from .common import BaseConfiguration, BaseFileLayout
from .common import BaseContext, BaseModuleFileWriter from .common import BaseContext, BaseModuleFileWriter
#: TCL specific part of the configuration #: 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} #: Caches the configuration {spec_hash: configuration}
configuration_registry = {} configuration_registry = {}

View File

@ -654,15 +654,21 @@ def _impl(filename):
with open(file) as f: with open(file) as f:
configuration = yaml.load(f) configuration = yaml.load(f)
def mock_config_function():
return configuration
def writer_key_function():
return mock_config_function()[writer_key]
monkeypatch.setattr( monkeypatch.setattr(
spack.modules.common, spack.modules.common,
'configuration', 'configuration',
configuration mock_config_function
) )
monkeypatch.setattr( monkeypatch.setattr(
writer_mod, writer_mod,
'configuration', 'configuration',
configuration[writer_key] writer_key_function
) )
monkeypatch.setattr( monkeypatch.setattr(
writer_mod, writer_mod,