diff --git a/doc/source/module.rst b/doc/source/module.rst index 130cdbb2..d686322e 100644 --- a/doc/source/module.rst +++ b/doc/source/module.rst @@ -162,7 +162,7 @@ switches are accepted: **--default**, **-d** On **avail** sub-command, display only the default version of each module - name. Default version is either the explicitely set default version or + name. Default version is either the explicitly set default version or the highest numerically sorted *modulefile* if no default version set (see Locating Modulefiles section in the :ref:`modulefile(4)` man page). @@ -327,6 +327,11 @@ Module Sub-Commands If **MODULES_COLLECTION_TARGET** is set, a suffix equivalent to the value of this variable will be appended to the *collection* file name. + By default, if loaded modulefile corresponds to the default module version, + the bare module name is recorded. If **MODULES_COLLECTION_PIN_VERSION** is + set to **1**, module version is always recorded even if it is the default + version. + **restore** [collection] Restore the environment state as defined in *collection*. If *collection* @@ -547,6 +552,12 @@ ENVIRONMENT command initialization scripts, the executable program **modulecmd.tcl**, and a directory containing a collection of master *modulefiles*. +**MODULES_COLLECTION_PIN_VERSION** + + If set to **1**, register exact version number of modulefiles when saving a + collection. Elsewhere modulefile version number is omitted if it corresponds + to the implicit or explicitly set default version. + **MODULES_COLLECTION_TARGET** The collection target that determines what collections are valid thus diff --git a/modulecmd.tcl.in b/modulecmd.tcl.in index 7605327c..289f9343 100755 --- a/modulecmd.tcl.in +++ b/modulecmd.tcl.in @@ -4566,6 +4566,18 @@ proc getCollectionTarget {} { } } +# should modulefile version be pinned when saving collection? +proc pinVersionInCollection {} { + global env + + if {[info exists env(MODULES_COLLECTION_PIN_VERSION)] &&\ + $env(MODULES_COLLECTION_PIN_VERSION) eq "1"} { + return 1 + } else { + return 0 + } +} + # return saved collections found in user directory which corresponds to # enabled collection target if any set. proc findCollections {} { @@ -5023,9 +5035,14 @@ proc cmdModuleSave {{coll {}}} { } reportDebug "cmdModuleSave: $coll" - # format collection content - set save [formatCollectionContent [getModulePathList] \ - [getSimplifiedLoadedModuleList]] + # format collection content, version number of modulefile are saved if + # version pinning is enabled + if {[pinVersionInCollection]} { + set curr_mod_list [getLoadedModuleList] + } else { + set curr_mod_list [getSimplifiedLoadedModuleList] + } + set save [formatCollectionContent [getModulePathList] $curr_mod_list] if { [string length $save] == 0} { reportErrorAndExit "Nothing to save in a collection" @@ -5087,6 +5104,13 @@ proc cmdModuleRestore {{coll {}}} { # from current situation with preservation of the load order lassign [getMovementBetweenList $curr_mod_list $coll_mod_list] \ mod_to_unload mod_to_load + # determine unload movement with raw loaded list in case versions are + # pinning in saved collection + lassign [getMovementBetweenList $curr_mod_list_raw $coll_mod_list] \ + mod_to_unload_raw mod_to_load_raw + if {[llength $mod_to_unload] > [llength $mod_to_unload_raw]} { + set mod_to_unload $mod_to_unload_raw + } # proceed as well for modulepath lassign [getMovementBetweenList $curr_path_list $coll_path_list] \ @@ -5115,11 +5139,19 @@ proc cmdModuleRestore {{coll {}}} { # before starting to unload modules set curr_mod_list [getSimplifiedLoadedModuleList\ $curr_mod_list_raw $curr_mod_list] + set curr_mod_list_raw [getLoadedModuleList] # determine what module to load to restore collection # from current situation with preservation of the load order lassign [getMovementBetweenList $curr_mod_list $coll_mod_list] \ mod_to_unload mod_to_load + # determine load movement with raw loaded list in case versions are + # pinning in saved collection + lassign [getMovementBetweenList $curr_mod_list_raw $coll_mod_list] \ + mod_to_unload_raw mod_to_load_raw + if {[llength $mod_to_load] > [llength $mod_to_load_raw]} { + set mod_to_load $mod_to_load_raw + } # proceed as well for modulepath lassign [getMovementBetweenList $curr_path_list $coll_path_list] \