Skip to content

Conversation

@gsell
Copy link

@gsell gsell commented Oct 29, 2025

Changes implemented in this PR:

  • add config option lmod_path_rules
  • if lmod_path_rules is set: append/prepend dir to path and remove all other occurrences of dir from path

Copy link
Collaborator

@xdelaruelle xdelaruelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your contribution. In addition to the code feedback:

  • We should find a better name for the option. It should not relate to an external software (that could change its name or behavior over the time) and it should concisely express what it does for users to easily get it

  • This option should apply to any kind of path element addition. So module use is also concerned. I have quickly looked at the code base and it seems that adding code to add-path procedure will cover any kind of path element addition.

  • The Add new configuration option document will guide you over all the things to adapt to introduce a new config option

} else {
set val $dir
set mpath_list "[lsearch -inline -all -not -exact\
$mpath_list $dir] $dir"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent does not seem correct (4 spaces instead of 3)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still fighting with the Emacs config for the Tcl-Mode. Setting tcl-continued-indent-level to 3 doesn't work as expected. Example:

            set mpath_list [lsearch -inline -all -not -exact\
                               $mpath_list $dir]

Do you have an idea how I can fix this in Emacs?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not an Emacs user so I cannot help here unfortunately.

set mpath_list [split $val $separator]
foreach dir $path_list {
if {$bhv eq {prepend}} {
set mpath_list "$dir [lsearch -inline -all -not -exact\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend having the path removal command separated, as it is the same whether we append or we prepend.

}
}
}
if {[info exists countarr($dir)]} {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code to be added should be placed under this if branch instead of duplicating the whole foreach loop. this way --duplicates and --ignore-refcount are already handled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the revised code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think code addition would be better located within the if {[info exists countarr($dir)]} { code block as there would be no need to handle duplicates, ignore-refcount mode and also no need to have specific code to increase or not the reference counter.

There would be a small duplication of code to add the path entry into the variable value, but everything else will be already managed.

# Local Variables:
# Mode: tcl-mode
# tcl-indent-level: 3
# End:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why changing the whole syntax instead of just adding the indent directive using the existing syntax?

set mpath_list [split $val $separator]
foreach dir $path_list {
if {$bhv eq {prepend}} {
set mpath_list "$dir [lsearch -inline -all -not -exact\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be interesting to have a code comment about the design decision: if the path element is found multiple times, all these entries are replaced by a single occurrence at the beginning or at the end

# ;;; tcl-indent-level: 3
# ;;; tcl-continued-indent-level: 3
# ;;; indent-tabs-mode: nil
# ;;; End:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emacs is not happy with the trailing ***, so I removed them. tcl-continued-indent-level still doesn't work for me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that tcl-continued-indent-level do not do we need here but it is ok as this situation does not occur too often.

configure Outdated
extendeddefault moduleshome initconfin pager pageropts verbosity color \
darkbgcolors lightbgcolors termbg lockedconfigs icase unloadmatchorder \
searchmatch modulepath loadedmodules quarantinevars wa277 advversspec ml \
searchmatch modulepath loadedmodules quarantinevars wa277 lmodpath advversspec ml \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to adapt the option name here

tcl/init.tcl.in Outdated
alias indesym sym tag hidden key} {} {} eltlist}\
list_terse_output {MODULES_LIST_TERSE_OUTPUT {@listterseoutput@} 0 l\
{header idx variant alias indesym sym tag hidden key} {} {} eltlist}\
path_entry_reorder {MODULES_PATH_ENTRY_REORDER 1 0 b {0 1}}\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @pathentryreorder@ as default value for option

}
}
}
if {[info exists countarr($dir)]} {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think code addition would be better located within the if {[info exists countarr($dir)]} { code block as there would be no need to handle duplicates, ignore-refcount mode and also no need to have specific code to increase or not the reference counter.

There would be a small duplication of code to add the path entry into the variable value, but everything else will be already managed.

configure Outdated
pythonbin=$(get_package_value "$arg") ;;
--with-module-path=*)
echo_warning "Option \`--with-module-path' ignored, use \`--modulepath' instead" ;;
--enable-path-entry-reorder|--disable-path-entry-reorder)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the * character after --enable-path-entry-reorder is missing (to handle --enable-path-entry-reorder=no syntax).

best is to move this code to handle an --enable option next to other option of this kind.

}
} else {
set countarr($dir) 1
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a bit confused/unsure about the reference counter countarr($dir). If path_entry_reorder is true, are there cases where countarr($dir) is not equal to 1? If it is always 1, the current solution might be the best in terms of readability.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be greater than one (for instance if two loaded modules add the same path entry)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but if path_entry_reorder is true, all occurrences of $dir are removed and exactly one is added again. Looks like I still don't understand the code. :( Maybe an example would help.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

countarr is the reference counter of each entry (how many loaded modules set this entry). It helps when unloading a module to determine if the path entry should be kept (if it is used by other loaded modules) or not.

reference counter should behave the same whether path_entry_reorder is set or not. These 2 concepts are not linked.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hesitate to tell me if it is still not clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants