Skip to content

Commit ded0b4e

Browse files
committed
Get correct tags for mod having same name than a loaded mod
Ensure that a module having the same name than a loaded module from another modulepath will not inherit the tags of this loaded module. Split collectModuleTags procedure to have a getMatchingTagList procedure that gets the tags applying to a module. Use this procedure in getTagList instead of the g_tagHash structure to avoid the tags only applying to the loaded module if we are not checking this modulefile. Fixes #599 Signed-off-by: Xavier Delaruelle <[email protected]>
1 parent d5ce06e commit ded0b4e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

NEWS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Modules 5.6.1 (not yet released)
3131
:mfcmd:`prepend-path`, :mfcmd:`append-path` or :mfcmd:`remove-path`
3232
modulefile commands. (fix issue #597)
3333
* Doc: add way to build latexpdf documentation.
34+
* Ensure that a module having the same name than a loaded module from
35+
another modulepath does not inherit its tags. (fix issue #599)
3436

3537
.. _Furo: https://github.com/pradyunsg/furo
3638

tcl/modfind.tcl.in

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,24 +646,38 @@ proc getModuleTagProp {mod fpmod tag prop} {
646646

647647
# Gather all tags applying to a given module
648648
proc collectModuleTags {mod} {
649+
if {[info exists ::g_tagHash($mod)]} {
650+
set known_tag_list $::g_tagHash($mod)
651+
} else {
652+
set known_tag_list {}
653+
}
654+
set tag_list [getMatchingTagList $mod $known_tag_list]
655+
if {[llength $tag_list]} {
656+
setModuleTag $mod {*}$tag_list
657+
}
658+
}
659+
660+
proc getMatchingTagList {mod {known_tag_list {}}} {
661+
set tag_list {}
649662
set modroot [getModuleRootFromVersSpec $mod]
650663
# look if mod matches one of the module specs applying to mod root
651664
if {[info exists ::g_moduleTagRoot($modroot)]} {
652665
for {set i 0} {$i < [llength $::g_moduleTagRoot($modroot)]} {incr i} {
653666
set tag [lindex $::g_moduleTagRoot($modroot) $i]
654-
# skip already known tag
655-
if {![info exists ::g_tagHash($mod)] || $tag ni $::g_tagHash($mod)} {
667+
if {$tag ni $tag_list} {
656668
foreach {tmodspec tprops} [lindex\
657669
$::g_moduleTagRootSpec($modroot) $i] {
658670
# add tag if one modspec matches mod
659671
if {[modEq $tmodspec $mod eqstart 1 0 1]} {
660-
setModuleTag $mod $tag
672+
lappend known_tag_list $tag
673+
lappend tag_list $tag
661674
break
662675
}
663676
}
664677
}
665678
}
666679
}
680+
return $tag_list
667681
}
668682

669683
proc setModuleTag {mod args} {
@@ -730,8 +744,16 @@ proc getTagList {mod {fpmod {}} {sort 1}} {
730744
if {$fpmod ne {} && [info exists ::g_moduleTagFullPath($fpmod)]} {
731745
appendNoDupToList tag_list {*}$::g_moduleTagFullPath($fpmod)
732746
}
747+
# recompute tags applying from module specification if mod is loaded but
748+
# not the same modulefile. tags applying to loaded mod are recorded in
749+
# g_tagHash but should not apply to same mod from a different modulepath
750+
# do not make this distinction if modulefile is not provided
751+
# directly check on g_loadedModules array to avoid triggering env check
752+
if {[string length $fpmod] && [info exists ::g_loadedModules($mod)] &&\
753+
$fpmod ne [getModulefileFromLoadedModule $mod]} {
754+
appendNoDupToList tag_list {*}[getMatchingTagList $mod]
733755
# get collected tags applied on short designation
734-
if {[info exists ::g_tagHash($mod)]} {
756+
} elseif {[info exists ::g_tagHash($mod)]} {
735757
appendNoDupToList tag_list {*}$::g_tagHash($mod)
736758
}
737759
if {[llength $tag_list]} {

0 commit comments

Comments
 (0)