Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new 'add_to_module' hook. #738

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions docs/source/170_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ used in the Lmod program.
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.

**add_to_module** (table):
(Returns: table)
This hook allows a site to add contents to a module file (e.g. add
``add_property(...)`` based on the location of the module file). It
provides a table ``{path, name, version, contents}`` as a parameter and
should return an indexed table of strings to add to the module file as lines.


Example Hook: msgHook
Expand Down
1 change: 1 addition & 0 deletions src/Hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local validT =
reverseMapPathFilter = {}, -- This hook returns two arrays keepA, ignoreA to keep or
-- ignore a path in the reverseMap mapping
colorize_fullName = {}, -- Allow module avail and list to colorize name and/or version
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}.
}

local s_actionT = { append = true, prepend = true, replace = true }
Expand Down
6 changes: 6 additions & 0 deletions src/loadModuleFile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require("fileOps")
require("sandbox")
require("string_utils")
require("utils")
local hook = require("Hook")
local dbg = require("Dbg"):dbg()
local concatTbl = table.concat
local getenv = os.getenv
Expand Down Expand Up @@ -152,6 +153,11 @@ function loadModuleFile(t)
end
end

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

-- Use the sandbox to evaluate modulefile text.
if (whole) then
status, msg = sandbox_run(whole)
Expand Down
Loading