Skip to content

Commit

Permalink
Issue #665: Added getenv function for TCL modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcawood committed Aug 9, 2023
1 parent 2969c7f commit 20127d9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.new
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ Lmod 8.7+
* Update zsh and bash tab completion files
* Issue #657: Added support for "module purge" in a TCL modulefile to unload all other modules on load.
(8.7.30) * Issue #662: Fix bug where the version is very long (like git commit tags)
(8.7.31) * Issue #665: Added support for getenv function in TCL modules
10 changes: 8 additions & 2 deletions rt/tclmodules/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 shell --regression_testing --version
===========================
Modules based on Lua: Version 8.7.20 2023-03-16 11:43 -05:00
Modules based on Lua: Version 8.7.30 2023-07-21 17:13 -05:00
by Robert McLay [email protected]
===========================
step 2
Expand Down Expand Up @@ -33,7 +33,8 @@ step 6
lua ProjectDIR/src/lmod.in.lua shell --regression_testing avail
===========================
ProjectDIR/rt/tclmodules/mf
a/1.0 earlyLateOutput/2.0 (L) hide/1.0 hide/2.0 (D) showMe/1.0
a/1.0 getenv/1.0 hide/2.0 (D)
earlyLateOutput/2.0 (L) hide/1.0 showMe/1.0
Where:
D: Default Module
L: Module is loaded
Expand All @@ -42,3 +43,8 @@ If the avail list is too long consider trying:
"module overview" or "ml ov" to display the number of modules for each name.
Use "module spider" to find all possible modules and extensions.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".
===========================
step 7
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load getenv
===========================
FOUND
8 changes: 8 additions & 0 deletions rt/tclmodules/mf/getenv/1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#%Module

if { {BAR} eq [getenv FOO] } {
puts stderr "FOUND"
} else {
puts stderr "NOT FOUND"
}

12 changes: 12 additions & 0 deletions rt/tclmodules/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ MODULEPATH=ProjectDIR/rt/tclmodules/mf;
export MODULEPATH;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={earlyLateOutput={fn="ProjectDIR/rt/tclmodules/mf/earlyLateOutput/2.0",fullName="earlyLateOutput/2.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="earlyLateOutput",wV="000000002.*zfinal",},},mpathA={"ProjectDIR/rt/tclmodules/mf",},systemBaseMPATH="ProjectDIR/rt/tclmodules/mf",}';
export _ModuleTable_;
===========================
step 7
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load getenv
===========================
LOADEDMODULES=earlyLateOutput/2.0:getenv/1.0;
export LOADEDMODULES;
MODULEPATH=ProjectDIR/rt/tclmodules/mf;
export MODULEPATH;
_LMFILES_=ProjectDIR/rt/tclmodules/mf/earlyLateOutput/2.0:ProjectDIR/rt/tclmodules/mf/getenv/1.0;
export _LMFILES_;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={earlyLateOutput={fn="ProjectDIR/rt/tclmodules/mf/earlyLateOutput/2.0",fullName="earlyLateOutput/2.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="earlyLateOutput",wV="000000002.*zfinal",},getenv={fn="ProjectDIR/rt/tclmodules/mf/getenv/1.0",fullName="getenv/1.0",loadOrder=2,propT={},stackDepth=0,status="active",userName="getenv",wV="000000001.*zfinal",},},mpathA={"ProjectDIR/rt/tclmodules/mf",},systemBaseMPATH="ProjectDIR/rt/tclmodules/mf",}';
export _ModuleTable_;
3 changes: 2 additions & 1 deletion rt/tclmodules/tclmodules.tdesc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ testdescript = {
unsetMT
initStdEnvVars
export MODULEPATH=$(testDir)/mf
export FOO=BAR
rm -fr _stderr.* _stdout.* err.* out.* .lmod.d .cache .config
Expand All @@ -29,7 +30,7 @@ testdescript = {
runLmod list # 4
runLmod show showMe # 5
runLmod avail # 6
runLmod load getenv # 7
HOME=$ORIG_HOME
cat _stdout.[0-9][0-9][0-9] > _stdout.orig
Expand Down
18 changes: 17 additions & 1 deletion src/tcl2lua.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ proc setenv { var val args } {
cmdargs "setenv" $var $val
}

proc getenv { var args } {
cmdargs "os.getenv" $var
}

proc unsetenv { var {val {}}} {
global env g_varsT
set mode [currentMode]
Expand Down Expand Up @@ -996,9 +1000,10 @@ proc execute-modulefile {modfile } {
interp alias $child complete {} complete
interp alias $child conflict {} conflict
interp alias $child depends-on {} depends-on
interp alias $child exit {} my_exit
interp alias $child exit {} my_exit
interp alias $child extensions {} extensions
interp alias $child family {} family
interp alias $child getenv {} getenv
interp alias $child haveDynamicMPATH {} haveDynamicMPATH
interp alias $child initGA {} initGA
interp alias $child is-loaded {} is-loaded
Expand Down Expand Up @@ -1077,13 +1082,24 @@ proc execute-modulefile {modfile } {
return $errorVal
}

proc getenv {var} {

global env
set v ""
if {[info exists env($var)]} {
set v $env($var)
}
return $v
}

proc unset-env {var} {
global env

if {[info exists env($var)]} {
unset env($var)
}
}

proc set-env {var value} {
global g_envT g_envClrT env
# If setting a var not seen then mark it for deletion when reset is called.
Expand Down

0 comments on commit 20127d9

Please sign in to comment.