Skip to content

Commit f453fe9

Browse files
authored
Merge pull request #195 from ocaisa/reset_in_new_shell
Allow EESSI to re-initialised in a subshell (since a subshell may restore a system module tool)
2 parents 4c81f00 + 6fa5c28 commit f453fe9

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

.github/workflows/scripts/test_init_scripts.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ for shell in ${SHELLS[@]}; do
4949
assert_raises "$shell -c '. init/lmod/$shell' 2>&1 | grep -E \"${expected_pattern}\""
5050
fi
5151

52-
# TEST 2: Check if module overviews first section is the loaded EESSI module
52+
# TEST 2: Source Script again in an subshell and check Module Output
53+
expected_pattern=".*EESSI has selected $EESSI_SOFTWARE_SUBDIR_OVERRIDE as the compatible CPU target for EESSI/$EESSI_VERSION.*"
54+
if [ "$shell" = "csh" ]; then
55+
# Cannot figure out how to chain shells with silenced output to test this in csh but it does work
56+
# assert_raises "$shell -c 'setenv LMOD_QUIET 1 ; source init/lmod/$shell ; ($shell -c \"unsetenv LMOD_QUIET ; source init/lmod/$shell\")' 2>&1 | grep -E \"${expected_pattern}\""
57+
echo "Skipping chained shell check for csh as can't figure out how to silence output in first call"
58+
else
59+
assert_raises "$shell -c '. init/lmod/$shell > /dev/null 2>&1; $shell -c \". init/lmod/$shell\"' 2>&1 | grep -E \"${expected_pattern}\""
60+
fi
61+
62+
# TEST 3: Check if module overviews first section is the loaded EESSI module
5363
if [ "$shell" = "csh" ]; then
5464
# module is defined as alias, but aliases are only retained in interactive
5565
# shells we work around this by creating a .cshrc file (which sources the
@@ -63,10 +73,10 @@ for shell in ${SHELLS[@]}; do
6373
assert_raises 'echo "${MODULE_SECTIONS[1]}" | grep -E "$PATTERN"'
6474
# echo "${MODULE_SECTIONS[1]}" "$PATTERN"
6575

66-
# TEST 3: Check if module overviews second section is the EESSI init module
76+
# TEST 4: Check if module overviews second section is the EESSI init module
6777
assert "echo ${MODULE_SECTIONS[4]}" "/cvmfs/software.eessi.io/init/modules"
6878

69-
# TEST 4: Load EasyBuild module and check version
79+
# TEST 5: Load EasyBuild module and check version
7080
# eb --version outputs: "This is EasyBuild 5.1.1 (framework: 5.1.1, easyblocks: 5.1.1) on host ..."
7181
if [ "$shell" = "csh" ]; then
7282
echo "source init/lmod/$shell" > ~/.cshrc
@@ -76,7 +86,7 @@ for shell in ${SHELLS[@]}; do
7686
fi
7787
assert "$command" "$EXPECTED_EASYBUILD_VERSION"
7888

79-
# TEST 5: Load EasyBuild module and check path
89+
# TEST 6: Load EasyBuild module and check path
8090
if [ "$shell" = "csh" ]; then
8191
echo "source init/lmod/$shell" > ~/.cshrc
8292
EASYBUILD_PATH=$($shell -c "module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; which eb")
@@ -89,7 +99,7 @@ for shell in ${SHELLS[@]}; do
8999
assert_raises 'echo "$EASYBUILD_PATH" | grep -E "$PATTERN"'
90100
# echo "$EASYBUILD_PATH" "$PATTERN"
91101

92-
# TEST 6 and 7: Check the various options (EESSI_DEFAULT_MODULES_APPEND, EESSI_DEFAULT_MODULES_APPEND, EESSI_EXTRA_MODULEPATH) all work
102+
# TEST 7 and 8: Check the various options (EESSI_DEFAULT_MODULES_APPEND, EESSI_DEFAULT_MODULES_APPEND, EESSI_EXTRA_MODULEPATH) all work
93103
if [ "$shell" = "csh" ]; then
94104
echo "setenv EESSI_DEFAULT_MODULES_APPEND append_module" > ~/.cshrc
95105
echo "setenv EESSI_DEFAULT_MODULES_PREPEND prepend_module" >> ~/.cshrc
@@ -115,7 +125,7 @@ for shell in ${SHELLS[@]}; do
115125
# echo "$TEST_MODULEPATH" AND "$MODULEPATH_PATTERN"
116126
assert_raises 'echo "$TEST_MODULEPATH" | grep -E "$MODULEPATH_PATTERN"'
117127

118-
# TEST 8 and 9: Add a conditional test depending on whether we have the Lmod command is available locally or not (Ubuntu-based location for CI)
128+
# TEST 9 and 10: Add a conditional test depending on whether we have the Lmod command is available locally or not (Ubuntu-based location for CI)
119129
if [ -d "$LMOD_PKG/init" ]; then
120130
echo "Running check for locally available Lmod with purge"
121131
if [ "$shell" = "csh" ]; then
@@ -142,7 +152,7 @@ for shell in ${SHELLS[@]}; do
142152
assert_raises 'echo "$TEST_EESSI_WITHOUT_PURGE" | grep "$pattern"' 1
143153
fi
144154

145-
# Optional test 10, check if the prompt has been updated
155+
# Optional test 11, check if the prompt has been updated
146156
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ] || [ "$shell" = "sh" ]; then
147157
# Typically this is a non-interactive shell, so manually unset PS1 and reset to a non-exported variable when testing
148158
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")

init/lmod/csh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
if ( ! $?EESSI_CVMFS_REPO) then
1414
set EESSI_CVMFS_REPO = "/cvmfs/software.eessi.io"
1515
endif
16+
set internal_cvmfs_repo = "$EESSI_CVMFS_REPO"
1617

1718
# Choose an EESSI version (default is used if EESSI_VERSION is not provided)
1819
if ( ! $?__EESSI_VERSION_USED_FOR_INIT ) then
@@ -21,15 +22,13 @@ else
2122
set EESSI_VERSION_DEFAULT = "$__EESSI_VERSION_USED_FOR_INIT"
2223
endif
2324
if ( ! $?__Init_EESSI_Default_Modules ) then
24-
if ( $?EESSI_VERSION ) then
25-
# keep existing value
26-
else
27-
set EESSI_VERSION "$EESSI_VERSION_DEFAULT"
25+
if ( ! $?EESSI_VERSION ) then
26+
set EESSI_VERSION = "$EESSI_VERSION_DEFAULT"
2827
endif
2928
else
3029
# If we have already initialised and this is being called again,
3130
# then we must want the specific version
32-
set EESSI_VERSION "__EESSI_VERSION_DEFAULT__"
31+
set EESSI_VERSION = "__EESSI_VERSION_DEFAULT__"
3332
endif
3433
# On first run, record the EESSI version used for init as an environment variable.
3534
# We use setenv to ensure it is available to child processes (equivalent to export).
@@ -48,7 +47,7 @@ endif
4847
setenv LMOD_SYSTEM_DEFAULT_MODULES "${LMOD_SYSTEM_DEFAULT_MODULES}"
4948

5049
if ( ! $?__Init_EESSI_Default_Modules ) then
51-
setenv __Init_EESSI_Default_Modules 1
50+
set __Init_EESSI_Default_Modules = 1
5251

5352
# Lmod version in 2023.06 has a problem with newer Lmod caches, so let's stick to more recent Lmod
5453
# (has no effect except on Lmod itself, and compatible caches are still created/supported by EESSI)
@@ -67,15 +66,15 @@ if ( ! $?__Init_EESSI_Default_Modules ) then
6766
# and clear out any memory Lmod might have
6867
unsetenv _ModuleTable001_
6968
# Path to top-level module tree
70-
set modulepath = "${EESSI_CVMFS_REPO}/init/modules"
69+
set modulepath = "${internal_cvmfs_repo}/init/modules"
7170
if ( $?EESSI_EXTRA_MODULEPATH ) then
7271
# Now that we know it exists, check IF it is not empty
7372
if ( "$EESSI_EXTRA_MODULEPATH" != "" ) then
7473
set modulepath = "${modulepath}:${EESSI_EXTRA_MODULEPATH}"
7574
endif
7675
endif
7776
setenv MODULEPATH "$modulepath"
78-
source "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/`uname -m`/usr/share/Lmod/init/csh"
77+
source "${internal_cvmfs_repo}/versions/${LMOD_EESSI_VERSION}/compat/linux/`uname -m`/usr/share/Lmod/init/csh"
7978

8079
module --initial_load --no_redirect restore
8180

init/lmod/fish

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Please refer to the reference bash implementation for full documentation, only minimal comments are included here
1111

1212
# Choose an EESSI CVMFS repository
13-
set EESSI_CVMFS_REPO (set -q EESSI_CVMFS_REPO; and echo "$EESSI_CVMFS_REPO"; or echo "/cvmfs/software.eessi.io")
13+
set internal_cvmfs_repo (set -q EESSI_CVMFS_REPO; and echo "$EESSI_CVMFS_REPO"; or echo "/cvmfs/software.eessi.io")
1414

1515
# Choose an EESSI version
1616
if not set -q __EESSI_VERSION_USED_FOR_INIT
@@ -46,7 +46,7 @@ end
4646
set -x LMOD_SYSTEM_DEFAULT_MODULES $LMOD_SYSTEM_DEFAULT_MODULES
4747

4848
if test -z "$__Init_EESSI_Default_Modules"
49-
set -x __Init_EESSI_Default_Modules 1
49+
set __Init_EESSI_Default_Modules 1
5050

5151
# Lmod version in 2023.06 has a problem with newer Lmod caches, so let's stick to more recent Lmod
5252
# (has no effect except on Lmod itself, and compatible caches are still created/supported by EESSI)
@@ -64,12 +64,12 @@ if test -z "$__Init_EESSI_Default_Modules"
6464
# and clear out any memory Lmod might have
6565
set -e _ModuleTable001_
6666
# Path to top-level module tree
67-
set modulepath "$EESSI_CVMFS_REPO/init/modules"
67+
set modulepath "$internal_cvmfs_repo/init/modules"
6868
if set -q EESSI_EXTRA_MODULEPATH; and test -n "$EESSI_EXTRA_MODULEPATH"
6969
set modulepath "$modulepath:$EESSI_EXTRA_MODULEPATH"
7070
end
7171
set -x MODULEPATH $modulepath
72-
. "$EESSI_CVMFS_REPO"/versions/"$LMOD_EESSI_VERSION"/compat/linux/(uname -m)/usr/share/Lmod/init/fish
72+
. "$internal_cvmfs_repo"/versions/"$LMOD_EESSI_VERSION"/compat/linux/(uname -m)/usr/share/Lmod/init/fish
7373

7474
module --initial_load --no_redirect restore
7575

init/lmod/sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
# - Lmod initialisation cannot be undone
4444

4545
# Choose an EESSI CVMFS repository
46-
EESSI_CVMFS_REPO="${EESSI_CVMFS_REPO:-/cvmfs/software.eessi.io}"
46+
internal_cvmfs_repo="${EESSI_CVMFS_REPO:-/cvmfs/software.eessi.io}"
4747

4848
# Choose an EESSI version (the default is only used if the EESSI_VERSION environment variable is not provided)
4949
# (Note: in the repository which is home to this file a template value __EESSI_VERSION_DEFAULT__ is present in
5050
# the line below which is replaced within our deployment pipeline.)
5151
EESSI_VERSION_DEFAULT="${__EESSI_VERSION_USED_FOR_INIT:-__EESSI_VERSION_DEFAULT__}"
52-
if [ -z "$__Init_EESSI_Default_Modules" ]; then
52+
if [ "${__Init_EESSI_Default_Modules-}" != "1" ]; then
5353
EESSI_VERSION="${EESSI_VERSION:-${EESSI_VERSION_DEFAULT}}"
5454
else
5555
# If we have already initialised and this is being called again, then we must want the specific version
@@ -75,8 +75,10 @@ export __EESSI_VERSION_USED_FOR_INIT="${__EESSI_VERSION_USED_FOR_INIT:-${EESSI_V
7575
LMOD_SYSTEM_DEFAULT_MODULES="${EESSI_DEFAULT_MODULES_PREPEND:+$EESSI_DEFAULT_MODULES_PREPEND:}EESSI/$EESSI_VERSION${EESSI_DEFAULT_MODULES_APPEND:+:$EESSI_DEFAULT_MODULES_APPEND}"
7676
export LMOD_SYSTEM_DEFAULT_MODULES
7777

78-
if [ -z "$__Init_EESSI_Default_Modules" ]; then
79-
export __Init_EESSI_Default_Modules=1;
78+
if [ "${__Init_EESSI_Default_Modules-}" != "1" ]; then
79+
# We do _not_ export this as we do not want it picked up by a new shell
80+
# (since the system module tool may be restored in that scenario)
81+
__Init_EESSI_Default_Modules=1
8082

8183
# Lmod version in 2023.06 has a problem with newer Lmod caches, so let's stick to more recent Lmod
8284
# (has no effect except on Lmod itself, and compatible caches are still created/supported by EESSI)
@@ -122,8 +124,8 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
122124
# Path to top-level module tree
123125
# - EESSI_EXTRA_MODULEPATH environment variable allows a site to append to MODULEPATH
124126
# (lower priority than EESSI MODULEPATH)
125-
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
126-
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/${shell}"
127+
export MODULEPATH="${internal_cvmfs_repo}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
128+
. "${internal_cvmfs_repo}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/${shell}"
127129
module --initial_load --no_redirect restore
128130

129131
# After initialising, we now know the architecture(s) that was/were selected so let's report them

0 commit comments

Comments
 (0)