modules: ignore more Modules variables in from_sourcing_file (#38455)

Update list of excluded variables in `from_sourcing_file` function to
cover all variables specific to Environment Modules or Lmod. Add
specifically variables relative to the definition of `module()`, `ml()`
and `_module_raw()` Bash functions.

Fixes #13504
This commit is contained in:
Xavier Delaruelle 2023-06-26 20:21:46 +02:00 committed by GitHub
parent 46fe1f48bc
commit 1dcc67535a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 7 deletions

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Copyright 2013-2023 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)
_module_raw() { return 1; };
module() { return 1; };
ml() { return 1; };
export -f _module_raw;
export -f module;
export -f ml;
export MODULES_AUTO_HANDLING=1
export __MODULES_LMCONFLICT=bar&foo
export NEW_VAR=new

View file

@ -400,7 +400,7 @@ def test_sanitize_literals(env, exclude, include):
({"SHLVL": "1"}, ["SH.*"], [], [], ["SHLVL"]),
# Check we can include using a regex
({"SHLVL": "1"}, ["SH.*"], ["SH.*"], ["SHLVL"], []),
# Check regex to exclude Modules v4 related vars
# Check regex to exclude Environment Modules related vars
(
{"MODULES_LMALTNAME": "1", "MODULES_LMCONFLICT": "2"},
["MODULES_(.*)"],
@ -415,6 +415,13 @@ def test_sanitize_literals(env, exclude, include):
[],
["A_modquar", "b_modquar", "C_modshare"],
),
(
{"__MODULES_LMTAG": "1", "__MODULES_LMPREREQ": "2"},
["__MODULES_(.*)"],
[],
[],
["__MODULES_LMTAG", "__MODULES_LMPREREQ"],
),
],
)
def test_sanitize_regex(env, exclude, include, expected, deleted):
@ -489,3 +496,19 @@ def test_exclude_lmod_variables():
# 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)
@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)")
@pytest.mark.regression("13504")
def test_exclude_modules_variables():
# Construct the list of environment modifications
file = os.path.join(datadir, "sourceme_modules.sh")
env = EnvironmentModifications.from_sourcing_file(file)
# Check that variables related to modules are not in there
modifications = env.group_by_name()
assert not any(x.startswith("MODULES_") for x in modifications)
assert not any(x.startswith("__MODULES_") for x in modifications)
assert not any(x.startswith("BASH_FUNC_ml") for x in modifications)
assert not any(x.startswith("BASH_FUNC_module") for x in modifications)
assert not any(x.startswith("BASH_FUNC__module_raw") for x in modifications)

View file

@ -776,16 +776,21 @@ def from_sourcing_file(
"PS1",
"PS2",
"ENV",
# Environment modules v4
# Environment Modules or Lmod
"LOADEDMODULES",
"_LMFILES_",
"BASH_FUNC_module()",
"MODULEPATH",
"MODULES_(.*)",
r"(\w*)_mod(quar|share)",
# Lmod configuration
r"LMOD_(.*)",
"MODULERCFILE",
"BASH_FUNC_ml()",
"BASH_FUNC_module()",
# Environment Modules-specific configuration
"MODULESHOME",
"BASH_FUNC__module_raw()",
r"MODULES_(.*)",
r"__MODULES_(.*)",
r"(\w*)_mod(quar|share)",
# Lmod-specific configuration
r"LMOD_(.*)",
]
)