Skip to content

Commit 22edddf

Browse files
committed
Check if mod is already loaded before looking at avails
When trying to load a module, first look into already loaded modules and their alternative names prior resolving available modules. Only take into account the loaded module that exactly matches the module specification passed to cmdModuleLoad. Which means that partial start match, version range or version list are not taken into account (to be able to resolve to the default from these kind of specifications). Fixes #602 Signed-off-by: Xavier Delaruelle <[email protected]>
1 parent 28d8a25 commit 22edddf

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

NEWS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Modules 5.6.1 (not yet released)
3939
* Always apply *abort on error* behavior in case a Dependent Reload sticky
4040
(and :option:`--force` is not set) or super-sticky module fails to reload.
4141
(fix issue #601)
42+
* When loading a module, check already loaded modules and their aliases
43+
exactly matching specification before looking at available modules and their
44+
aliases. (fix issue #602)
4245

4346
.. _Furo: https://github.com/pradyunsg/furo
4447

tcl/modfind.tcl.in

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,11 @@ proc getPathToModule {mod {indir {}} {report_issue 1} {look_loaded no}\
11951195
# or to find a closest match (used when switching with single name arg)
11961196
} elseif {$look_loaded ne {no}} {
11971197
switch -- $look_loaded {
1198-
match {set getLoadedNameProc getLoadedMatchingName}
1198+
exact {set getLoadedNameProc getLoadedExactName}
1199+
match {set getLoadedNameProc getLoadedEqstartName}
11991200
close {set getLoadedNameProc getLoadedWithClosestName}
12001201
}
1201-
if {[set lm [$getLoadedNameProc $mod]] ne {}} {
1202+
if {[set lm [$getLoadedNameProc $mod $indir]] ne {}} {
12021203
set vrlist [getVariantList $lm 1]
12031204
set retlist [list [getModulefileFromLoadedModule $lm] $lm]
12041205
} else {
@@ -1436,7 +1437,7 @@ proc unsetLoadedModule {mod modfile} {
14361437
# return the currently loaded module whose name is the closest to the
14371438
# name passed as argument. if no loaded module match at least one part
14381439
# of the passed name, an empty string is returned.
1439-
proc getLoadedWithClosestName {name} {
1440+
proc getLoadedWithClosestName {name modulepath_list} {
14401441
set ret {}
14411442
set retmax 1
14421443

@@ -1497,12 +1498,20 @@ proc getLoadedWithClosestName {name} {
14971498
return $ret
14981499
}
14991500

1501+
proc getLoadedExactName {name modulepath_list} {
1502+
return [getLoadedMatchingName $name {} 0 {} $modulepath_list eqspec]
1503+
}
1504+
1505+
proc getLoadedEqstartName {name modulepath_list} {
1506+
return [getLoadedMatchingName $name {} 0 {} $modulepath_list]
1507+
}
1508+
15001509
# return the currently loaded module whose name is equal or include the name
15011510
# passed as argument. if no loaded module match, an empty string is returned.
15021511
# loading: look at currently loading modules instead of loaded if loading == 1
15031512
# lmlist: only take into account passed loaded module list not all loaded mods
15041513
proc getLoadedMatchingName {name {behavior {}} {loading 0} {lmlist {}}\
1505-
{modulepath_list {}}} {
1514+
{modulepath_list {}} {eqtest eqstart}} {
15061515
set ret {}
15071516
set retmax 0
15081517
# get default behavior from unload_match_order config
@@ -1569,7 +1578,7 @@ proc getLoadedMatchingName {name {behavior {}} {loading 0} {lmlist {}}\
15691578
if {![$isLoadedMatchSpecificPath $mod $modulepath_list]} {
15701579
continue
15711580
}
1572-
if {[modEq $name $matchmod eqstart 1 [expr {$loading ? 1 : 2}] 1]} {
1581+
if {[modEq $name $matchmod $eqtest 1 [expr {$loading ? 1 : 2}] 1]} {
15731582
switch -- $behavior {
15741583
returnlast {
15751584
# the last loaded module will be returned

tcl/modspec.tcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,13 @@ proc getModuleNameFromVersSpec {modarg} {
16901690
}
16911691
}
16921692

1693+
proc getCmpSpecFromVersSpec {modarg} {
1694+
if {[info exists ::g_moduleVersSpec($modarg)]} {
1695+
return [lindex $::g_moduleVersSpec($modarg) 2]
1696+
} else {
1697+
return eq
1698+
}
1699+
}
16931700
# get module root name from module name and version spec if parsed
16941701
proc getModuleRootFromVersSpec {modarg} {
16951702
if {[info exists ::g_moduleVersSpec($modarg)]} {

tcl/subcmd.tcl.in

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,17 @@ proc cmdModuleLoad {context uasked tryload loadany tag_list modulepath_list\
11141114
# error if module not found or forbidden
11151115
set notfounderr [expr {!$tryload}]
11161116

1117-
lassign [getPathToModule $mod $modulepath_list $notfounderr] modfile\
1118-
modname modnamevr
1117+
# first try to resolve over loaded mods unless spec corresponds to
1118+
# multiple module designations, otherwise search avail mods
1119+
unset -nocomplain modfile
1120+
if {[getCmpSpecFromVersSpec $mod] eq {eq}} {
1121+
lassign [getPathToModule $mod $modulepath_list 0 exact] modfile\
1122+
modname modnamevr
1123+
}
1124+
if {![info exists modfile] || ![string length $modfile]} {
1125+
lassign [getPathToModule $mod $modulepath_list $notfounderr] modfile\
1126+
modname modnamevr
1127+
}
11191128

11201129
# record evaluation attempt on specified module name
11211130
registerModuleEvalAttempt $context $mod $modfile

0 commit comments

Comments
 (0)