Skip to content

Commit

Permalink
Merge pull request #525 from casparvl/allow_lmod_hook_host_injections
Browse files Browse the repository at this point in the history
Allow defining lmod hooks in host injections
  • Loading branch information
boegel authored Apr 2, 2024
2 parents e479236 + 1e8eb6e commit 1eeb8ab
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/tests_scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- build_container.sh
- create_directory_tarballs.sh
- create_lmodsitepackage.py
- EESSI-install-software.sh
- install_software_layer.sh
- load_easybuild_module.sh
Expand All @@ -16,6 +17,7 @@ on:
paths:
- build_container.sh
- create_directory_tarballs.sh
- create_lmodsitepackage.py
- EESSI-install-software.sh
- install_software_layer.sh
- load_easybuild_module.sh
Expand Down Expand Up @@ -96,3 +98,24 @@ jobs:
./eessi_container.sh --mode run --verbose /software-layer/create_directory_tarballs.sh 2023.06
# check if tarballs have been produced
ls -l *.tar.gz
- name: test create_lmodsitepackage.py script
run: |
# bind current directory into container as /software-layer
export SINGULARITY_BIND="${PWD}:/software-layer"
# Creates .lmod/SitePackage.lua in current dir, which then gets bind-mounted into /software-layer
python3 create_lmodsitepackage.py .
# run some commands to make sure that generated Lmod SitePackage file works
test_script="${PWD}/test_lmod_sitepackage.sh"
echo '#!/bin/bash' > ${test_script}
echo 'export LMOD_PACKAGE_PATH="/software-layer/.lmod"' > ${test_script}
echo 'ml --config' >> ${test_script}
chmod u+x ${test_script}
out="${PWD}/test_create_lmodsitepackage.out"
./eessi_container.sh --mode run --verbose /software-layer/run_in_compat_layer_env.sh /software-layer/test_lmod_sitepackage.sh 2>&1 | tee ${out}
for pattern in "^Site Pkg location.*/software-layer/.lmod/SitePackage.lua" "LMOD_SITEPACKAGE_LOCATION.*/software-layer/.lmod/SitePackage.lua"; do
grep "${pattern}" ${out} || (echo "Pattern '${pattern}' not found in output!" && exit 1)
done
68 changes: 68 additions & 0 deletions create_lmodsitepackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,71 @@
return content
end
local function load_site_specific_hooks()
-- This function will be run after the EESSI hooks are registered
-- It will load a local SitePackage.lua that is architecture independent (if it exists) from e.g.
-- /cvmfs/software.eessi.io/host_injections/2023.06/.lmod/SitePackage.lua
-- That can define a new hook
--
-- function site_specific_load_hook(t)
-- <some_action_on_load>
-- end
--
-- And the either append to the existing hook:
--
-- local function final_load_hook(t)
-- eessi_load_hook(t)
-- site_specific_load_hook(t)
-- end
--
-- Over overwrite the EESSI hook entirely:
--
-- hook.register("load", final_load_hook)
--
-- Note that the appending procedure can be simplified once we have an lmod >= 8.7.36
-- See https://github.com/TACC/Lmod/pull/696#issuecomment-1998765722
--
-- Subsequently, this function will look for an architecture-specific SitePackage.lua, e.g. from
-- /cvmfs/software.eessi.io/host_injections/2023.06/software/linux/x86_64/amd/zen2/.lmod/SitePackage.lua
-- This can then register an additional hook, e.g.
--
-- function arch_specific_load_hook(t)
-- <some_action_on_load>
-- end
--
-- local function final_load_hook(t)
-- eessi_load_hook(t)
-- site_specific_load_hook(t)
-- arch_specific_load_hook(t)
-- end
--
-- hook.register("load", final_load_hook)
--
-- Again, the host site could also decide to overwrite by simply doing
--
-- hook.register("load", arch_specific_load_hook)
-- get path to to architecture independent SitePackage.lua
local prefixHostInjections = string.gsub(os.getenv('EESSI_PREFIX') or "", 'versions', 'host_injections')
local hostSitePackage = prefixHostInjections .. "/.lmod/SitePackage.lua"
-- If the file exists, run it
if isFile(hostSitePackage) then
dofile(hostSitePackage)
end
-- build the full architecture specific path in host_injections
local archHostInjections = string.gsub(os.getenv('EESSI_SOFTWARE_PATH') or "", 'versions', 'host_injections')
local archSitePackage = archHostInjections .. "/.lmod/SitePackage.lua"
-- If the file exists, run it
if isFile(archSitePackage) then
dofile(archSitePackage)
end
end
local function eessi_cuda_enabled_load_hook(t)
local frameStk = require("FrameStk"):singleton()
local mt = frameStk:mt()
Expand Down Expand Up @@ -92,6 +157,9 @@
hook.register("load", eessi_load_hook)
-- Note that this needs to happen at the end, so that any EESSI specific hooks can be overwritten by the site
load_site_specific_hooks()
"""

def error(msg):
Expand Down

0 comments on commit 1eeb8ab

Please sign in to comment.