Skip to content

Commit 5ef0a94

Browse files
gsellxdelaruelle
authored andcommitted
Add path_entry_reorder configuration option
Add path_entry_reorder configuration option that controls whether or not a path-like environment variable should be updated if a path entry is already present in the variable value. If enabled, such entry is moved at the front or the back of the variable value (depending on the modulefile command used: append-path or prepend-path). This option when set matches the default behavior found on Lmod. Add path_entry_reorder configuration option to completion script. Add the --enable-path-entry-reorder configure option to choose at installation time the path_entry_reorder behavior. Default is 'n'. When configuration is modified it sets the MODULES_PATH_ENTRY_REORDER environment variable. Signed-off-by: Achim Gsell <achim.gsell@psi.ch>
1 parent a555880 commit 5ef0a94

10 files changed

Lines changed: 60 additions & 20 deletions

File tree

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ else
394394
setwa277 := 0
395395
endif
396396

397+
ifeq ($(pathentryreorder),y)
398+
setpathentryreorder := 1
399+
else
400+
setpathentryreorder := 0
401+
endif
402+
397403
ifneq ($(tcllinteropts),)
398404
tcllintercmd := $(tcllinter) $(tcllinteropts)
399405
else
@@ -442,6 +448,7 @@ sed -e 's|@prefix@|$(prefix)|g' \
442448
-e 's|@sourcecache@|$(setsourcecache)|g' \
443449
-e 's|@searchmatch@|$(searchmatch)|g' \
444450
-e 's|@wa277@|$(setwa277)|g' \
451+
-e 's|@pathentryreorder@|$(setpathentryreorder)|g' \
445452
-e 's|@icase@|$(icase)|g' \
446453
-e 's|@nearlyforbiddendays@|$(nearlyforbiddendays)|g' \
447454
-e 's|@tagabbrev@|$(tagabbrev)|g' \

Makefile.inc.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ variantshortcut := @variantshortcut@
158158
# editor
159159
editor := @editor@
160160

161+
# Lmod path order
162+
pathentryreorder := @pathentryreorder@
163+
161164
# shell completion location
162165
bashcompletiondir := @bashcompletiondir@
163166
fishcompletiondir := @fishcompletiondir@

configure

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ multilibsupport libdir64 libdir32 versioning silentshdbgsupport \
3434
setshellstartup quarantinesupport autohandling availindepth implicitdefault \
3535
extendeddefault moduleshome initconfin pager pageropts verbosity color \
3636
darkbgcolors lightbgcolors termbg lockedconfigs icase unloadmatchorder \
37-
searchmatch modulepath loadedmodules quarantinevars wa277 advversspec ml \
37+
searchmatch modulepath loadedmodules quarantinevars wa277 pathentryreorder advversspec ml \
3838
windowssupport nearlyforbiddendays implicitrequirement tagabbrev \
3939
tagcolorname mcookieversioncheck availoutput availterseoutput listoutput \
4040
listterseoutput editor variantshortcut bashcompletiondir fishcompletiondir \
@@ -79,6 +79,7 @@ extendeddefault=y
7979
advversspec=y
8080
ml=y
8181
wa277=n
82+
pathentryreorder=n
8283
loadedmodules=
8384
quarantinevars=
8485
binsearchpath=/usr/bin:/bin:/usr/local/bin
@@ -803,6 +804,9 @@ for arg in "$@"; do
803804
--enable-mcookie-version-check*|--disable-mcookie-version-check)
804805
# shellcheck disable=SC2034
805806
mcookieversioncheck=$(get_feature_value "$arg") ;;
807+
--enable-path-entry-reorder*|--disable-path-entry-reorder)
808+
# shellcheck disable=SC2034
809+
pathentryreorder=$(get_feature_value "$arg") ;;
806810
--with-bin-search-path=*|--without-bin-search-path)
807811
binsearchpath=$(get_package_value "$arg") ;;
808812
--with-moduleshome=*|--without-moduleshome)

init/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ comp_lint_opts := -a -i --all --icase
136136
comp_modtosh_opts := --auto --no-auto --force -f --icase -i
137137
comp_path_opts := -d --delim --duplicates
138138
comp_rm_path_opts := -d --delim --index
139-
comp_config_opts := --dump-state --reset abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277
139+
comp_config_opts := --dump-state --reset abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager path_entry_reorder protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277
140140

141141
define translate-in-script
142142
$(ECHO_GEN)
@@ -167,6 +167,7 @@ sed -e 's|@prefix@|$(prefix)|g' \
167167
-e 's|@comp_path_opts@|$(comp_path_opts)|g' \
168168
-e 's|@comp_rm_path_opts@|$(comp_rm_path_opts)|g' \
169169
-e 's|@comp_config_opts@|$(comp_config_opts)|g' \
170+
-e 's|@comp_path_entry_reorder@|$(comp_path_entry_reorder)|g' \
170171
-e '$(setzshfpathre)' \
171172
-e $$'s|@modulerc@|$(modulerc)|g' \
172173
-e 's|@modulepath@|$(modulepath)|g' \

init/fish_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ complete -c module -n '__fish_module_use_stashlist' -f -a "(module stashlist --c
8787
/Stash collection list\$/d; \
8888
/:\$/d; \
8989
/:ERROR:/d;')"
90-
complete -c module -n '__fish_module_use_config' -f -a "--dump-state --reset abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277"
90+
complete -c module -n '__fish_module_use_config' -f -a "--dump-state --reset abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager path_entry_reorder protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277"
9191

9292
complete -f -n '__fish_module_no_subcommand' -c module -a 'help' --description 'Print this or modulefile(s) help info'
9393
complete -f -n '__fish_module_no_subcommand' -c module -a 'avail' --description 'List all or matching available modules'

init/zsh-functions/_module.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ _module() {
378378
_arguments \
379379
'--dump-state[Report each state value of current Modules execution]' \
380380
'--reset[Unset environment variable relative to configuration key]' \
381-
'1:configuration key:(abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277)' \
381+
'1:configuration key:(abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager path_entry_reorder protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277)' \
382382
&& ret=0
383383
;;
384384
(edit)

site.exp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ set install_variantshortcut "@variantshortcut@"
117117

118118
set install_editor "@editor@"
119119

120+
set install_pathentryreorder "@pathentryreorder@"
121+
120122
set install_bashcompletiondir "@bashcompletiondir@"
121123
set install_fishcompletiondir "@fishcompletiondir@"
122124
set install_zshcompletiondir "@zshcompletiondir@"

tcl/envmngt.tcl.in

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,27 +1808,43 @@ proc add-path {cmd mode dflbhv args} {
18081808
set val [get-env $var]
18091809

18101810
foreach dir $path_list {
1811-
if {![info exists countarr($dir)] || $allow_dup} {
1811+
# remove $dir from path only if path_entry_reorder is true and
1812+
# $dir is already in path and duplicates are NOT allowed.
1813+
if {[getConf path_entry_reorder] && [info exists countarr($dir)]\
1814+
&& ! $allow_dup} {
1815+
set mpath_list [split $val $separator]
1816+
set mpath_list [lsearch -inline -all -not -exact $mpath_list $dir]
1817+
set val [join $mpath_list $separator]
1818+
}
1819+
# add $dir to beginning or end only if path_entry_reorder is true or
1820+
# $dir is NOT in path or duplicates are allowed.
1821+
# Please note: if path_entry_reorder is true and duplicates are not
1822+
# allowed, $dir is not in path ($val) - either it was not in or it
1823+
# had been removed. Hence we have to add it.
1824+
if {[getConf path_entry_reorder] || ![info exists countarr($dir)]\
1825+
|| $allow_dup} {
18121826
# ignore env var set empty if no empty entry found in reference
18131827
# counter array (sometimes var is cleared by setting it empty not
18141828
# unsetting it)
18151829
if {$val ne {} || [info exists countarr()]} {
18161830
set sep [expr {$val eq $separator ? {} : $separator}]
18171831
set val [expr {$bhv eq {prepend} ? "$dir$sep$val" :\
1818-
"$val$sep$dir"}]
1832+
"$val$sep$dir"}]
18191833
} else {
18201834
set val $dir
18211835
}
18221836
}
1823-
if {[info exists countarr($dir)]} {
1824-
# do not increase counter if bare separator string is added or if
1825-
# reference count is ignored (--ignore-refcount set) unless if
1826-
# duplicate mode is enabled (--duplicates set)
1827-
if {!$val_set_is_delim && (!$ign_refcount || $allow_dup)} {
1828-
incr countarr($dir)
1829-
}
1830-
} else {
1837+
#### ref-counting
1838+
# if $dir is NOT in path
1839+
# set ref-count 1
1840+
# else
1841+
# do NOT increase counter if bare separator string is added or if
1842+
# reference count is ignored (--ignore-refcount set) unless if
1843+
# duplicate mode is enabled (--duplicates set)
1844+
if {![info exists countarr($dir)]} {
18311845
set countarr($dir) 1
1846+
} elseif {!$val_set_is_delim && (!$ign_refcount || $allow_dup)} {
1847+
incr countarr($dir)
18321848
}
18331849
}
18341850

@@ -2046,7 +2062,10 @@ proc getModulesEnvVarGlobList {{loaded_ctx 0}} {
20462062
return $envvar_glob_list
20472063
}
20482064

2049-
# ;;; Local Variables: ***
2050-
# ;;; mode:tcl ***
2051-
# ;;; End: ***
2065+
# ;;; Local Variables:
2066+
# ;;; Mode: tcl-mode
2067+
# ;;; tcl-indent-level: 3
2068+
# ;;; tcl-continued-indent-level: 3
2069+
# ;;; indent-tabs-mode: nil
2070+
# ;;; End:
20522071
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent:

tcl/init.tcl.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ array set g_config_defs [list\
121121
nearly_forbidden_days {MODULES_NEARLY_FORBIDDEN_DAYS @nearlyforbiddendays@\
122122
0 i {0 365} {} {} intbe}\
123123
pager {MODULES_PAGER {@pagercmd@} 0 s}\
124+
path_entry_reorder {MODULES_PATH_ENTRY_REORDER @pathentryreorder@ 0 b {0 1}}\
124125
protected_envvars {MODULES_PROTECTED_ENVVARS <undef> 0 l}\
125126
rcfile {MODULERCFILE <undef> 0 l}\
126127
redirect_output {MODULES_REDIRECT_OUTPUT 1 0 b {0 1}}\

tcl/subcmd.tcl.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,7 +3155,10 @@ proc cmdModuleSpider {show_oneperline show_mtime show_filter search_filter\
31553155
$search_match $modpath_list {*}$args
31563156
}
31573157

3158-
# ;;; Local Variables: ***
3159-
# ;;; mode:tcl ***
3160-
# ;;; End: ***
3158+
# ;;; Local Variables:
3159+
# ;;; Mode: tcl-mode
3160+
# ;;; tcl-indent-level: 3
3161+
# ;;; tcl-continued-indent-level: 3
3162+
# ;;; indent-tabs-mode: nil
3163+
# ;;; End:
31613164
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent:

0 commit comments

Comments
 (0)