spack.modules package

Submodules

spack.modules.common module

Here we consolidate the logic for creating an abstract description of the information that module systems need.

This information maps a single spec to:

  • a unique module filename
  • the module file content

and is divided among four classes:

  • a configuration class that provides a convenient interface to query details about the configuration for the spec under consideration.
  • a layout class that provides the information associated with module file names and directories
  • a context class that provides the dictionary used by the template engine to generate the module file
  • a writer that collects and uses the information above to either write or remove the module file

Each of the four classes needs to be sub-classed when implementing a new module type.

class spack.modules.common.BaseConfiguration(spec)

Bases: object

Manipulates the information needed to generate a module file to make querying easier. It needs to be sub-classed for specific module types.

blacklisted

Returns True if the module has been blacklisted, False otherwise.

context
env

List of environment modifications that should be done in the module.

environment_blacklist

List of variables that should be left unmodified.

hash

Hash tag for the module or None

literals_to_load

List of literal modules to be loaded.

naming_scheme

Naming scheme suitable for non-hierarchical layouts

specs_to_load

List of specs that should be loaded in the module file.

specs_to_prereq

List of specs that should be prerequisite of the module file.

suffixes

List of suffixes that should be appended to the module file name.

template

Returns the name of the template to use for the module file or None if not specified in the configuration.

verbose

Returns True if the module file needs to be verbose, False otherwise

class spack.modules.common.BaseContext(configuration)

Bases: spack.tengine.Context

Provides the base context needed for template rendering.

This class needs to be sub-classed for specific module types. The following attributes need to be implemented:

  • fields
autoload

List of modules that needs to be loaded automatically.

category
configure_options
context_properties = ['spec', 'timestamp', 'category', 'short_description', 'long_description', 'configure_options', 'environment_modifications', 'autoload', 'verbose']
environment_modifications

List of environment modifications to be processed.

long_description
short_description
spec
timestamp
verbose

Verbosity level.

class spack.modules.common.BaseFileLayout(configuration)

Bases: object

Provides information on the layout of module files. Needs to be sub-classed for specific module types.

classmethod dirname()

Root folder for module files of this type.

extension = None

This needs to be redefined

filename

Name of the module file for the current spec.

spec

Spec under consideration

use_name

Returns the ‘use’ name of the module i.e. the name you have to type to console to use it. This implementation fits the needs of most non-hierarchical layouts.

class spack.modules.common.BaseModuleFileWriter(spec)

Bases: object

remove()

Deletes the module file.

write(overwrite=False)

Writes the module file.

Parameters:overwrite (bool) – if True it is fine to overwrite an already existing file. If False the operation is skipped an we print a warning to the user.
exception spack.modules.common.DefaultTemplateNotDefined

Bases: AttributeError, spack.modules.common.ModulesError

Raised if the attribute ‘default_template’ has not been specified in the derived classes.

exception spack.modules.common.ModulesError(message, long_message=None)

Bases: spack.error.SpackError

Base error for modules.

exception spack.modules.common.ModulesTemplateNotFoundError(message, long_message=None)

Bases: spack.modules.common.ModulesError, RuntimeError

Raised if the template for a module file was not found.

spack.modules.common.configuration = {'enable': ['tcl', 'dotkit'], 'lmod': {'hierarchy': ['mpi'], 'blacklist_implicits': False, 'hash_length': 7, 'verbose': False}, 'prefix_inspections': {'bin': ['PATH'], 'man': ['MANPATH'], 'share/man': ['MANPATH'], 'share/aclocal': ['ACLOCAL_PATH'], 'lib': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'], 'lib64': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'], 'include': ['CPATH'], 'lib/pkgconfig': ['PKG_CONFIG_PATH'], 'lib64/pkgconfig': ['PKG_CONFIG_PATH'], '': ['CMAKE_PREFIX_PATH']}}

config section for this file

spack.modules.common.dependencies(spec, request='all')

Returns the list of dependent specs for a given spec, according to the request passed as parameter.

Parameters:
  • spec – spec to be analyzed
  • request – either ‘none’, ‘direct’ or ‘all’
Returns:

list of dependencies

The return list will be empty if request is ‘none’, will contain the direct dependencies if request is ‘direct’, or the entire DAG if request is ‘all’.

spack.modules.common.merge_config_rules(configuration, spec)

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
Returns:

actions to be taken on the spec passed as an argument

Return type:

dict

spack.modules.common.prefix_inspections = {'': ['CMAKE_PREFIX_PATH'], 'bin': ['PATH'], 'include': ['CPATH'], 'lib': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'], 'lib/pkgconfig': ['PKG_CONFIG_PATH'], 'lib64': ['LIBRARY_PATH', 'LD_LIBRARY_PATH'], 'lib64/pkgconfig': ['PKG_CONFIG_PATH'], 'man': ['MANPATH'], 'share/aclocal': ['ACLOCAL_PATH'], 'share/man': ['MANPATH']}

Inspections that needs to be done on spec prefixes

spack.modules.common.root_path(name)

Returns the root folder for module file installation.

Parameters:name – name of the module system t be used (e.g. ‘tcl’)
Returns:root folder for module file installation
spack.modules.common.roots = {'dotkit': '$spack/share/spack/dotkit', 'lmod': '$spack/share/spack/lmod', 'tcl': '$spack/share/spack/modules'}

Root folders where the various module files should be written

spack.modules.common.update_dictionary_extending_lists(target, update)

Updates a dictionary, but extends lists instead of overriding them.

Parameters:
  • target – dictionary to be updated
  • update – update to be applied

spack.modules.dotkit module

This module implements the classes necessary to generate dotkit modules.

class spack.modules.dotkit.DotkitConfiguration(spec)

Bases: spack.modules.common.BaseConfiguration

Configuration class for dotkit module files.

class spack.modules.dotkit.DotkitContext(configuration)

Bases: spack.modules.common.BaseContext

Context class for dotkit module files.

context_properties = ['spec', 'timestamp', 'category', 'short_description', 'long_description', 'configure_options', 'environment_modifications', 'autoload', 'verbose']
class spack.modules.dotkit.DotkitFileLayout(configuration)

Bases: spack.modules.common.BaseFileLayout

File layout for dotkit module files.

extension = 'dk'

file extension of dotkit module files

class spack.modules.dotkit.DotkitModulefileWriter(spec)

Bases: spack.modules.common.BaseModuleFileWriter

Writer class for dotkit module files.

default_template = 'modules/modulefile.dk'
spack.modules.dotkit.configuration = {}

Dotkit specific part of the configuration

spack.modules.dotkit.configuration_registry = {}

Caches the configuration {spec_hash – configuration}

spack.modules.dotkit.make_configuration(spec)

Returns the dotkit configuration for spec

spack.modules.dotkit.make_context(spec)

Returns the context information for spec

spack.modules.dotkit.make_layout(spec)

Returns the layout information for spec

spack.modules.lmod module

exception spack.modules.lmod.CoreCompilersNotFoundError(message, long_message=None)

Bases: spack.error.SpackError, KeyError

Error raised if the key ‘core_compilers’ has not been specified in the configuration file.

class spack.modules.lmod.LmodConfiguration(spec)

Bases: spack.modules.common.BaseConfiguration

Configuration class for lmod module files.

available

Returns a dictionary of the services that are currently available.

core_compilers

Returns the list of “Core” compilers

Raises:CoreCompilersNotFoundError – if the key was not specified in the configuration file or the sequence is empty
hierarchy_tokens

Returns the list of tokens that are part of the modulefile hierarchy. ‘compiler’ is always present.

missing

Returns the list of tokens that are not available.

provides

Returns a dictionary mapping all the services provided by this spec to the spec itself.

requires

Returns a dictionary mapping all the requirements of this spec to the actual provider. ‘compiler’ is always present among the requirements.

class spack.modules.lmod.LmodContext(configuration)

Bases: spack.modules.common.BaseContext

Context class for lmod module files.

conditionally_unlocked_paths

Returns the list of paths that are unlocked conditionally. Each item in the list is a tuple with the structure (condition, path).

context_properties = ['has_modulepath_modifications', 'has_conditional_modifications', 'name_part', 'version_part', 'provides', 'missing', 'unlocked_paths', 'conditionally_unlocked_paths', 'spec', 'timestamp', 'category', 'short_description', 'long_description', 'configure_options', 'environment_modifications', 'autoload', 'verbose']
has_conditional_modifications

True if this module modifies MODULEPATH conditionally to the presence of other services in the environment, False otherwise.

has_modulepath_modifications

True if this module modifies MODULEPATH, False otherwise.

missing

Returns a list of missing services.

name_part

Name of this provider.

provides

Returns the dictionary of provided services.

unlocked_paths

Returns the list of paths that are unlocked unconditionally.

version_part

Version of this provider.

class spack.modules.lmod.LmodFileLayout(configuration)

Bases: spack.modules.common.BaseFileLayout

File layout for lmod module files.

arch_dirname

Returns the root folder for THIS architecture

available_path_parts

List of path parts that are currently available. Needed to construct the file name.

extension = 'lua'

file extension of lua module files

filename

Returns the filename for the current module file

token_to_path(name, value)

Transforms a hierarchy token into the corresponding path part.

Parameters:
  • name (str) – name of the service in the hierarchy
  • value – actual provider of the service
Returns:

part of the path associated with the service

Return type:

str

unlocked_paths

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.

use_name

Returns the ‘use’ name of the module i.e. the name you have to type to console to use it.

class spack.modules.lmod.LmodModulefileWriter(spec)

Bases: spack.modules.common.BaseModuleFileWriter

Writer class for lmod module files.

default_template = 'modules/modulefile.lua'
exception spack.modules.lmod.NonVirtualInHierarchyError(message, long_message=None)

Bases: spack.error.SpackError, TypeError

Error raised if non-virtual specs are used as hierarchy tokens in the lmod section of ‘modules.yaml’.

spack.modules.lmod.configuration = {'blacklist_implicits': False, 'hash_length': 7, 'hierarchy': ['mpi'], 'verbose': False}

TCL specific part of the configuration

spack.modules.lmod.configuration_registry = {}

Caches the configuration {spec_hash – configuration}

spack.modules.lmod.make_configuration(spec)

Returns the lmod configuration for spec

spack.modules.lmod.make_context(spec)

Returns the context information for spec

spack.modules.lmod.make_layout(spec)

Returns the layout information for spec

spack.modules.tcl module

This module implements the classes necessary to generate TCL non-hierarchical modules.

class spack.modules.tcl.TclConfiguration(spec)

Bases: spack.modules.common.BaseConfiguration

Configuration class for tcl module files.

conflicts

Conflicts for this module file

class spack.modules.tcl.TclContext(configuration)

Bases: spack.modules.common.BaseContext

Context class for tcl module files.

conflicts

List of conflicts for the tcl module file.

context_properties = ['prerequisites', 'conflicts', 'spec', 'timestamp', 'category', 'short_description', 'long_description', 'configure_options', 'environment_modifications', 'autoload', 'verbose']
prerequisites

List of modules that needs to be loaded automatically.

class spack.modules.tcl.TclFileLayout(configuration)

Bases: spack.modules.common.BaseFileLayout

File layout for tcl module files.

class spack.modules.tcl.TclModulefileWriter(spec)

Bases: spack.modules.common.BaseModuleFileWriter

Writer class for tcl module files.

default_template = 'modules/modulefile.tcl'
spack.modules.tcl.configuration = {}

TCL specific part of the configuration

spack.modules.tcl.configuration_registry = {}

Caches the configuration {spec_hash – configuration}

spack.modules.tcl.make_configuration(spec)

Returns the tcl configuration for spec

spack.modules.tcl.make_context(spec)

Returns the context information for spec

spack.modules.tcl.make_layout(spec)

Returns the layout information for spec

Module contents

This package contains code for creating environment modules, which can include dotkits, TCL non-hierarchical modules, LUA hierarchical modules, and others.

class spack.modules.DotkitModulefileWriter(spec)

Bases: spack.modules.common.BaseModuleFileWriter

Writer class for dotkit module files.

default_template = 'modules/modulefile.dk'
class spack.modules.TclModulefileWriter(spec)

Bases: spack.modules.common.BaseModuleFileWriter

Writer class for tcl module files.

default_template = 'modules/modulefile.tcl'
class spack.modules.LmodModulefileWriter(spec)

Bases: spack.modules.common.BaseModuleFileWriter

Writer class for lmod module files.

default_template = 'modules/modulefile.lua'