mirror of
https://github.com/envmodules/modules.git
synced 2026-06-14 00:42:43 +08:00
Adapt version modulefile, which is deployed in versioning installation mode, to re-initialize module command during its unload, to restore the command of the previously loaded version. Goes through a full re-initialization to overcome incompatible definition of the module command between version 3 and 4. This full re-initialization cannot be attempted on scripting shells, like Perl or Python, as function re-definition is not a common practice on these languages.
72 lines
2.4 KiB
Plaintext
72 lines
2.4 KiB
Plaintext
#%Module1.0#####################################################################
|
|
##
|
|
## version modulefile
|
|
##
|
|
proc ModulesHelp { } {
|
|
global version
|
|
|
|
puts stderr "\tInitializes new version of the module command"
|
|
puts stderr "\n\tVersion $version\n"
|
|
}
|
|
|
|
module-whatis "Initializes new version of the module command"
|
|
|
|
# for Tcl script use only
|
|
set version @VERSION@
|
|
|
|
if [ expr [ module-info mode load ] || [ module-info mode display ] ] {
|
|
# get rid of old version
|
|
module unload null
|
|
module unload modules
|
|
setenv MODULE_VERSION @VERSION@
|
|
}
|
|
|
|
# version stack
|
|
prepend-path MODULE_VERSION_STACK @VERSION@
|
|
|
|
if [ module-info mode remove ] {
|
|
# unload modules modulefile to get PATHs refreshed after previous module
|
|
# command restoration
|
|
module load modules
|
|
set prevversion [lindex [split $env(MODULE_VERSION_STACK) : ] 0 ]
|
|
unsetenv MODULE_VERSION $prevversion
|
|
|
|
# re-initialize previous module command version by sourcing its
|
|
# initialization script, as module function definition is not compatible
|
|
# between Modules 3 and Modules 4
|
|
set shell [module-info shell]
|
|
switch -- $shell {
|
|
{sh} - {bash} - {ksh} - {zsh} - {csh} - {tcsh} - {fish} {
|
|
set versionre [regsub -all "\(\[.+?\]\)" $version {\\\1}]
|
|
regsub $versionre "@initdir@/$shell" $prevversion previnitshell
|
|
if {[file exists $previnitshell]} {
|
|
switch -- $shell {
|
|
{sh} - {bash} - {ksh} - {zsh} {
|
|
set sourcecmd "."
|
|
}
|
|
{csh} - {tcsh} - {fish} {
|
|
set sourcecmd "source"
|
|
}
|
|
}
|
|
puts stdout "$sourcecmd $previnitshell"
|
|
puts stdout "module load modules"
|
|
} else {
|
|
puts stderr "No initialization script for '$shell' on version '$prevversion'"
|
|
}
|
|
}
|
|
default {
|
|
# no support for re-initializing module command on scripting shell
|
|
# as it is not a common practice for most of these languages to
|
|
# redefine an already set function
|
|
puts stderr "No re-initialization supported for '$shell' on version '$prevversion'"
|
|
}
|
|
}
|
|
}
|
|
|
|
if [ expr [ module-info mode load ] || [ module-info mode display ] ] {
|
|
# bring in new version
|
|
module load modules
|
|
puts stdout [exec @TCLSH@ @libexecdir@/modulecmd.tcl [module-info shell] autoinit]
|
|
}
|
|
|