Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .github/workflows/scripts/test_init_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [ ! -d assert.sh ]; then
fi
. assert.sh/assert.sh

TEST_SHELLS=("bash" "zsh" "fish" "ksh" "csh")
TEST_SHELLS=("bash" "zsh" "fish" "ksh" "csh" "sh")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boegel All shells are covered via this script

SHELLS=$@

for shell in ${SHELLS[@]}; do
Expand All @@ -43,7 +43,11 @@ for shell in ${SHELLS[@]}; do

# TEST 1: Source Script and check Module Output
expected_pattern=".*EESSI has selected $EESSI_SOFTWARE_SUBDIR_OVERRIDE as the compatible CPU target for EESSI/$EESSI_VERSION.*"
assert_raises "$shell -c 'source init/lmod/$shell' 2>&1 | grep -E \"${expected_pattern}\""
if [ "$shell" = "csh" ]; then
assert_raises "$shell -c 'source init/lmod/$shell' 2>&1 | grep -E \"${expected_pattern}\""
else
assert_raises "$shell -c '. init/lmod/$shell' 2>&1 | grep -E \"${expected_pattern}\""
fi

# TEST 2: Check if module overviews first section is the loaded EESSI module
if [ "$shell" = "csh" ]; then
Expand All @@ -53,7 +57,7 @@ for shell in ${SHELLS[@]}; do
echo "source init/lmod/$shell" > ~/.cshrc
MODULE_SECTIONS=($($shell -c "module ov" 2>&1 | grep -e '---'))
else
MODULE_SECTIONS=($($shell -c "source init/lmod/$shell >/dev/null 2>&1; module ov 2>&1 | grep -e '---'"))
MODULE_SECTIONS=($($shell -c ". init/lmod/$shell >/dev/null 2>&1; module ov 2>&1 | grep -e '---'"))
fi
PATTERN="/cvmfs/software\.eessi\.io/versions/$EESSI_VERSION/software/linux/$EESSI_SOFTWARE_SUBDIR_OVERRIDE/modules/all"
assert_raises 'echo "${MODULE_SECTIONS[1]}" | grep -E "$PATTERN"'
Expand All @@ -68,7 +72,7 @@ for shell in ${SHELLS[@]}; do
echo "source init/lmod/$shell" > ~/.cshrc
command="$shell -c 'module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; eb --version' | tail -n 1 | awk '{print \$4}'"
else
command="$shell -c 'source init/lmod/$shell >/dev/null 2>&1; module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; eb --version' | tail -n 1 | awk '{print \$4}'"
command="$shell -c '. init/lmod/$shell >/dev/null 2>&1; module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; eb --version' | tail -n 1 | awk '{print \$4}'"
fi
assert "$command" "$EXPECTED_EASYBUILD_VERSION"

Expand All @@ -77,7 +81,7 @@ for shell in ${SHELLS[@]}; do
echo "source init/lmod/$shell" > ~/.cshrc
EASYBUILD_PATH=$($shell -c "module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; which eb")
else
EASYBUILD_PATH=$($shell -c "source init/lmod/$shell 2>/dev/null; module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; which eb")
EASYBUILD_PATH=$($shell -c ". init/lmod/$shell 2>/dev/null; module load EasyBuild/${EXPECTED_EASYBUILD_VERSION}; which eb")
fi
# escape the dots in ${EASYBUILD_VERSION}
PATTERN="/cvmfs/software\.eessi\.io/versions/$EESSI_VERSION/software/linux/$EESSI_SOFTWARE_SUBDIR_OVERRIDE/software/EasyBuild/${EXPECTED_EASYBUILD_VERSION//./\\.}/bin/eb"
Expand All @@ -97,8 +101,8 @@ for shell in ${SHELLS[@]}; do
TEST_LMOD_SYSTEM_DEFAULT_MODULES=$($shell -c 'set -x EESSI_DEFAULT_MODULES_APPEND append_module ; set -x EESSI_DEFAULT_MODULES_PREPEND prepend_module ; set -x EESSI_EXTRA_MODULEPATH .github/workflows/modules ; source init/lmod/'"$shell"' 2>/dev/null; echo $LMOD_SYSTEM_DEFAULT_MODULES')
TEST_MODULEPATH=$($shell -c 'set -x EESSI_DEFAULT_MODULES_APPEND append_module ; set -x EESSI_DEFAULT_MODULES_PREPEND prepend_module ; set -x EESSI_EXTRA_MODULEPATH .github/workflows/modules ; source init/lmod/'"$shell"' 2>/dev/null; echo $MODULEPATH')
else
TEST_LMOD_SYSTEM_DEFAULT_MODULES=$($shell -c 'export EESSI_DEFAULT_MODULES_APPEND=append_module ; export EESSI_DEFAULT_MODULES_PREPEND=prepend_module ; export EESSI_EXTRA_MODULEPATH=.github/workflows/modules ; source init/lmod/'"$shell"' ; echo $LMOD_SYSTEM_DEFAULT_MODULES')
TEST_MODULEPATH=$($shell -c 'export EESSI_DEFAULT_MODULES_APPEND=append_module ; export EESSI_DEFAULT_MODULES_PREPEND=prepend_module ; export EESSI_EXTRA_MODULEPATH=.github/workflows/modules ; source init/lmod/'"$shell"' 2>/dev/null; echo $MODULEPATH')
TEST_LMOD_SYSTEM_DEFAULT_MODULES=$($shell -c 'export EESSI_DEFAULT_MODULES_APPEND=append_module ; export EESSI_DEFAULT_MODULES_PREPEND=prepend_module ; export EESSI_EXTRA_MODULEPATH=.github/workflows/modules ; . init/lmod/'"$shell"' ; echo $LMOD_SYSTEM_DEFAULT_MODULES')
TEST_MODULEPATH=$($shell -c 'export EESSI_DEFAULT_MODULES_APPEND=append_module ; export EESSI_DEFAULT_MODULES_PREPEND=prepend_module ; export EESSI_EXTRA_MODULEPATH=.github/workflows/modules ; . init/lmod/'"$shell"' 2>/dev/null; echo $MODULEPATH')
fi
LMOD_SYSTEM_DEFAULT_MODULES_PATTERN='^prepend_module:.*:append_module$'
# echo "$TEST_LMOD_SYSTEM_DEFAULT_MODULES" AND "$LMOD_SYSTEM_DEFAULT_MODULES_PATTERN"
Expand Down Expand Up @@ -126,8 +130,8 @@ for shell in ${SHELLS[@]}; do
TEST_EESSI_WITH_PURGE=$($shell -c "source $LMOD_PKG/init/$shell 2>/dev/null ; source init/lmod/$shell 2>/dev/null")
TEST_EESSI_WITHOUT_PURGE=$($shell -c "set -x EESSI_NO_MODULE_PURGE_ON_INIT 1 ; source $LMOD_PKG/init/$shell 2>/dev/null ; source init/lmod/$shell 2>/dev/null")
else
TEST_EESSI_WITH_PURGE=$($shell -c "source $LMOD_PKG/init/$shell 2>/dev/null ; source init/lmod/$shell 2>/dev/null")
TEST_EESSI_WITHOUT_PURGE=$($shell -c "export EESSI_NO_MODULE_PURGE_ON_INIT=1 ; source $LMOD_PKG/init/$shell 2>/dev/null ; source init/lmod/$shell 2>/dev/null")
TEST_EESSI_WITH_PURGE=$($shell -c ". $LMOD_PKG/init/$shell 2>/dev/null ; . init/lmod/$shell 2>/dev/null")
TEST_EESSI_WITHOUT_PURGE=$($shell -c "export EESSI_NO_MODULE_PURGE_ON_INIT=1 ; . $LMOD_PKG/init/$shell 2>/dev/null ; . init/lmod/$shell 2>/dev/null")
fi
# In the first case we should have the test and in the second case we shouldn't
pattern="Modules purged before initialising EESSI"
Expand All @@ -139,10 +143,10 @@ for shell in ${SHELLS[@]}; do
fi

# Optional test 10, check if the prompt has been updated
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ]; then
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ] || [ "$shell" = "sh" ]; then
# Typically this is a non-interactive shell, so manually unset PS1 and reset to a non-exported variable when testing
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; source init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
TEST_EESSI_NO_PS1_UPDATE=$($shell -c "unset PS1 ; source init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
TEST_EESSI_NO_PS1_UPDATE=$($shell -c "unset PS1 ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
pattern="{EESSI/${EESSI_VERSION}} "
assert_raises 'echo "$TEST_EESSI_PS1_UPDATE" | grep "$pattern"'
assert_raises 'echo "$TEST_EESSI_NO_PS1_UPDATE" | grep "$pattern"' 1
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests_init_module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
- name: Install missing shells
run: |
sudo apt update
# We're in Ubuntu so dash is already installed (and is symlinked to sh)
sudo apt install zsh ksh fish tcsh
echo "# INIT ZSH" > ~/.zshrc

Expand All @@ -65,7 +66,7 @@ jobs:
export EESSI_SOFTWARE_SUBDIR_OVERRIDE=${{matrix.EESSI_SOFTWARE_SUBDIR_OVERRIDE}}
export EESSI_VERSION=${{matrix.EESSI_VERSION}}
export EXPECTED_EASYBUILD_VERSION=${{matrix.EXPECTED_EASYBUILD_VERSION}}
.github/workflows/scripts/test_init_scripts.sh "bash" "zsh" "ksh" "fish" "csh"
.github/workflows/scripts/test_init_scripts.sh "bash" "zsh" "ksh" "fish" "csh" "sh"
- name: Run tests for available shells with system Lmod
run: |
# We also want to perform the same test when there is an Lmod version available on the system
Expand All @@ -76,4 +77,4 @@ jobs:
export EESSI_SOFTWARE_SUBDIR_OVERRIDE=${{matrix.EESSI_SOFTWARE_SUBDIR_OVERRIDE}}
export EESSI_VERSION=${{matrix.EESSI_VERSION}}
export EXPECTED_EASYBUILD_VERSION=${{matrix.EXPECTED_EASYBUILD_VERSION}}
.github/workflows/scripts/test_init_scripts.sh "bash" "zsh" "ksh" "fish" "csh"
.github/workflows/scripts/test_init_scripts.sh "bash" "zsh" "ksh" "fish" "csh" "sh"
24 changes: 20 additions & 4 deletions init/lmod/bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script is meant to be sourced, so the shebang here is meaningless


# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2020-2026 EESSI contributors
Expand Down Expand Up @@ -49,7 +49,12 @@ EESSI_CVMFS_REPO="${EESSI_CVMFS_REPO:-/cvmfs/software.eessi.io}"
# (Note: in the repository which is home to this file a template value __EESSI_VERSION_DEFAULT__ is present in
# the line below which is replaced within our deployment pipeline.)
EESSI_VERSION_DEFAULT="${__EESSI_VERSION_USED_FOR_INIT:-__EESSI_VERSION_DEFAULT__}"
EESSI_VERSION="${EESSI_VERSION:-${EESSI_VERSION_DEFAULT}}"
if [ -z "$__Init_EESSI_Default_Modules" ]; then
EESSI_VERSION="${EESSI_VERSION:-${EESSI_VERSION_DEFAULT}}"
else
# If we have already initialised and this is being called again, then we must want the specific version
EESSI_VERSION="__EESSI_VERSION_DEFAULT__"
fi
# On the first run we want to record the EESSI version used for init as an environment variable so that if a different
# version of this script is called (e.g, for a a different EESSI version) it retains a memory which EESSI
# version was actually used in the initialisation. This is useful as __Init_EESSI_Default_Modules used below will
Expand All @@ -75,7 +80,7 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then

# Lmod version in 2023.06 has a problem with newer Lmod caches, so let's stick to more recent Lmod
# (has no effect except on Lmod itself, and compatible caches are still created/supported by EESSI)
LMOD_EESSI_VERSION=${EESSI_VERSION/2023.06/2025.06}
LMOD_EESSI_VERSION=$(printf '%s\n' "$EESSI_VERSION" | sed 's/2023\.06/2025\.06/')

# Let's attempt a purge of any loaded modules as any environment variables currently set will survive EESSI initialisation
# (it's ok if the module command does not exist)
Expand All @@ -96,10 +101,21 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
export EESSI_MODULE_UPDATE_PS1=1
fi

# Figure out what shell we have
if [ -n "${BASH_VERSION-}" ]; then
shell=bash
elif [ -n "${ZSH_VERSION-}" ]; then
shell=zsh
elif [ -n "${KSH_VERSION-}" ]; then
shell=ksh
else
shell=sh
fi

# Path to top-level module tree
# - EESSI_EXTRA_MODULEPATH environment variable allows a site to append to MODULEPATH (lower priority than EESSI MODULEPATH)
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/bash"
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/${shell}"
module --initial_load --no_redirect restore

# After initialising, we now know the architecture(s) that was/were selected so let's report them
Expand Down
12 changes: 10 additions & 2 deletions init/lmod/csh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ if ( ! $?__EESSI_VERSION_USED_FOR_INIT ) then
else
set EESSI_VERSION_DEFAULT = "$__EESSI_VERSION_USED_FOR_INIT"
endif
if ( ! $?EESSI_VERSION ) then
set EESSI_VERSION = "$EESSI_VERSION_DEFAULT"
if ( ! $?__Init_EESSI_Default_Modules ) then
if ( $?EESSI_VERSION ) then
# keep existing value
else
set EESSI_VERSION "$EESSI_VERSION_DEFAULT"
endif
else
# If we have already initialised and this is being called again,
# then we must want the specific version
set EESSI_VERSION "__EESSI_VERSION_DEFAULT__"
endif
# On first run, record the EESSI version used for init as an environment variable.
# We use setenv to ensure it is available to child processes (equivalent to export).
Expand Down
12 changes: 10 additions & 2 deletions init/lmod/fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ if not set -q __EESSI_VERSION_USED_FOR_INIT
else
set EESSI_VERSION_DEFAULT "$__EESSI_VERSION_USED_FOR_INIT"
end
if not set -q EESSI_VERSION
set EESSI_VERSION "$EESSI_VERSION_DEFAULT"
if not set -q __Init_EESSI_Default_Modules
if set -q EESSI_VERSION
# keep existing value
else
set EESSI_VERSION $EESSI_VERSION_DEFAULT
end
else
# If we have already initialised and this is being called again,
# then we must want the specific version
set EESSI_VERSION "__EESSI_VERSION_DEFAULT__"
end

# Record version used for init; -x exports it to the environment
Expand Down
73 changes: 0 additions & 73 deletions init/lmod/ksh

This file was deleted.

1 change: 1 addition & 0 deletions init/lmod/ksh
1 change: 1 addition & 0 deletions init/lmod/sh
Loading
Loading