From a85cce05a172769e0c658ff530b106e2e6b20152 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Mon, 6 Apr 2020 10:02:03 +0200 Subject: 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. --- lib/spack/spack/test/data/sourceme_lmod.sh | 10 ++++++++++ lib/spack/spack/test/environment_modifications.py | 11 +++++++++++ lib/spack/spack/util/environment.py | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/spack/spack/test/data/sourceme_lmod.sh 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 -- cgit v1.2.3-60-g2f50