summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-04-06 10:02:03 +0200
committerGitHub <noreply@github.com>2020-04-06 10:02:03 +0200
commit06f3381dfd4355939350a6f20004fcebe3a25d24 (patch)
tree0638b01fe82c4524be3455ee190961fe2a0ab1d9 /lib
parent359d7adf7ee07aa1adc09f2ad4aace1a0cd6316a (diff)
downloadspack-06f3381dfd4355939350a6f20004fcebe3a25d24.tar.gz
spack-06f3381dfd4355939350a6f20004fcebe3a25d24.tar.bz2
spack-06f3381dfd4355939350a6f20004fcebe3a25d24.tar.xz
spack-06f3381dfd4355939350a6f20004fcebe3a25d24.zip
Blacklist Lmod variable modifications when sourcing files (#15778)
fixes #15775 Add all the variables listed here: https://lmod.readthedocs.io/en/latest/090_configuring_lmod.html to the list of those blacklisted when constructing environment modifications by sourcing files.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/data/sourceme_lmod.sh10
-rw-r--r--lib/spack/spack/test/environment_modifications.py11
-rw-r--r--lib/spack/spack/util/environment.py4
3 files changed, 24 insertions, 1 deletions
diff --git a/lib/spack/spack/test/data/sourceme_lmod.sh b/lib/spack/spack/test/data/sourceme_lmod.sh
new file mode 100644
index 0000000000..b71e338ec9
--- /dev/null
+++ b/lib/spack/spack/test/data/sourceme_lmod.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+#
+# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+export LMOD_VARIABLE=foo
+export LMOD_ANOTHER_VARIABLE=bar
+export NEW_VAR=new
diff --git a/lib/spack/spack/test/environment_modifications.py b/lib/spack/spack/test/environment_modifications.py
index 9983594a84..d1f5a4b791 100644
--- a/lib/spack/spack/test/environment_modifications.py
+++ b/lib/spack/spack/test/environment_modifications.py
@@ -437,3 +437,14 @@ def test_from_environment_diff(before, after, search_list):
for item in search_list:
assert item in mod
+
+
+@pytest.mark.regression('15775')
+def test_blacklist_lmod_variables():
+ # Construct the list of environment modifications
+ file = os.path.join(datadir, 'sourceme_lmod.sh')
+ env = EnvironmentModifications.from_sourcing_file(file)
+
+ # Check that variables related to lmod are not in there
+ modifications = env.group_by_name()
+ assert not any(x.startswith('LMOD_') for x in modifications)
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
index 862f04f8eb..8069f51431 100644
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -597,7 +597,9 @@ class EnvironmentModifications(object):
'SHLVL', '_', 'PWD', 'OLDPWD', 'PS1', 'PS2', 'ENV',
# Environment modules v4
'LOADEDMODULES', '_LMFILES_', 'BASH_FUNC_module()', 'MODULEPATH',
- 'MODULES_(.*)', r'(\w*)_mod(quar|share)'
+ 'MODULES_(.*)', r'(\w*)_mod(quar|share)',
+ # Lmod configuration
+ r'LMOD_(.*)', 'MODULERCFILE'
])
# Compute the environments before and after sourcing