Skip to content

Commit ed6c2b7

Browse files
author
Robert McLay
committed
Modifying add_to_module to become decorate_module and adding test
1 parent 70f2c27 commit ed6c2b7

File tree

10 files changed

+71
-6
lines changed

10 files changed

+71
-6
lines changed

docs/source/025_new.rst

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
New Features in Lmod
22
====================
33

4+
**decorate_module**:
5+
(Lmod 8.7.59+) Sites can use this new hook to add text to a
6+
modulefile. Note that if this hook exists all modules will call this
7+
hook, so sites will typically only want to text to certain modules.
8+
Also this added text must be written in Lua. TCL modulefiles will
9+
have already been converted to Lua.
10+
11+
412
**LMOD_FILE_IGNORE_PATTERNS**
513
(Lmod 8.7.56+) Sites can replace the default value with their own
614
list of file patterns to ignore.

docs/source/170_hooks.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ used in the Lmod program.
178178
property table. See *rt/uitSitePkg/mf/site_scripts/SitePackage.lua*
179179
for a complete example.
180180

181-
**add_to_module** (table):
181+
**decorate_module** (table):
182182
(Returns: table)
183183
This hook allows a site to add contents to a module file (e.g. add
184184
``add_property(...)`` based on the location of the module file). It
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local Hook = require("Hook")
2+
3+
function test_hook(t)
4+
if (t.name == "decorate") then
5+
return {"LmodMessage('I made it!')"}
6+
end
7+
return {}
8+
end
9+
10+
Hook.register("decorate_module", test_hook, "append")
11+

rt/hook/err.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
step 1
33
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --version
44
===========================
5-
Modules based on Lua: Version 8.7.40 2024-06-11 15:18 -06:00
5+
Modules based on Lua: Version 8.7.57 2025-02-25 17:22 -07:00
66
by Robert McLay [email protected]
77
===========================
88
step 2
@@ -36,3 +36,12 @@ Load hook B called on admin
3636
Load hook A called on admin
3737
Load hook B called on intel
3838
Load hook A called on intel
39+
===========================
40+
step 7
41+
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load A
42+
===========================
43+
===========================
44+
step 8
45+
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load decorate
46+
===========================
47+
I made it!

rt/hook/hook.tdesc

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ testdescript = {
3737
export LMOD_PACKAGE_PATH=$(testDir)/prepend
3838
runLmod load admin intel # 6
3939
40+
export LMOD_PACKAGE_PATH=$(testDir)/decorate_module;
41+
runLmod load A # 7
42+
runLmod load decorate # 8
43+
44+
45+
46+
4047
HOME=$ORIG_HOME
4148
cat _stdout.[0-9][0-9][0-9] > _stdout.orig
4249
joinBase64Results -bash _stdout.orig _stdout.new

rt/hook/mf/Core/A/1.0.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setenv("A","1")

rt/hook/mf/Core/decorate/1.0.lua

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setenv("foo","bar")

rt/hook/out.txt

+28
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,31 @@ PATH=/vol/local/intel/idb/idb/bin:/vol/local/intel/fc/fc/bin:/vol/local/intel/cc
120120
export PATH;
121121
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={compiler="intel",},mT={admin={fn="ProjectDIR/rt/hook/mf/Core/admin/admin-1.0.lua",fullName="admin/admin-1.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="admin",wV="^admin.*zfinal-.000000001.*zfinal",},intel={actionA={"prepend_path(\"MODULEPATH\",\"ProjectDIR/rt/hook/mf/Compiler/intel/10.1\")",},fn="ProjectDIR/rt/hook/mf/Core/intel/intel.lua",fullName="intel/intel",loadOrder=2,propT={},stackDepth=0,status="active",userName="intel",wV="*intel.*zfinal",},},mpathA={"ProjectDIR/rt/hook/mf/Compiler/intel/10.1","ProjectDIR/rt/hook/mf/Core",},}';
122122
export _ModuleTable_;
123+
===========================
124+
step 7
125+
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load A
126+
===========================
127+
A=1;
128+
export A;
129+
LOADEDMODULES=admin/admin-1.0:intel/intel:A/1.0;
130+
export LOADEDMODULES;
131+
MODULEPATH=ProjectDIR/rt/hook/mf/Compiler/intel/10.1:ProjectDIR/rt/hook/mf/Core;
132+
export MODULEPATH;
133+
_LMFILES_=ProjectDIR/rt/hook/mf/Core/admin/admin-1.0.lua:ProjectDIR/rt/hook/mf/Core/intel/intel.lua:ProjectDIR/rt/hook/mf/Core/A/1.0.lua;
134+
export _LMFILES_;
135+
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={compiler="intel",},mT={A={fn="ProjectDIR/rt/hook/mf/Core/A/1.0.lua",fullName="A/1.0",loadOrder=3,propT={},stackDepth=0,status="active",userName="A",wV="000000001.*zfinal",},admin={fn="ProjectDIR/rt/hook/mf/Core/admin/admin-1.0.lua",fullName="admin/admin-1.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="admin",wV="^admin.*zfinal-.000000001.*zfinal",},intel={actionA={"prepend_path(\"MODULEPATH\",\"ProjectDIR/rt/hook/mf/Compiler/intel/10.1\")",},fn="ProjectDIR/rt/hook/mf/Core/intel/intel.lua",fullName="intel/intel",loadOrder=2,propT={},stackDepth=0,status="active",userName="intel",wV="*intel.*zfinal",},},mpathA={"ProjectDIR/rt/hook/mf/Compiler/intel/10.1","ProjectDIR/rt/hook/mf/Core",},}';
136+
export _ModuleTable_;
137+
===========================
138+
step 8
139+
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load decorate
140+
===========================
141+
LOADEDMODULES=admin/admin-1.0:intel/intel:A/1.0:decorate/1.0;
142+
export LOADEDMODULES;
143+
MODULEPATH=ProjectDIR/rt/hook/mf/Compiler/intel/10.1:ProjectDIR/rt/hook/mf/Core;
144+
export MODULEPATH;
145+
_LMFILES_=ProjectDIR/rt/hook/mf/Core/admin/admin-1.0.lua:ProjectDIR/rt/hook/mf/Core/intel/intel.lua:ProjectDIR/rt/hook/mf/Core/A/1.0.lua:ProjectDIR/rt/hook/mf/Core/decorate/1.0.lua;
146+
export _LMFILES_;
147+
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={compiler="intel",},mT={A={fn="ProjectDIR/rt/hook/mf/Core/A/1.0.lua",fullName="A/1.0",loadOrder=3,propT={},stackDepth=0,status="active",userName="A",wV="000000001.*zfinal",},admin={fn="ProjectDIR/rt/hook/mf/Core/admin/admin-1.0.lua",fullName="admin/admin-1.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="admin",wV="^admin.*zfinal-.000000001.*zfinal",},decorate={fn="ProjectDIR/rt/hook/mf/Core/decorate/1.0.lua",fullName="decorate/1.0",loadOrder=4,propT={},stackDepth=0,status="active",userName="decorate",wV="000000001.*zfinal",},intel={actionA={"prepend_path(\"MODULEPATH\",\"ProjectDIR/rt/hook/mf/Compiler/intel/10.1\")",},fn="ProjectDIR/rt/hook/mf/Core/intel/intel.lua",fullName="intel/intel",loadOrder=2,propT={},stackDepth=0,status="active",userName="intel",wV="*intel.*zfinal",},},mpathA={"ProjectDIR/rt/hook/mf/Compiler/intel/10.1","ProjectDIR/rt/hook/mf/Core",},}';
148+
export _ModuleTable_;
149+
foo=bar;
150+
export foo;

src/Hook.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ local validT =
7676
reverseMapPathFilter = {}, -- This hook returns two arrays keepA, ignoreA to keep or
7777
-- ignore a path in the reverseMap mapping
7878
colorize_fullName = {}, -- Allow module avail and list to colorize name and/or version
79-
add_to_module = {}, -- Allow dynamic additions to modules. The additions are still run through the sandbox. It passes the following table as a parameter {path, name, version, contents}.
79+
decorate_module = {}, -- Allow dynamic additions to modules. The additions are still run through the sandbox.
80+
-- It passes the following table as a parameter {path, name, version, contents}.
8081
}
8182

8283
local s_actionT = { append = true, prepend = true, replace = true }

src/loadModuleFile.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ function loadModuleFile(t)
154154
end
155155

156156
-- dynamic additions via hook
157-
local additional_lines = hook.apply("add_to_module", {path=myFileName(), name=myModuleName(), version=myModuleVersion(), contents=whole}) or {}
158-
additional_lines = concatTbl(additional_lines, "\n")
159-
whole = whole .. "\n" .. additional_lines
157+
local additional_lines = hook.apply("decorate_module", {path=myFileName(), name=myModuleName(), version=myModuleVersion(), contents=whole}) or {}
158+
whole = whole .. "\n" .. concatTbl(additional_lines, "\n")
160159

161160
-- Use the sandbox to evaluate modulefile text.
162161
if (whole) then

0 commit comments

Comments
 (0)