summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-04-06 10:02:03 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2020-04-15 12:36:53 -0700
commita85cce05a172769e0c658ff530b106e2e6b20152 (patch)
tree29422bd2e50da92aad2b22a603855e5118535bbe /lib
parente2b1737a42c9c0c796671f9dd0c39f623e4c91c0 (diff)
downloadspack-a85cce05a172769e0c658ff530b106e2e6b20152.tar.gz
spack-a85cce05a172769e0c658ff530b106e2e6b20152.tar.bz2
spack-a85cce05a172769e0c658ff530b106e2e6b20152.tar.xz
spack-a85cce05a172769e0c658ff530b106e2e6b20152.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 248a6d3c8c..1acbb64790 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