Skip to content

Commit 55f89e3

Browse files
committed
Make "getenv" available from modulerc eval context
Fixes #588 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
1 parent bfb32ec commit 55f89e3

6 files changed

Lines changed: 48 additions & 17 deletions

File tree

NEWS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Modules 5.7.0 (not yet released)
4848
* Install: reorder the options in the :file:`configure` script help message
4949
alphabetically.
5050
* Doc: add manual page for :ref:`modulecmd(1)` command.
51+
* Make :mfcmd:`getenv` modulefile command available from module rc file
52+
evaluation context. (fix issue #588)
5153

5254

5355
.. _5.6 release notes:

doc/source/changes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,9 @@ The following modulefile Tcl commands appeared on Modules 5.
11111111
environment variable value or its fallback when modulefile is evaluated in
11121112
*display* mode.
11131113

1114+
Starting version 5.7, this command is also available from module rc file
1115+
context.
1116+
11141117
:mfcmd:`prereq`, :mfcmd:`module load/try-load/load-any/switch<module>`
11151118

11161119
Starting Modules 5.1, these modulefile commands accept the :option:`--tag`

doc/source/modulefile.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ the *modulefile* is being loaded.
343343
.. versionchanged:: 5.1
344344
Option ``--return-value`` added
345345

346+
.. versionchanged:: 5.7
347+
Command available from module rc file context
348+
346349
.. mfcmd:: getvariant [--return-value] variant [value]
347350

348351
Returns value of designated *variant*. If *variant* is not defined, *value*
@@ -1772,15 +1775,16 @@ for each interpretation context.
17721775
| Commands available from | Commands available from run-command (rc) file |
17731776
| modulefile interpretation | interpretation |
17741777
+===========================+=====================================================+
1775-
| All the Modules specific | :mfcmd:`hide-modulefile`, :mfcmd:`hide-version`, |
1776-
| and standard Tcl commands | :mfcmd:`is-loaded`, :mfcmd:`is-used`, |
1777-
| | :mfcmd:`lsb-release`, :mfcmd:`module-alias`, |
1778-
| | :mfcmd:`module-forbid`, :mfcmd:`module-hide`, |
1779-
| | :mfcmd:`module-info`, :mfcmd:`module-tag`, |
1780-
| | :mfcmd:`module-version`, :mfcmd:`module-virtual`, |
1781-
| | :mfcmd:`module-warn`, :mfcmd:`modulepath-label`, |
1782-
| | :mfcmd:`system`, :mfcmd:`uname`, |
1783-
| | :mfcmd:`versioncmp` and standard Tcl commands |
1778+
| All the Modules specific | :mfcmd:`getenv`, :mfcmd:`hide-modulefile`, |
1779+
| and standard Tcl commands | :mfcmd:`hide-version`, :mfcmd:`is-loaded`, |
1780+
| | :mfcmd:`is-used`, :mfcmd:`lsb-release`, |
1781+
| | :mfcmd:`module-alias`, :mfcmd:`module-forbid`, |
1782+
| | :mfcmd:`module-hide`, :mfcmd:`module-info`, |
1783+
| | :mfcmd:`module-tag`, :mfcmd:`module-version`, |
1784+
| | :mfcmd:`module-virtual`, :mfcmd:`module-warn`, |
1785+
| | :mfcmd:`modulepath-label`, :mfcmd:`system`, |
1786+
| | :mfcmd:`uname`, :mfcmd:`versioncmp` and standard |
1787+
| | Tcl commands |
17841788
+---------------------------+-----------------------------------------------------+
17851789

17861790
.. note:: Global and user run-command files are interpreted like modulefiles

tcl/interp.tcl.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,14 @@ proc execute-modulerc {modfile modname modspec} {
522522

523523
# list interpreter alias commands to define
524524
array set ::g_modrcAliases [list uname uname system system versioncmp\
525-
versioncmp hide-modulefile hide-modulefile hide-version\
526-
hide-modulefile is-loaded is-loaded is-used is-used module-version\
527-
module-version module-alias module-alias module-virtual\
528-
module-virtual module-forbid module-forbid module-hide module-hide\
529-
module-tag module-tag module-info module-info modulepath-label\
530-
modulepath-label setModulesVersion setModulesVersion\
531-
getModuleContent getModuleContent lsb-release lsb-release\
532-
module-warn module-warn]
525+
versioncmp getenv getenv hide-modulefile hide-modulefile\
526+
hide-version hide-modulefile is-loaded is-loaded is-used is-used\
527+
module-version module-version module-alias module-alias\
528+
module-virtual module-virtual module-forbid module-forbid\
529+
module-hide module-hide module-tag module-tag module-info\
530+
module-info modulepath-label modulepath-label setModulesVersion\
531+
setModulesVersion getModuleContent getModuleContent lsb-release\
532+
lsb-release module-warn module-warn]
533533

534534
if {[getConf source_cache]} {
535535
set ::g_modrcAliases(source) sourceModfileCmd

testsuite/modulefiles.4/foo/.modulerc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ if {[info exists env(TESTSUITE_CONFLICT_UNLOAD)]} {
2323
}
2424
}
2525
}
26+
if {[info exists env(TESTSUITE_RC_GETENV)]} {
27+
switch -- $env(TESTSUITE_RC_GETENV) {
28+
sym {
29+
module-version foo/1.0 [getenv TESTSUITE_RC_GETENV]
30+
}
31+
unk {
32+
module-version foo/1.0 [getenv UNK_VAR foo]
33+
}
34+
}
35+
}

testsuite/modules.50-cmds/260-getenv.exp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ $modlin"
184184
testouterr_cmd_re sh "display $module" OK $tserr
185185

186186

187+
# test usage from rc file
188+
setenv_var MODULES_SEARCH_MATCH starts_with
189+
setenv_var MODULEPATH $modpath.4
190+
setenv_var TESTSUITE_RC_GETENV sym
191+
set tserr {foo/1.0(sym) }
192+
testouterr_cmd sh {avail -o sym foo/1.0} OK $tserr
193+
194+
setenv_var TESTSUITE_RC_GETENV unk
195+
set tserr {foo/1.0(foo) }
196+
testouterr_cmd sh {avail -o sym foo/1.0} OK $tserr
197+
198+
187199
#
188200
# Cleanup
189201
#

0 commit comments

Comments
 (0)