spack.modules package¶
This package contains code for creating environment modules, which can include Tcl or Lua modules, and others.
- class spack.modules.LmodModulefileWriter(conf: BaseConfiguration)[source]¶
Bases:
BaseModuleFileWriterWriter class for lmod module files.
- configuration_class¶
alias of
LmodConfiguration
- class spack.modules.TclModulefileWriter(conf: BaseConfiguration)[source]¶
Bases:
BaseModuleFileWriterWriter class for tcl module files.
- configuration_class¶
alias of
TclConfiguration
- spack.modules.disable_modules() Iterator[None][source]¶
Disable the generation of modulefiles within the context manager.
Submodules¶
spack.modules.common module¶
This module contains the logic for generating environment module files for each installed spec.
The logic is split across four classes:
BaseConfiguration: queries themodules.yamlconfiguration for a given spec.FileLayout: derives the on-disk path and the use name of a module file.ModuleContext: builds the Jinja2 template context dictionary.BaseModuleFileWriter: uses the three classes above to write, update, and remove module files.
To add a new module type, subclass BaseConfiguration and BaseModuleFileWriter.
- class spack.modules.common.BaseConfiguration(spec: Spec, module_set_name: str, explicit: bool)[source]¶
Bases:
objectReads the
modulessection of the configuration for a given spec and exposes it as a set of properties used byFileLayout,ModuleContext, andBaseModuleFileWriter.- property available: Dict[str, Spec]¶
Returns a dictionary of the services that are currently available.
- property core_compilers: List[Spec]¶
Returns the list of “Core” compilers
- Raises:
CoreCompilersNotFoundError – if the key was not specified in the configuration file or the sequence is empty
- property env: EnvironmentModifications¶
List of environment modifications that should be done in the module.
- property filter_hierarchy_specs: Dict[str, List[str]]¶
Returns the dict of specs with modified hierarchies
Returns True if the module has been hidden, False otherwise.
- property hierarchy_tokens: List[str]¶
Returns the list of tokens that are part of the modulefile hierarchy.
compileris always present.
- classmethod make_configuration(spec: Spec, module_set_name: str, explicit: bool | None = None) BaseConfiguration[source]¶
Returns the cached configuration object for spec.
- classmethod make_layout(spec: Spec, module_set_name: str, explicit: bool | None = None) FileLayout[source]¶
- property provides: Dict[str, Spec]¶
Returns a dictionary mapping all the services provided by this spec to the spec itself.
Returns an empty dictionary if hierarchical mode is disabled.
- property requires: Dict[str, Spec]¶
Returns a dictionary mapping all the requirements of this spec to the actual provider.
The
compilerkey is always present among the requirements.Returns an empty dictionary if hierarchical mode is disabled.
- class spack.modules.common.BaseModuleFileWriter(conf: BaseConfiguration)[source]¶
Bases:
object- configuration_class: ClassVar[Type[BaseConfiguration]]¶
- classmethod from_spec(spec: Spec, module_set_name: str, explicit: bool | None = None) BaseModuleFileWriter[source]¶
Update modulerc file corresponding to module to add or remove command that hides module depending on its hidden state.
- Parameters:
remove (bool) – if True, hiddenness information for module is removed from modulerc.
- class spack.modules.common.FileLayout(configuration)[source]¶
Bases:
objectProvides information on the layout of module files.
- property available_path_parts: List[str]¶
List of path parts that are currently available. Needed to construct the file name.
- token_to_path(name: str, value: Spec) str[source]¶
Transforms a hierarchy token into the corresponding path part.
- property unlocked_paths: Dict[Tuple[str, ...] | None, List[Tuple[str, ...]]]¶
Returns a dictionary mapping conditions to a list of unlocked paths.
The paths that are unconditionally unlocked are under the key ‘None’. The other keys represent the list of services you need loaded to unlock the corresponding paths.
- class spack.modules.common.ModuleContext(configuration, layout: FileLayout)[source]¶
Bases:
ContextProvides the context dictionary used by the template engine to render a module file.
- property conditionally_unlocked_paths: List[Tuple[str, str]]¶
Returns the list of paths that are unlocked conditionally. Each item in the list is a tuple with the structure (condition, path).
- property environment_modifications: List[Tuple[str, NameModifier | NameValueModifier]]¶
List of environment modifications to be processed.
- property has_conditional_modifications: bool¶
True if this module modifies MODULEPATH conditionally to the presence of other services in the environment, False otherwise.
- property has_modulepath_modifications: bool¶
True if this module modifies MODULEPATH, False otherwise.
- modification_needs_formatting(modification: NameModifier | NameValueModifier) bool[source]¶
Returns True if environment modification entry needs to be formatted.
- class spack.modules.common.ModuleIndexEntry(path, use_name)[source]¶
Bases:
NamedTuple
- class spack.modules.common.UpstreamModuleIndex(local_db, module_indices)[source]¶
Bases:
objectThis is responsible for taking the individual module indices of all upstream Spack installations and locating the module for a given spec based on which upstream install it is located in.
- spack.modules.common.dependencies(spec: Spec, request: str = 'all') List[Spec][source]¶
Returns the list of dependencies for a given spec.
- Parameters:
spec – spec to be analyzed
request – one of
"none","run","direct","all"
- spack.modules.common.disable_modules() Iterator[None][source]¶
Disable the generation of modulefiles within the context manager.
- spack.modules.common.generate_module_index(root: str, modules: List[BaseModuleFileWriter], overwrite: bool = False) None[source]¶
- spack.modules.common.merge_config_rules(configuration: dict, spec: Spec) dict[source]¶
Parses the module specific part of a configuration and returns a dictionary containing the actions to be performed on the spec passed as an argument.
- Parameters:
configuration – module specific configuration (e.g. entries under the top-level ‘tcl’ key)
spec – spec for which we need to generate a module file
spack.modules.error module¶
Errors and exceptions for the modules package.
- exception spack.modules.error.CoreCompilersNotFoundError(message: str, long_message: str | None = None)[source]¶
Bases:
SpackError,KeyErrorRaised if
core_compilershas not been specified in the configuration file.
- exception spack.modules.error.DefaultTemplateNotDefined[source]¶
Bases:
AttributeError,ModulesErrorRaised if
default_templatehas not been specified in the derived class.
- exception spack.modules.error.HideCmdFormatNotDefined[source]¶
Bases:
AttributeError,ModulesErrorRaised if
hide_cmd_formathas not been specified in the derived class.
- exception spack.modules.error.ModuleNotFoundError(message: str, long_message: str | None = None)[source]¶
Bases:
ModulesErrorRaised when a module cannot be found for a spec
- exception spack.modules.error.ModulercHeaderNotDefined[source]¶
Bases:
AttributeError,ModulesErrorRaised if
modulerc_headerhas not been specified in the derived class.
- exception spack.modules.error.ModulesError(message: str, long_message: str | None = None)[source]¶
Bases:
SpackErrorBase error for modules.
- exception spack.modules.error.ModulesTemplateNotFoundError(message: str, long_message: str | None = None)[source]¶
Bases:
ModulesError,RuntimeErrorRaised if the template for a module file was not found.
spack.modules.lmod module¶
- class spack.modules.lmod.LmodConfiguration(spec: Spec, module_set_name: str, explicit: bool)[source]¶
Bases:
BaseConfigurationConfiguration class for lmod module files.
- class spack.modules.lmod.LmodModulefileWriter(conf: BaseConfiguration)[source]¶
Bases:
BaseModuleFileWriterWriter class for lmod module files.
- configuration_class¶
alias of
LmodConfiguration
spack.modules.tcl module¶
This module implements the classes necessary to generate Tcl modules.
- class spack.modules.tcl.TclConfiguration(spec: Spec, module_set_name: str, explicit: bool)[source]¶
Bases:
BaseConfigurationConfiguration class for tcl module files.
- class spack.modules.tcl.TclModulefileWriter(conf: BaseConfiguration)[source]¶
Bases:
BaseModuleFileWriterWriter class for tcl module files.
- configuration_class¶
alias of
TclConfiguration