summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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