Skip to content

Commit c2ab5c1

Browse files
authored
Merge pull request #154 from ocaisa/update_prompt_with_module
Add capability to update `PS1` when loading the EESSI module
2 parents 6e27876 + 0be8f62 commit c2ab5c1

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

.github/workflows/tests_eessi_module.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,45 @@ jobs:
315315
module load "EESSI/${{matrix.EESSI_VERSION}}"
316316
GREP_PATTERN="Lmod is automatically replacing \"EESSI/${{matrix.EESSI_VERSION}}\" with \"${LOCAL_STACK_NAME}/${LOCAL_STACK_VERSION}\"."
317317
module load "${LOCAL_STACK_NAME}/${LOCAL_STACK_VERSION}" |& grep "${GREP_PATTERN}"
318+
319+
check_PS1_update_eessi_module:
320+
runs-on: ubuntu-24.04
321+
strategy:
322+
fail-fast: false
323+
matrix:
324+
EESSI_VERSION:
325+
- '2023.06'
326+
- '2025.06'
327+
328+
steps:
329+
- name: Check out software-layer repository
330+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
331+
332+
- name: Mount EESSI CernVM-FS repository
333+
uses: cvmfs-contrib/github-action-cvmfs@55899ca74cf78ab874bdf47f5a804e47c198743c # v4.0
334+
with:
335+
cvmfs_config_package: https://github.com/EESSI/filesystem-layer/releases/download/latest/cvmfs-config-eessi_latest_all.deb
336+
cvmfs_http_proxy: DIRECT
337+
cvmfs_repositories: software.eessi.io
338+
339+
- name: Make sure we can use EESSI_UPDATE_PS1 to update PS1 in the EESSI module
340+
run: |
341+
# Initialise Lmod
342+
. /cvmfs/software.eessi.io/versions/${{matrix.EESSI_VERSION}}/compat/linux/$(uname -m)/usr/share/Lmod/init/bash
343+
344+
export MODULEPATH=init/modules
345+
# Set the relevant environment variable, load the EESSI module, and grep for what we expect in PS1
346+
export EESSI_MODULE_UPDATE_PS1=1
347+
# Need to set PS1 manually as we are in a non-interactive shell
348+
export PS1="mytest $"
349+
echo $PS1
350+
module load "EESSI/${{matrix.EESSI_VERSION}}"
351+
GREP_PATTERN="{EESSI/${{matrix.EESSI_VERSION}}} "
352+
# Pipe the PS1 variable into grep to check for the pattern
353+
echo "$PS1"
354+
echo "$PS1" | grep "$GREP_PATTERN"
355+
356+
# Let's also check that quiet mode works
357+
module load "EESSI/${{matrix.EESSI_VERSION}}" |& grep -q "Module for EESSI/${{matrix.EESSI_VERSION}} loaded successfully"
358+
export EESSI_MODULE_QUIET_LOAD=1
359+
! module load "EESSI/${{matrix.EESSI_VERSION}}" |& grep -q "Module for EESSI/${{matrix.EESSI_VERSION}} loaded successfully"

init/modules/EESSI/2023.06.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,26 @@ if family_name then
214214
family(family_name)
215215
end
216216

217+
-- Change the PS1 to indicate you have EESSI loaded. For this to work, it requires that
218+
-- PS1 exists _and_ is exported (i.e, an environment variable, *not* a shell variable)
219+
-- (doesn't help with a csh or fish prompt, but we just live with that)
220+
local quiet_load = false
221+
if os.getenv("EESSI_MODULE_UPDATE_PS1") then
222+
local prompt = os.getenv("PS1")
223+
if prompt then
224+
pushenv("PS1", "{EESSI/" .. eessi_version .. "} " .. prompt)
225+
end
226+
end
227+
217228
-- allow sites to make the EESSI module sticky by defining EESSI_MODULE_STICKY (to any value)
218-
load_message = "Module for EESSI/" .. eessi_version .. " loaded successfully"
229+
local load_message = "Module for EESSI/" .. eessi_version .. " loaded successfully"
219230
if os.getenv("EESSI_MODULE_STICKY") then
220231
add_property("lmod","sticky")
221232
load_message = load_message .. " (requires '--force' option to unload or purge)"
222233
end
223234

224235
if mode() == "load" then
225-
LmodMessage(load_message)
236+
if not os.getenv("EESSI_MODULE_QUIET_LOAD") then
237+
LmodMessage(load_message)
238+
end
226239
end

0 commit comments

Comments
 (0)