Skip to content

Commit

Permalink
issue #382: Support a hook so that sites can add decoration to spider…
Browse files Browse the repository at this point in the history
… level 1 output
  • Loading branch information
Robert McLay committed May 10, 2019
1 parent d6605db commit 4e32f54
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 36 deletions.
3 changes: 2 additions & 1 deletion README.new
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Lmod 8.1+
(8.1.1) * Issue #392: include family info in spiderT and all other products based on spiderT like
dbT and the software page.

(8.1.2) * Issue #382: Adding a spider_decoration hook so that sites can modify the output of spider
level 1 output.
7 changes: 7 additions & 0 deletions docs/source/170_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ Hook functions
argument is a table containing: fullName, sn (short name), fn (file path) and
isVisible (boolean) of the module.

**spider_decoration** (table):
This hook provide a way for a site to add decoration to spider level
1 output. The table passed in contains the whatis category and the
property table. See *rt/uitSitePkg/mf/site_scripts/SitePackage.lua*
for a complete example.


Example Hook: msgHook
---------------------

Expand Down
21 changes: 19 additions & 2 deletions rt/softwarePage/err.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
step 1
lua ProjectDIR/src/lmod.in.lua bash --regression_testing --version
===========================
Modules based on Lua: Version 8.1 2019-05-07 15:35 -05:00
Modules based on Lua: Version 8.1.1 2019-05-10 11:12 -05:00
by Robert McLay [email protected]
===========================
step 2
lua ProjectDIR/src/lmod.in.lua bash --regression_testing avail
===========================
ProjectDIR/rt/softwarePage/mf
foo/1.0 foo/1.1 (D) foo/1.3
foo/1.0 (g) foo/1.1 (m,D) foo/1.3 (T)
Where:
D: Default Module
T: Testing
g: built for GPU
m: built for host and native MIC
Use "module spider" to find all possible modules.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".
===========================
Expand All @@ -26,3 +29,17 @@ runSpiderCmd -o dbT ProjectDIR/rt/softwarePage/mf
step 5
runSpiderCmd -o softwarePageLua ProjectDIR/rt/softwarePage/mf
===========================
===========================
step 6
lua ProjectDIR/src/lmod.in.lua bash --regression_testing spider foo
===========================
foo:
Description:
This is a descript
Versions:
foo/1.0
foo/1.1
foo/1.3
For detailed information about a specific "foo" module (including how to load the modules) use the module's full name.
For example:
$ module spider foo/1.3
2 changes: 1 addition & 1 deletion rt/softwarePage/mf/foo/.2.0.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
help([[foo v.2.0]])
whatis("Description: foo description")
whatis("Version: 1.0")
whatis("Categories: foo")
whatis("Category: foo")
family("bar")
3 changes: 2 additions & 1 deletion rt/softwarePage/mf/foo/1.0.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
help([[foo v1.0]])
whatis("Description: foo description")
whatis("Version: 1.0")
whatis("Categories: foo")
whatis("Category: foo")
family("bar")
add_property("arch","gpu")
3 changes: 2 additions & 1 deletion rt/softwarePage/mf/foo/1.1.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
help([[foo v1.1]])
whatis("Description: foo description")
whatis("Version: 1.1")
whatis("Categories: foo")
whatis("Category: foo")
family("bar")
add_property("arch","mic")
2 changes: 1 addition & 1 deletion rt/softwarePage/mf/foo/1.3
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module-whatis "Version: 1.3"
module-whatis "Category: system"
module-whatis "Description: This is a descript"
family "bar"

add-property "state" "testing"
proc ModulesHelp { } {
puts stderr "This is the help message for the foo 1.3 module"
puts stderr "And even more help"
Expand Down
53 changes: 53 additions & 0 deletions rt/softwarePage/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ spiderT = {
["luaExt"] = 4,
["mpath"] = "ProjectDIR/rt/softwarePage/mf",
["pV"] = "000000001.*zfinal",
propT = {
arch = {
["gpu"] = 1,
},
},
["wV"] = "^00000001.*zfinal",
whatis = {
"Description: foo description", "Version: 1.0", "Categories: foo",
Expand All @@ -103,6 +108,11 @@ spiderT = {
["luaExt"] = 4,
["mpath"] = "ProjectDIR/rt/softwarePage/mf",
["pV"] = "000000001.000000001.*zfinal",
propT = {
arch = {
["mic"] = 1,
},
},
["wV"] = "000000001.000000001.*zfinal",
whatis = {
"Description: foo description", "Version: 1.1", "Categories: foo",
Expand All @@ -122,6 +132,11 @@ And even more help
]],
["mpath"] = "ProjectDIR/rt/softwarePage/mf",
["pV"] = "000000001.000000003.*zfinal",
propT = {
state = {
["testing"] = 1,
},
},
["wV"] = "000000001.000000003.*zfinal",
whatis = {
"Name: foo ", "Version: 1.3 ", "Category: system ", "Description: This is a descript ",
Expand Down Expand Up @@ -184,6 +199,11 @@ dbT = {
["help"] = "foo v1.0",
["hidden"] = false,
["pV"] = "000000001.*zfinal",
propT = {
arch = {
["gpu"] = 1,
},
},
["wV"] = "^00000001.*zfinal",
whatis = {
"Description: foo description", "Version: 1.0", "Categories: foo",
Expand All @@ -197,6 +217,11 @@ dbT = {
["help"] = "foo v1.1",
["hidden"] = false,
["pV"] = "000000001.000000001.*zfinal",
propT = {
arch = {
["mic"] = 1,
},
},
["wV"] = "000000001.000000001.*zfinal",
whatis = {
"Description: foo description", "Version: 1.1", "Categories: foo",
Expand All @@ -214,6 +239,11 @@ And even more help
]],
["hidden"] = false,
["pV"] = "000000001.000000003.*zfinal",
propT = {
state = {
["testing"] = 1,
},
},
["wV"] = "000000001.000000003.*zfinal",
whatis = {
"Name: foo ", "Version: 1.3 ", "Category: system ", "Description: This is a descript ",
Expand All @@ -239,6 +269,11 @@ spA = {
["help"] = "foo v1.1",
["markedDefault"] = false,
["path"] = "ProjectDIR/rt/softwarePage/mf/foo/1.1.lua",
properties = {
arch = {
["mic"] = 1,
},
},
["versionName"] = "1.1",
["wV"] = "000000001.000000001.*zfinal",
},
Expand All @@ -253,6 +288,11 @@ And even more help
]],
["markedDefault"] = false,
["path"] = "ProjectDIR/rt/softwarePage/mf/foo/1.3",
properties = {
state = {
["testing"] = 1,
},
},
["versionName"] = "1.3 ",
["wV"] = "000000001.000000003.*zfinal",
},
Expand All @@ -264,9 +304,22 @@ And even more help
["help"] = "foo v1.0",
["markedDefault"] = true,
["path"] = "ProjectDIR/rt/softwarePage/mf/foo/1.0.lua",
properties = {
arch = {
["gpu"] = 1,
},
},
["versionName"] = "1.0",
["wV"] = "^00000001.*zfinal",
},
},
},
}
===========================
step 6
lua ProjectDIR/src/lmod.in.lua bash --regression_testing spider foo
===========================
MODULEPATH=ProjectDIR/rt/softwarePage/mf;
export MODULEPATH;
_ModuleTable_='_ModuleTable_={["MTversion"]=3,depthT={},family={},mT={},mpathA={"ProjectDIR/rt/softwarePage/mf",},["systemBaseMPATH"]="ProjectDIR/rt/softwarePage/mf",}';
export _ModuleTable_;
15 changes: 14 additions & 1 deletion rt/uitSitePkg/err.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
step 1
lua ProjectDIR/src/lmod.in.lua bash --regression_testing --version
===========================
Modules based on Lua: Version 7.7.14 2017-11-16 16:23 -07:00
Modules based on Lua: Version 8.1.1 2019-05-10 11:12 -05:00
by Robert McLay [email protected]
===========================
step 2
Expand Down Expand Up @@ -39,3 +39,16 @@ where "Foo" is the name of a module.
To find detailed information about a particular package you
must specify the version if there is more than one version:
$ module spider Foo/11.1
===========================
step 7
lua ProjectDIR/src/lmod.in.lua bash --regression_testing spider python
===========================
python:
Description:
Python with scientific packages
Versions:
python/2.7.3 (Application)
python/3.3.0 (Application)
For detailed information about a specific "python" module (including how to load the modules) use the module's full name.
For example:
$ module spider python/3.3.0
9 changes: 9 additions & 0 deletions rt/uitSitePkg/mf/site-scripts/SitePackage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
-- author: [email protected]

require("lmod_system_execute")
require("string_utils")

local Dbg = require("Dbg")
local dbg = Dbg:dbg()
local hook = require("Hook")
Expand Down Expand Up @@ -173,6 +175,13 @@ function loadPkgDefaults()
return pkg
end

function spdrDecoration(v)
local cat = (v.Category or ""):trim()
return cat
end

hook.register("spider_decoration", spdrDecoration)

sandbox_registration {
getAppRoot = getAppRoot
, loadPkgDefaults = loadPkgDefaults
Expand Down
8 changes: 8 additions & 0 deletions rt/uitSitePkg/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ MODULEPATH=ProjectDIR/rt/uitSitePkg/mf/Compiler/gcc/4.7.2:ProjectDIR/rt/uitSiteP
export MODULEPATH;
_ModuleTable_='_ModuleTable_={["MTversion"]=3,depthT={},family={["compiler"]="gcc",},mT={gcc={["fn"]="ProjectDIR/rt/uitSitePkg/mf/Core/gcc/4.7.2.lua",["fullName"]="gcc/4.7.2",["loadOrder"]=1,propT={},["stackDepth"]=0,["status"]="active",["userName"]="gcc",},python={["fn"]="ProjectDIR/rt/uitSitePkg/mf/Core/python/2.7.3.lua",["fullName"]="python/2.7.3",["loadOrder"]=2,propT={},["stackDepth"]=0,["status"]="active",["userName"]="python",},},mpathA={"ProjectDIR/rt/uitSitePkg/mf/Compiler/gcc/4.7.2","ProjectDIR/rt/uitSitePkg/mf/Core",},["systemBaseMPATH"]="ProjectDIR/rt/uitSitePkg/mf/Core",}';
export _ModuleTable_;
===========================
step 7
lua ProjectDIR/src/lmod.in.lua bash --regression_testing spider python
===========================
MODULEPATH=ProjectDIR/rt/uitSitePkg/mf/Compiler/gcc/4.7.2:ProjectDIR/rt/uitSitePkg/mf/Core;
export MODULEPATH;
_ModuleTable_='_ModuleTable_={["MTversion"]=3,depthT={},family={["compiler"]="gcc",},mT={gcc={["fn"]="ProjectDIR/rt/uitSitePkg/mf/Core/gcc/4.7.2.lua",["fullName"]="gcc/4.7.2",["loadOrder"]=1,propT={},["stackDepth"]=0,["status"]="active",["userName"]="gcc",},python={["fn"]="ProjectDIR/rt/uitSitePkg/mf/Core/python/2.7.3.lua",["fullName"]="python/2.7.3",["loadOrder"]=2,propT={},["stackDepth"]=0,["status"]="active",["userName"]="python",},},mpathA={"ProjectDIR/rt/uitSitePkg/mf/Compiler/gcc/4.7.2","ProjectDIR/rt/uitSitePkg/mf/Core",},["systemBaseMPATH"]="ProjectDIR/rt/uitSitePkg/mf/Core",}';
export _ModuleTable_;
1 change: 1 addition & 0 deletions rt/uitSitePkg/uitSitePkg.tdesc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ testdescript = {
runLmod save default # 4
runLmod restore # 5
runLmod spider # 6
runLmod spider python # 7
HOME=$ORIG_HOME
Expand Down
52 changes: 27 additions & 25 deletions src/Hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,33 @@ local M={}

local validT =
{
['load'] = false, -- This load hook is called after a
-- modulefile is loaded.
unload = false, -- This unload hook is called after a
-- modulefile is unloaded.
parse_updateFn = false, -- This hook returns the time on the
-- timestamp file.
writeCache = false, -- This hook return whether a cache
-- should be written.
SiteName = false, -- Hook to specify Site Name
-- It is used to generate family
-- prefix: site_FAMILY_
msgHook = false, -- Hook to print messages after:
-- avail, list, spider,
errWarnMsgHook = false, -- Hook to print messages after LmodError
-- LmodWarning, LmodMessage
groupName = false, -- This hook adds the arch and os name
-- to moduleT.lua to make it safe on
-- shared filesystems.
avail = false, -- Map directory names to labels
restore = false, -- This hook is run after restore operation
startup = false, -- This hook is run when Lmod is called
packagebasename = false, -- Hook to find the patterns that spider uses for reverse map
load_spider = false, -- This hook is run evaluating modules for spider/avail
listHook = false, -- This hook gets the list of active modules
isVisibleHook = false, -- Called to evalate if a module should be hidden or not
['load'] = false, -- This load hook is called after a
-- modulefile is loaded.
unload = false, -- This unload hook is called after a
-- modulefile is unloaded.
parse_updateFn = false, -- This hook returns the time on the
-- timestamp file.
writeCache = false, -- This hook return whether a cache
-- should be written.
SiteName = false, -- Hook to specify Site Name
-- It is used to generate family
-- prefix: site_FAMILY_
msgHook = false, -- Hook to print messages after:
-- avail, list, spider,
errWarnMsgHook = false, -- Hook to print messages after LmodError
-- LmodWarning, LmodMessage
groupName = false, -- This hook adds the arch and os name
-- to moduleT.lua to make it safe on
-- shared filesystems.
avail = false, -- Map directory names to labels
restore = false, -- This hook is run after restore operation
startup = false, -- This hook is run when Lmod is called
packagebasename = false, -- Hook to find the patterns that spider uses for reverse map
load_spider = false, -- This hook is run evaluating modules for spider/avail
listHook = false, -- This hook gets the list of active modules
isVisibleHook = false, -- Called to evalate if a module should be hidden or not
spider_decoration = false, -- This hook adds decoration to spider level one output.
-- It can be the category or a property.
}

--------------------------------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions src/Spider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ function M._Level1(self, dbT, possibleA, sn, key, helpFlg)
if (fullVT[kk] == nil) then
key = sn
Description = v.Description
fullVT[kk] = v.fullName
fullVT[kk] = { fullName = v.fullName, Category = v.Category, propT = v.propT }
exampleV = v.fullName
end
end
Expand All @@ -886,7 +886,7 @@ function M._Level1(self, dbT, possibleA, sn, key, helpFlg)
local ia = 0
if (masterTbl.terse) then
for k, v in pairsByKeys(fullVT) do
ia = ia + 1; a[ia] = v .. "\n"
ia = ia + 1; a[ia] = v.fullName .. "\n"
end
return concatTbl(a,"")
end
Expand All @@ -900,7 +900,10 @@ function M._Level1(self, dbT, possibleA, sn, key, helpFlg)
end
ia = ia + 1; a[ia] = i18n("m_Versions",{})
for k, v in pairsByKeys(fullVT) do
ia = ia + 1; a[ia] = " " .. v .. "\n"
local decoration = hook.apply("spider_decoration",v)
decoration = decoration and " ("..decoration..")" or ""
local str = v.fullName .. decoration
ia = ia + 1; a[ia] = " " .. str .. "\n"
end

if (next(possibleA) ~= nil) then
Expand Down

0 comments on commit 4e32f54

Please sign in to comment.