diff options
author | becker33 <becker33@llnl.gov> | 2016-08-03 09:49:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-03 09:49:28 -0700 |
commit | 7ae163d4369f7ab74b816f52cd0cbb4727a35876 (patch) | |
tree | 34c92730fd7e2f7e437a5e87842e108a7e53b1ec | |
parent | b9195b415a92d5ba2213e27f4d8693e82fe2fc3d (diff) | |
parent | 9c7b98dcc80d3bb3b5a09d06ec81da12b8761fb2 (diff) | |
download | spack-7ae163d4369f7ab74b816f52cd0cbb4727a35876.tar.gz spack-7ae163d4369f7ab74b816f52cd0cbb4727a35876.tar.bz2 spack-7ae163d4369f7ab74b816f52cd0cbb4727a35876.tar.xz spack-7ae163d4369f7ab74b816f52cd0cbb4727a35876.zip |
Merge pull request #1361 from epfl-scitas/features/module_token_expansion_in_environment
module : token expansion in environment
-rw-r--r-- | lib/spack/spack/environment.py | 10 | ||||
-rw-r--r-- | lib/spack/spack/modules.py | 25 | ||||
-rw-r--r-- | lib/spack/spack/test/modules.py | 9 |
3 files changed, 38 insertions, 6 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 30c6228ca4..41136ab2eb 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -37,6 +37,10 @@ class NameModifier(object): self.args = {'name': name} self.args.update(kwargs) + def update_args(self, **kwargs): + self.__dict__.update(kwargs) + self.args.update(kwargs) + class NameValueModifier(object): @@ -44,7 +48,11 @@ class NameValueModifier(object): self.name = name self.value = value self.separator = kwargs.get('separator', ':') - self.args = {'name': name, 'value': value, 'delim': self.separator} + self.args = {'name': name, 'value': value, 'separator': self.separator} + self.args.update(kwargs) + + def update_args(self, **kwargs): + self.__dict__.update(kwargs) self.args.update(kwargs) diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index db8b20ae42..8701a31c49 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -272,14 +272,26 @@ class EnvModule(object): @property def tokens(self): + """Tokens that can be substituted in environment variable values + and naming schemes + """ tokens = { 'name': self.spec.name, 'version': self.spec.version, - 'compiler': self.spec.compiler + 'compiler': self.spec.compiler, + 'prefix': self.spec.package.prefix } return tokens @property + def upper_tokens(self): + """Tokens that can be substituted in environment variable names""" + upper_tokens = { + 'name': self.spec.name.replace('-', '_').upper() + } + return upper_tokens + + @property def use_name(self): """ Subclasses should implement this to return the name the module command @@ -438,6 +450,11 @@ class EnvModule(object): def process_environment_command(self, env): for command in env: + # Token expansion from configuration file + name = command.args.get('name', '').format(**self.upper_tokens) + value = str(command.args.get('value', '')).format(**self.tokens) + command.update_args(name=name, value=value) + # Format the line int the module file try: yield self.environment_modifications_formats[type( command)].format(**command.args) @@ -511,9 +528,9 @@ class TclModule(EnvModule): name = 'tcl' path = join_path(spack.share_path, "modules") environment_modifications_formats = { - PrependPath: 'prepend-path --delim "{delim}" {name} \"{value}\"\n', - AppendPath: 'append-path --delim "{delim}" {name} \"{value}\"\n', - RemovePath: 'remove-path --delim "{delim}" {name} \"{value}\"\n', + PrependPath: 'prepend-path --delim "{separator}" {name} \"{value}\"\n', + AppendPath: 'append-path --delim "{separator}" {name} \"{value}\"\n', + RemovePath: 'remove-path --delim "{separator}" {name} \"{value}\"\n', SetEnv: 'setenv {name} \"{value}\"\n', UnsetEnv: 'unsetenv {name}\n' } diff --git a/lib/spack/spack/test/modules.py b/lib/spack/spack/test/modules.py index 135cd028e3..5e280d8e43 100644 --- a/lib/spack/spack/test/modules.py +++ b/lib/spack/spack/test/modules.py @@ -89,7 +89,10 @@ configuration_alter_environment = { 'enable': ['tcl'], 'tcl': { 'all': { - 'filter': {'environment_blacklist': ['CMAKE_PREFIX_PATH']} + 'filter': {'environment_blacklist': ['CMAKE_PREFIX_PATH']}, + 'environment': { + 'set': {'{name}_ROOT': '{prefix}'} + } }, 'platform=test target=x86_64': { 'environment': { @@ -248,6 +251,8 @@ class TclTests(MockPackagesTest): self.assertEqual( len([x for x in content if 'setenv FOO "foo"' in x]), 1) self.assertEqual(len([x for x in content if 'unsetenv BAR' in x]), 1) + self.assertEqual( + len([x for x in content if 'setenv MPILEAKS_ROOT' in x]), 1) spec = spack.spec.Spec('libdwarf %clang platform=test target=x86_32') content = self.get_modulefile_content(spec) @@ -262,6 +267,8 @@ class TclTests(MockPackagesTest): len([x for x in content if 'is-loaded foo/bar' in x]), 1) self.assertEqual( len([x for x in content if 'module load foo/bar' in x]), 1) + self.assertEqual( + len([x for x in content if 'setenv LIBDWARF_ROOT' in x]), 1) def test_blacklist(self): spack.modules.CONFIGURATION = configuration_blacklist |