From 0b8c722b61231d63ff4fda71fa59643f63b3507c Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 17 Nov 2026 09:15:10 -0600 Subject: [PATCH 1/3] Detect altered interp commands regardless of their order After a modulefile or modulerc evaluation, the commands defined in the interpreter are compared to those initially recorded to recreate the interpreter if some are missing. Both lists were compared as strings, whereas "info commands" returns its result in an unspecified order. This order may change when procedures are defined then deleted by an evaluation. Interpreter was then recreated although all its commands were still there. It occurs with Tcl 9.1 as soon as two commands are added to the modulefile interpreter. Sort the two lists when they differ to only recreate the interpreter if their content is different. The spread test modulefiles and modulercs override the first procedure returned by "info procs" then check from another evaluation that this first procedure is still overridden, which assumes a stable order. Name explicitly the procedure they have always picked: auto_load_index. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- tcl/interp.tcl.in | 8 ++++++-- testsuite/modulefiles/spread/1.0 | 6 +++--- testsuite/modulefiles/spread/2.0 | 4 ++-- testsuite/modulefiles/spread/3.0 | 6 +++--- testsuite/modulefiles/spread/4.0 | 4 ++-- testsuite/modulefiles/spread/5.0 | 8 ++++---- testsuite/modulefiles/spread/6.0 | 4 ++-- testsuite/modulefiles/spread/7.0 | 8 ++++---- testsuite/modulefiles/spread/8.0 | 4 ++-- testsuite/modulefiles/spreadrc/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir1/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir1/1.0 | 6 +++--- testsuite/modulefiles/spreadrc/dir2/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir2/1.0 | 4 ++-- testsuite/modulefiles/spreadrc/dir3/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir3/1.0 | 6 +++--- testsuite/modulefiles/spreadrc/dir4/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir4/1.0 | 4 ++-- testsuite/modulefiles/spreadrc/dir5/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir5/1.0 | 8 ++++---- testsuite/modulefiles/spreadrc/dir6/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir6/1.0 | 4 ++-- testsuite/modulefiles/spreadrc/dir7/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir7/1.0 | 8 ++++---- testsuite/modulefiles/spreadrc/dir8/.modulerc | 6 +++--- testsuite/modulefiles/spreadrc/dir8/1.0 | 4 ++-- 26 files changed, 77 insertions(+), 73 deletions(-) diff --git a/tcl/interp.tcl.in b/tcl/interp.tcl.in index a0b21fab2..c4ac809fa 100644 --- a/tcl/interp.tcl.in +++ b/tcl/interp.tcl.in @@ -859,8 +859,12 @@ proc resetInterpState {itrp fresh dumpVarsVN dumpArrayVarsVN untrackVarsVN\ reportDebug "saving for $itrp command list $dumpCommands" # if current interpreter command list does not match initial list it # means that at least one command has been altered so we need to recreate - # interpreter to guaranty proper functioning - } elseif {$dumpCommands ne [$itrp eval {info commands}]} { + # interpreter to guaranty proper functioning. commands are returned in an + # unspecified order that may change when some are deleted then defined + # again, so lists are sorted when they differ to only detect a change in + # their content + } elseif {$dumpCommands ne [set cmd_list [$itrp eval {info commands}]]\ + && [lsort $dumpCommands] ne [lsort $cmd_list]} { reportDebug "missing command(s), recreating interp $itrp" interp delete $itrp createInterp $itrp diff --git a/testsuite/modulefiles/spread/1.0 b/testsuite/modulefiles/spread/1.0 index 007a0e196..b6c682664 100644 --- a/testsuite/modulefiles/spread/1.0 +++ b/testsuite/modulefiles/spread/1.0 @@ -48,8 +48,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -83,7 +83,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spread) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spread" } diff --git a/testsuite/modulefiles/spread/2.0 b/testsuite/modulefiles/spread/2.0 index 7ef85d9fd..aa447fdcb 100644 --- a/testsuite/modulefiles/spread/2.0 +++ b/testsuite/modulefiles/spread/2.0 @@ -48,8 +48,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spread/3.0 b/testsuite/modulefiles/spread/3.0 index 3b001b5cb..3759b4bfa 100644 --- a/testsuite/modulefiles/spread/3.0 +++ b/testsuite/modulefiles/spread/3.0 @@ -48,8 +48,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -86,7 +86,7 @@ set env(spread) "yes" set env(spreadcmd) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadcmd" } diff --git a/testsuite/modulefiles/spread/4.0 b/testsuite/modulefiles/spread/4.0 index 48ccbcbac..eeeca05f9 100644 --- a/testsuite/modulefiles/spread/4.0 +++ b/testsuite/modulefiles/spread/4.0 @@ -48,8 +48,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spread/5.0 b/testsuite/modulefiles/spread/5.0 index 8e64fb6c6..eafb0b5ca 100644 --- a/testsuite/modulefiles/spread/5.0 +++ b/testsuite/modulefiles/spread/5.0 @@ -49,8 +49,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -83,7 +83,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadcasc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadcasc" } @@ -125,7 +125,7 @@ if {$tcl_platform(osVersion) ne "test"} { # test if specific or overridden interpreter alias command are still there # after cascaded interpretation -# test if first proc defined has been altered +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spread/6.0 b/testsuite/modulefiles/spread/6.0 index 06c9258f3..24cbddda3 100644 --- a/testsuite/modulefiles/spread/6.0 +++ b/testsuite/modulefiles/spread/6.0 @@ -49,8 +49,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spread/7.0 b/testsuite/modulefiles/spread/7.0 index 814ac4d95..cd3309152 100644 --- a/testsuite/modulefiles/spread/7.0 +++ b/testsuite/modulefiles/spread/7.0 @@ -49,8 +49,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -87,7 +87,7 @@ set env(spread) "yes" set env(spreadcasccmd) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadcasccmd" } @@ -138,7 +138,7 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] == -1} { # test if specific or overridden interpreter alias command are still there # after cascaded interpretation -# test if first proc defined has been altered +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spread/8.0 b/testsuite/modulefiles/spread/8.0 index 2af4c62ca..9e188e4e8 100644 --- a/testsuite/modulefiles/spread/8.0 +++ b/testsuite/modulefiles/spread/8.0 @@ -49,8 +49,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { } # test if specific or overridden interpreter alias command have spread here -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spreadrc/.modulerc b/testsuite/modulefiles/spreadrc/.modulerc index e680f52c9..2596ec3bb 100644 --- a/testsuite/modulefiles/spreadrc/.modulerc +++ b/testsuite/modulefiles/spreadrc/.modulerc @@ -51,8 +51,8 @@ if {$tcl_platform(osVersion) eq "test"} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -92,7 +92,7 @@ set tcl_platform(osVersion) "test" set env(spreadrc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrc" } diff --git a/testsuite/modulefiles/spreadrc/dir1/.modulerc b/testsuite/modulefiles/spreadrc/dir1/.modulerc index 3cf3e0859..aeb81dbd6 100644 --- a/testsuite/modulefiles/spreadrc/dir1/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir1/.modulerc @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -99,7 +99,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrc" } diff --git a/testsuite/modulefiles/spreadrc/dir1/1.0 b/testsuite/modulefiles/spreadrc/dir1/1.0 index e00da6122..2d197aa04 100644 --- a/testsuite/modulefiles/spreadrc/dir1/1.0 +++ b/testsuite/modulefiles/spreadrc/dir1/1.0 @@ -56,8 +56,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -98,7 +98,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadmod) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadmod" } diff --git a/testsuite/modulefiles/spreadrc/dir2/.modulerc b/testsuite/modulefiles/spreadrc/dir2/.modulerc index 3cf3e0859..aeb81dbd6 100644 --- a/testsuite/modulefiles/spreadrc/dir2/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir2/.modulerc @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -99,7 +99,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrc" } diff --git a/testsuite/modulefiles/spreadrc/dir2/1.0 b/testsuite/modulefiles/spreadrc/dir2/1.0 index 1a1c52a2f..487606705 100644 --- a/testsuite/modulefiles/spreadrc/dir2/1.0 +++ b/testsuite/modulefiles/spreadrc/dir2/1.0 @@ -56,8 +56,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spreadrc/dir3/.modulerc b/testsuite/modulefiles/spreadrc/dir3/.modulerc index 3e12db762..01b2ac837 100644 --- a/testsuite/modulefiles/spreadrc/dir3/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir3/.modulerc @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -102,7 +102,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrc" } diff --git a/testsuite/modulefiles/spreadrc/dir3/1.0 b/testsuite/modulefiles/spreadrc/dir3/1.0 index 51c60d20d..4b2d72693 100644 --- a/testsuite/modulefiles/spreadrc/dir3/1.0 +++ b/testsuite/modulefiles/spreadrc/dir3/1.0 @@ -56,8 +56,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -103,7 +103,7 @@ set env(spreadmod) "yes" set env(spreadmodcmd) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadmodcmd" } diff --git a/testsuite/modulefiles/spreadrc/dir4/.modulerc b/testsuite/modulefiles/spreadrc/dir4/.modulerc index fc4b12915..7f61ea49b 100644 --- a/testsuite/modulefiles/spreadrc/dir4/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir4/.modulerc @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -103,7 +103,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrc" } diff --git a/testsuite/modulefiles/spreadrc/dir4/1.0 b/testsuite/modulefiles/spreadrc/dir4/1.0 index 3969e7ed2..2a0dea80d 100644 --- a/testsuite/modulefiles/spreadrc/dir4/1.0 +++ b/testsuite/modulefiles/spreadrc/dir4/1.0 @@ -56,8 +56,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spreadrc/dir5/.modulerc b/testsuite/modulefiles/spreadrc/dir5/.modulerc index 97e1b37f1..e60d538cb 100644 --- a/testsuite/modulefiles/spreadrc/dir5/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir5/.modulerc @@ -58,8 +58,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -100,7 +100,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrccasc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrccasc" } diff --git a/testsuite/modulefiles/spreadrc/dir5/1.0 b/testsuite/modulefiles/spreadrc/dir5/1.0 index f5406dd23..d8de278c7 100644 --- a/testsuite/modulefiles/spreadrc/dir5/1.0 +++ b/testsuite/modulefiles/spreadrc/dir5/1.0 @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -100,7 +100,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadmodcasc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadmodcasc" } @@ -145,7 +145,7 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] == -1} { # test if specific or overridden interpreter alias command are still there # after cascaded interpretation -# test if first proc defined has been altered +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spreadrc/dir6/.modulerc b/testsuite/modulefiles/spreadrc/dir6/.modulerc index 97e1b37f1..e60d538cb 100644 --- a/testsuite/modulefiles/spreadrc/dir6/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir6/.modulerc @@ -58,8 +58,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -100,7 +100,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrccasc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrccasc" } diff --git a/testsuite/modulefiles/spreadrc/dir6/1.0 b/testsuite/modulefiles/spreadrc/dir6/1.0 index 7d9d9a7c6..eacd371fc 100644 --- a/testsuite/modulefiles/spreadrc/dir6/1.0 +++ b/testsuite/modulefiles/spreadrc/dir6/1.0 @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spreadrc/dir7/.modulerc b/testsuite/modulefiles/spreadrc/dir7/.modulerc index 5c6b84435..a72a71c4a 100644 --- a/testsuite/modulefiles/spreadrc/dir7/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir7/.modulerc @@ -58,8 +58,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -103,7 +103,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrccasc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrccasc" } diff --git a/testsuite/modulefiles/spreadrc/dir7/1.0 b/testsuite/modulefiles/spreadrc/dir7/1.0 index 4632fdf1a..8e27741b2 100644 --- a/testsuite/modulefiles/spreadrc/dir7/1.0 +++ b/testsuite/modulefiles/spreadrc/dir7/1.0 @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -104,7 +104,7 @@ set env(spreadmodcasc) "yes" set env(spreadmodcasccmd) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadmodcasccmd" } @@ -155,7 +155,7 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] == -1} { # test if specific or overridden interpreter alias command are still there # after cascaded interpretation -# test if first proc defined has been altered +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters diff --git a/testsuite/modulefiles/spreadrc/dir8/.modulerc b/testsuite/modulefiles/spreadrc/dir8/.modulerc index 4abaf0906..3b1cf210d 100644 --- a/testsuite/modulefiles/spreadrc/dir8/.modulerc +++ b/testsuite/modulefiles/spreadrc/dir8/.modulerc @@ -58,8 +58,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overriden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters @@ -104,7 +104,7 @@ lappend auto_path $env(TESTSUITEDIR) set env(spreadrccasc) "yes" # define specific procs or override interpreter alias command -# override first proc defined +# override a pre-existing proc proc $existing_proc {args} { return "spreadrccasc" } diff --git a/testsuite/modulefiles/spreadrc/dir8/1.0 b/testsuite/modulefiles/spreadrc/dir8/1.0 index 9f7d76bbc..a0413caea 100644 --- a/testsuite/modulefiles/spreadrc/dir8/1.0 +++ b/testsuite/modulefiles/spreadrc/dir8/1.0 @@ -57,8 +57,8 @@ if {[lsearch -exact $auto_path $env(TESTSUITEDIR)] > -1} { # test if specific or overridden interpreter alias command have spread here # coming from modulerc or sibbling modulefiles -set existing_proc [lindex [info procs] 0] -# test if first proc defined has been altered +set existing_proc auto_load_index +# test if a pre-existing proc has been altered if {[info procs $existing_proc] ne $existing_proc} { puts stderr "procedure $existing_proc does not exist" # env variable spread across interpretation and even between interpreters From 6542431fa7bb661f2398e6b5d2916b6361d5dd2e Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Mon, 16 Nov 2026 16:43:41 -0600 Subject: [PATCH 2/3] Add --regexp option to module-* modulefile commands Hiding, forbidding, tagging or warning about a set of modules that do not share a common name or version prefix (e.g., all the "-debug" builds or version 1 of several software) requires one statement per module, as a module specification always starts with a module name. Add a --regexp option to module-hide, module-forbid, module-tag and module-warn to designate target modules with Tcl regular expressions matched against module name and version. It is similar to the module-hide-regex and module-forbid-regex commands of Lmod. When this option is set, all the module arguments of the command are regular expressions. As such expression may start with a dash (e.g., "-debug$"), an argument starting with this character that is not a known option is then taken as a regular expression instead of raising an invalid option error. Regular expressions cannot be indexed per module root name like module specifications, so they are recorded in dedicated structures and tested against every module looked at. Nagelfar reports an argument starting with a dash as a bad option, so the lint plugins hide this leading dash when --regexp is set. Syntax of module-forbid, module-tag and module-warn moves from option-value pairs to options with a declared value, to describe the valueless --regexp. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- MIGRATING.rst | 27 ++ NEWS.rst | 4 + doc/source/changes.rst | 4 + .../design/hide-or-forbid-modulefile.rst | 7 + doc/source/design/module-tags.rst | 45 ++ doc/source/design/module-warn.rst | 2 + doc/source/modulefile.rst | 92 +++++ doc/source/other-implementations.rst | 3 + share/nagelfar/plugin_modulefile.tcl | 19 +- share/nagelfar/plugin_modulerc.tcl | 22 + share/nagelfar/syntaxdb_modulefile.tcl | 17 +- share/nagelfar/syntaxdb_modulerc.tcl | 17 +- tcl/mfcmd.tcl | 87 +++- tcl/modfind.tcl.in | 39 +- testsuite/modulefiles.4/tag/.modulerc | 65 +++ testsuite/modulefiles.lint/tag/.modulerc | 4 + testsuite/modulefiles.lint/tag/5.0 | 1 + testsuite/modules.20-locate/142-regexp.exp | 390 ++++++++++++++++++ 18 files changed, 806 insertions(+), 39 deletions(-) create mode 100644 testsuite/modules.20-locate/142-regexp.exp diff --git a/MIGRATING.rst b/MIGRATING.rst index a9a863cd8..7df49c5c0 100644 --- a/MIGRATING.rst +++ b/MIGRATING.rst @@ -96,6 +96,33 @@ kept across module evaluations. The ``--priority`` option is also available on the :subcmd:`prepend-path`, :subcmd:`append-path` and :subcmd:`use` sub-commands. +Selecting modules with regular expression +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The :mfcmd:`module-hide`, :mfcmd:`module-forbid`, :mfcmd:`module-tag` and +:mfcmd:`module-warn` modulefile commands accept a new ``--regexp`` option to +designate the modules they apply to with regular expressions. They are +matched against the name and version of modules, which helps to target modules +that do not share the same name or version prefix. + +.. parsed-literal:: + + :ps:`$` cat /path/to/modulefiles/.modulerc + #%Module + module-hide --regexp {-debug$} + module-forbid --regexp {^(foo|bar)/1\\.} --message {Version 1 is retired} + :ps:`$` module avail -a + --------------- /path/to/modulefiles --------------- + bar/1.4 bar/2.0-debug foo/1.0 foo/2.1 + bar/2.0 baz/3.2 foo/2.0 foo/2.1-debug + :ps:`$` module load foo/1.0 + :sgrer:`ERROR`: Access to module foo/1.0 is denied + Version 1 is retired + +When ``--regexp`` option is set, all the module arguments of the command are +regular expressions. See the :ref:`Regular expression module selection` +section for details. + v5.7 ---- diff --git a/NEWS.rst b/NEWS.rst index d61cbea86..42f520e9c 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -65,6 +65,10 @@ Modules 5.8.0 (not yet released) of the module providing a family in addition to its name. For compatibility with Lmod, the :envvar:`LMOD_FAMILY_\_VERSION` environment variable is also defined and set to the same value. +* Add ``--regexp`` option to :mfcmd:`module-forbid`, :mfcmd:`module-hide`, + :mfcmd:`module-tag` and :mfcmd:`module-warn` modulefile commands to + designate the modules they apply to with a regular expression matched + against module name and version. .. _5.7 release notes: diff --git a/doc/source/changes.rst b/doc/source/changes.rst index a4b497606..1c800d6b5 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -1303,6 +1303,10 @@ The following modulefile Tcl commands appeared on Modules 5. environment. * options ``--user`` and ``--group`` are added. + Starting with version ``5.8``, the ``--regexp`` option is added to designate + the modules these commands apply to with a regular expression. This option + is also added to :mfcmd:`module-warn`. + :mfcmd:`break` Starting with version 5.4, a modulefile using :mfcmd:`break` may be unloaded diff --git a/doc/source/design/hide-or-forbid-modulefile.rst b/doc/source/design/hide-or-forbid-modulefile.rst index e3cc97251..c2f100b11 100644 --- a/doc/source/design/hide-or-forbid-modulefile.rst +++ b/doc/source/design/hide-or-forbid-modulefile.rst @@ -229,6 +229,7 @@ Specification - ``--group``: specify a list of groups whose member are specifically affected by hide mechanism - ``--before``: enables hide mechanism until a given date - ``--after``: enables hide mechanism after a given date + - ``--regexp``: module arguments are regular expressions designating the modules to hide - ``module-forbid`` accepts options that change its behavior: @@ -240,6 +241,12 @@ Specification - ``--after``: enables forbid mechanism after a given date - ``--message``: supplements error message obtained when trying to evaluate a forbidden module with given text message - ``--nearly-message``: supplements warning message obtained when evaluating a nearly forbidden module with given text message + - ``--regexp``: module arguments are regular expressions designating the modules to forbid + +- ``--regexp`` option selects modules with regular expressions rather than module specifications + + - See :ref:`module-tags` design notes for the description of this option, as it is shared by ``module-hide``, ``module-forbid``, ``module-tag`` and ``module-warn`` + - Hiding level set through regular expressions is compared to the levels set on module specifications and on full path designation: the strongest matching level is retained - Each use case expressed above are covered by following command: diff --git a/doc/source/design/module-tags.rst b/doc/source/design/module-tags.rst index acef73946..f9c538a97 100644 --- a/doc/source/design/module-tags.rst +++ b/doc/source/design/module-tags.rst @@ -93,6 +93,51 @@ Defining - ``--not-group``: specify a list of groups whose member are unaffected by specified tagging - ``--user``: specify a list of users specifically affected by specified tagging - ``--group``: specify a list of groups whose member are specifically affected by specified tagging + - ``--regexp``: module arguments are regular expressions designating the modules to tag + +- ``--regexp`` option designates target modules with regular expressions + + - Useful to target with a single statement modules that have no name or version prefix in common (e.g., all the ``-debug`` versions) + - Option is available on all the commands relying on the tag mechanism to select modules: ``module-tag``, ``module-forbid``, ``module-hide`` and ``module-warn`` + - Implemented as a flag that changes the meaning of all the ``modspec`` arguments of the command + + - Wherever the flag is positioned on the command line + - Regular expressions and module specifications cannot be mixed on the same command + - At least one ``modspec`` argument is still required + - For ``module-tag``, first argument that does not start with ``-`` is still the tag name + + - A regular expression may start with a ``-`` character (e.g., ``-debug$``) + + - When ``--regexp`` is set, an argument starting with ``-`` that is not an option known by the command is considered a regular expression + - Rather than raising an *invalid option* error + - Drawback: a misspelled option is silently taken as a regular expression when ``--regexp`` is set + - A regular expression equal to an option name of the command cannot be expressed as is (``[-]-hard`` should be written instead of ``--hard``) + - Nagelfar linter reports such argument as a bad option: lint plugins remove the leading ``-`` of the arguments that do not look like a long option when ``--regexp`` is set + + - Regular expressions are Tcl regular expressions + + - Matched with ``regexp`` Tcl command against the name and version of module + - Variants of loaded modules are not part of the tested string + - Not anchored: ``^`` and ``$`` have to be used to match the whole module name and version + - Case insensitive match is applied when ``icase`` option enables it for the current context + - Validity is checked when regular expressions are recorded, an error is raised if one is incorrect + - Like module specifications, they are not checked if application criteria of the command (user, group, time frame) are not met + + - No module root name can be extracted from a regular expression + + - Tags defined on module specifications are stored per module root name to only test the specifications that may match a given module + - Regular expressions are stored in a separate list and each of them is tested against every module looked at + - Cost is thus proportional to the number of regular expressions defined, which is expected to be small + + - When both module specifications and regular expressions match a module for a given tag, properties (e.g., message) defined for the module specification are retained + + - Among regular expressions, the first one defined that matches wins + - Same precedence principle than full path designation over module specification: the more precise designation wins + + - Regular expressions are not recorded as stickiness rule in loaded environment + + - Stickiness set through a regular expression is satisfied only if the same module is reloaded + - Recording them would require to distinguish regular expressions from module specifications in ``__MODULES_LMSTICKYRULE`` - ``--user``, ``--group``, ``--not-user`` and ``--not-group`` specification is only supported on Unix platform diff --git a/doc/source/design/module-warn.rst b/doc/source/design/module-warn.rst index 22815e0d0..04973b21a 100644 --- a/doc/source/design/module-warn.rst +++ b/doc/source/design/module-warn.rst @@ -43,6 +43,8 @@ inhibit or enable specifically the warning mechanism. * ``--before``: enables warn mechanism until a given date * ``--after``: enables warn mechanism after a given date * ``--message``: warning message to print +* ``--regexp``: module arguments are regular expressions designating the + modules to warn about (see :ref:`module-tags`) ``warning`` tag --------------- diff --git a/doc/source/modulefile.rst b/doc/source/modulefile.rst index a3834ca70..b0b5eab33 100644 --- a/doc/source/modulefile.rst +++ b/doc/source/modulefile.rst @@ -647,6 +647,7 @@ the *modulefile* is being loaded. * ``--group {group...}`` * ``--message {text message}`` * ``--nearly-message {text message}`` + * ``--regexp`` If ``--after`` option is set, forbidding is only effective after specified date time. Following the same principle, if ``--before`` option is set, @@ -695,6 +696,10 @@ the *modulefile* is being loaded. ``nearly-forbidden`` tag applied to them. See :ref:`Module tags` section in :ref:`module(1)`. + If ``--regexp`` option is set, each *modulefile* argument is a regular + expression and forbidding applies to the modules whose name and version match + it. See `Regular expression module selection`_ section below. + The parameter *modulefile* may leverage a specific syntax to finely select module version (see `Advanced module version specifiers`_ section below). It may also be a full path file name to precisely designate one module in a @@ -710,6 +715,9 @@ the *modulefile* is being loaded. .. versionchanged:: 5.4 Options ``--user`` and ``--group`` added + .. versionchanged:: 5.8 + Option ``--regexp`` added + .. mfcmd:: module-help string Defines a string which is displayed in case of the invocation of the @@ -738,6 +746,7 @@ the *modulefile* is being loaded. * ``--soft|--hard`` * ``--hidden-loaded`` + * ``--regexp`` * ``--after datetime`` * ``--before datetime`` * ``--not-user {user...}`` @@ -815,6 +824,10 @@ the *modulefile* is being loaded. reported on :subcmd:`avail` or :subcmd:`spider` sub-commands context. See :ref:`Module tags` section in :ref:`module(1)`. + If ``--regexp`` option is set, each *modulefile* argument is a regular + expression and hiding applies to the modules whose name and version match it. + See `Regular expression module selection`_ section below. + The parameter *modulefile* may also be a symbolic modulefile name or a modulefile alias. It may also leverage a specific syntax to finely select module version (see `Advanced module version specifiers`_ section below). @@ -834,6 +847,9 @@ the *modulefile* is being loaded. .. versionchanged:: 5.4 Options ``--user`` and ``--group`` added + .. versionchanged:: 5.8 + Option ``--regexp`` added + .. mfcmd:: module-info option [info-args] Provide information about the :file:`modulecmd.tcl` program's state. Some of @@ -1054,6 +1070,7 @@ the *modulefile* is being loaded. * ``--not-group {group...}`` * ``--user {user...}`` * ``--group {group...}`` + * ``--regexp`` If ``--not-user`` option is set, the tag is not applied if the username of the user currently running :file:`modulecmd.tcl` is part of the list of @@ -1072,6 +1089,10 @@ the *modulefile* is being loaded. same group name is set on both ``--group`` and ``--not-group``, ``--group`` prevails over ``--not-group``. + If ``--regexp`` option is set, each *modulefile* argument is a regular + expression and *tag* is applied to the modules whose name and version match + it. See `Regular expression module selection`_ section below. + The parameter *modulefile* may also be a symbolic modulefile name or a modulefile alias. It may also leverage a specific syntax to finely select module version (see `Advanced module version specifiers`_ section below). @@ -1103,6 +1124,9 @@ the *modulefile* is being loaded. .. versionchanged:: 5.4 Options ``--user`` and ``--group`` added + .. versionchanged:: 5.8 + Option ``--regexp`` added + .. mfcmd:: module-version modulefile version-name... Assigns the symbolic *version-name* to the *modulefile*. This command @@ -1155,6 +1179,7 @@ the *modulefile* is being loaded. * ``--not-group {group...}`` * ``--user {user...}`` * ``--group {group...}`` + * ``--regexp`` If ``--after`` option is set, warning is only effective after specified date time. Following the same principle, if ``--before`` option is set, warning is @@ -1184,6 +1209,10 @@ the *modulefile* is being loaded. or :subcmd:`spider` sub-commands are reported with a ``warning`` tag applied to them. See :ref:`Module tags` section in :ref:`module(1)`. + If ``--regexp`` option is set, each *modulefile* argument is a regular + expression and warning applies to the modules whose name and version match + it. See `Regular expression module selection`_ section below. + The parameter *modulefile* may leverage a specific syntax to finely select module version (see `Advanced module version specifiers`_ section below). It may also be a full path file name to precisely designate one module in a @@ -1193,6 +1222,9 @@ the *modulefile* is being loaded. .. versionadded:: 5.6 + .. versionchanged:: 5.8 + Option ``--regexp`` added + .. mfcmd:: module-whatis string Defines a string which is displayed in case of the invocation of the @@ -2329,6 +2361,66 @@ a valid variant name (e.g., *name+*, *name++*, *name/version+1*). ``+`` and ``~`` characters are allowed in module name or version if not followed by a valid variant name +.. _Regular expression module selection: + +Regular expression module selection +----------------------------------- + +The :mfcmd:`module-forbid`, :mfcmd:`module-hide`, :mfcmd:`module-tag` and +:mfcmd:`module-warn` modulefile commands accept a ``--regexp`` option to +designate the modules they apply to with regular expressions instead of +module specifications. It helps to target with a single statement modules +that do not share the same name or the same version prefix. + +.. code-block:: text + + # hide all debug builds + module-hide --regexp {-debug$} + # forbid version 1 of several software + module-forbid --regexp {^(foo|bar)/1\.} + +When ``--regexp`` option is set, all the *modulefile* arguments of the +command are regular expressions, wherever the option is placed on the command +line. Each of them is a Tcl regular expression (see :manpage:`re_syntax(n)`) +matched against the name and version of modules (e.g., ``foo/1.2``), whatever +their variants. As for any regular expression, a match is found if it matches +any part of this string. Use the ``^`` and ``$`` anchors to match from the +start or up to the end of the module name and version. It is advised to +enclose regular expressions in curly-braces to protect their special +characters from Tcl interpretation. + +A regular expression may start with a ``-`` character. As a consequence, when +``--regexp`` option is set, an argument starting with ``-`` that does not +correspond to an option of the command is considered a regular expression +rather than reported as an invalid option. + +Match is case sensitive unless if the :mconfig:`icase` configuration option +enables case insensitive match in the current context. + +Symbolic versions and module aliases are not resolved: regular expressions +are matched against the name and version of the evaluated modulefile. A +symbolic version or a module alias is hidden by :mfcmd:`module-hide` if its +own name matches. + +When several statements match a module: + +* the strongest hiding level among the matching :mfcmd:`module-hide` + statements is retained, like for regular module specifications; +* properties of a tag (like the message of :mfcmd:`module-forbid` or + :mfcmd:`module-warn`) are those of the statement set with a matching + module specification if any, otherwise those of the first evaluated + statement set with a matching regular expression. + +A ``sticky`` or ``super-sticky`` tag applied through a regular expression is +only satisfied by the reload of the same module, not by the load of another +module matching this regular expression. + +An error is raised if an argument is not a valid regular expression. + +.. only:: html or latex + + .. versionadded:: 5.8 + .. _Dependencies between modulefiles: Dependencies between modulefiles diff --git a/doc/source/other-implementations.rst b/doc/source/other-implementations.rst index a31c3090b..c1557d327 100644 --- a/doc/source/other-implementations.rst +++ b/doc/source/other-implementations.rst @@ -147,6 +147,9 @@ implementation. - :ref:`Change modulefile command behavior` * - `NAG file`_ - :mfcmd:`module-forbid`, :mfcmd:`module-warn` modulefile commands + * - ``module-forbid-regex``, ``module-hide-regex`` modulefile commands + - ``--regexp`` option of :mfcmd:`module-forbid` and :mfcmd:`module-hide` + modulefile commands * - Lmod + `XALT`_ - :ref:`Logging activity` * - `Hook functions`_ diff --git a/share/nagelfar/plugin_modulefile.tcl b/share/nagelfar/plugin_modulefile.tcl index e14202f91..b9a88b898 100644 --- a/share/nagelfar/plugin_modulefile.tcl +++ b/share/nagelfar/plugin_modulefile.tcl @@ -49,8 +49,9 @@ proc statementWords {words info} { return $res } -# translate known '--option=value' arguments into '--option value' to -# correctly check them with Nagelfar +# adapt statements that Nagelfar cannot correctly check as is: translate +# known '--option=value' arguments into '--option value' and hide the leading +# dash of regular expression arguments proc statementRaw {stmt info} { set res {} regexp {^(.+?)\s} $stmt match cmd @@ -59,6 +60,20 @@ proc statementRaw {stmt info} { if {[regsub -all {(--(delim|tag))=} $stmt {\1 } newstmt]} { set res [list replace $newstmt] } + } elseif {$cmd in {module-forbid module-hide module-tag module-warn}} { + set res [stripRegexpLeadingDash $stmt] + } + return $res +} + +# when --regexp option is set, module arguments are regular expressions that +# may start with a dash character. Nagelfar would report them as bad options, +# so this leading dash is removed unless argument looks like a long option +proc stripRegexpLeadingDash {stmt} { + set res {} + if {[regexp {\s--regexp(\s|$)} $stmt] && [regsub -all\ + {(\s[\{"]?)-(?!-[a-z])} $stmt {\1} newstmt]} { + set res [list replace $newstmt] } return $res } diff --git a/share/nagelfar/plugin_modulerc.tcl b/share/nagelfar/plugin_modulerc.tcl index 89130ad10..7bf4a7d30 100644 --- a/share/nagelfar/plugin_modulerc.tcl +++ b/share/nagelfar/plugin_modulerc.tcl @@ -32,6 +32,28 @@ proc statementWords {words info} { return $res } +# adapt statements that Nagelfar cannot correctly check as is +proc statementRaw {stmt info} { + set res {} + if {[regexp {^(module-forbid|module-hide|module-tag|module-warn)\s}\ + $stmt]} { + set res [stripRegexpLeadingDash $stmt] + } + return $res +} + +# when --regexp option is set, module arguments are regular expressions that +# may start with a dash character. Nagelfar would report them as bad options, +# so this leading dash is removed unless argument looks like a long option +proc stripRegexpLeadingDash {stmt} { + set res {} + if {[regexp {\s--regexp(\s|$)} $stmt] && [regsub -all\ + {(\s[\{"]?)-(?!-[a-z])} $stmt {\1} newstmt]} { + set res [list replace $newstmt] + } + return $res +} + # report variable that should be renamed proc varWrite {var info} { set res {} diff --git a/share/nagelfar/syntaxdb_modulefile.tcl b/share/nagelfar/syntaxdb_modulefile.tcl index c98f8012b..d180ef589 100644 --- a/share/nagelfar/syntaxdb_modulefile.tcl +++ b/share/nagelfar/syntaxdb_modulefile.tcl @@ -155,7 +155,7 @@ set {::syntax(module test)} x* set {::syntax(module whatis)} x* set ::syntax(module-alias) 2 # module-forbid accepts option at any position -set ::syntax(module-forbid) {p* x p* x* p*} +set ::syntax(module-forbid) {o* x o* x* o*} set ::syntax(module-help) 1 # module-hide accepts option at any position set ::syntax(module-hide) {o* x o* x* o*} @@ -177,11 +177,11 @@ set {::syntax(module-info usergroups)} x? set {::syntax(module-info username)} x? set {::syntax(module-info version)} 1 # module-tag accepts option at any position -set ::syntax(module-tag) {p* x p* x p* x* p*} +set ::syntax(module-tag) {o* x o* x o* x* o*} set ::syntax(module-version) {x x x*} set ::syntax(module-virtual) 2 # module-warn accepts option at any position -set ::syntax(module-warn) {p* x p* x* p*} +set ::syntax(module-warn) {o* x o* x* o*} set ::syntax(module-whatis) 1 set ::syntax(modulepath-label) 2 set ::syntax(prepend-path) {o* x x x*} @@ -290,34 +290,37 @@ set {::option(module unuse)} {--remove-on-unload --noop-on-unload\ set {::option(module use)} {-a --append -p --prepend --priority} set {::option(module use --priority)} 1 set ::option(module-forbid) {--user --group --not-user --not-group --after\ - --before --message --nearly-message} + --before --message --nearly-message --regexp} set {::option(module-forbid --user)} 1 set {::option(module-forbid --group)} 1 set {::option(module-forbid --not-user)} 1 set {::option(module-forbid --not-group)} 1 set {::option(module-forbid --after)} 1 set {::option(module-forbid --before)} 1 +set {::option(module-forbid --message)} 1 +set {::option(module-forbid --nearly-message)} 1 set ::option(module-hide) {--user --group --not-user --not-group --after\ - --before --soft --hard --hidden-loaded} + --before --soft --hard --hidden-loaded --regexp} set {::option(module-hide --user)} 1 set {::option(module-hide --group)} 1 set {::option(module-hide --not-user)} 1 set {::option(module-hide --not-group)} 1 set {::option(module-hide --after)} 1 set {::option(module-hide --before)} 1 -set ::option(module-tag) {--user --group --not-user --not-group} +set ::option(module-tag) {--user --group --not-user --not-group --regexp} set {::option(module-tag --user)} 1 set {::option(module-tag --group)} 1 set {::option(module-tag --not-user)} 1 set {::option(module-tag --not-group)} 1 set ::option(module-warn) {--user --group --not-user --not-group --after\ - --before --message} + --before --message --regexp} set {::option(module-warn --user)} 1 set {::option(module-warn --group)} 1 set {::option(module-warn --not-user)} 1 set {::option(module-warn --not-group)} 1 set {::option(module-warn --after)} 1 set {::option(module-warn --before)} 1 +set {::option(module-warn --message)} 1 set ::option(prepend-path) {-d --delim --duplicates --ignore-refcount\ --priority} set {::option(prepend-path -d)} 1 diff --git a/share/nagelfar/syntaxdb_modulerc.tcl b/share/nagelfar/syntaxdb_modulerc.tcl index 38b7444b0..13ba22ac2 100644 --- a/share/nagelfar/syntaxdb_modulerc.tcl +++ b/share/nagelfar/syntaxdb_modulerc.tcl @@ -52,7 +52,7 @@ set ::syntax(is-used) x* set ::syntax(lsb-release) s set ::syntax(module-alias) 2 # module-forbid accepts option at any position -set ::syntax(module-forbid) {p* x p* x* p*} +set ::syntax(module-forbid) {o* x o* x* o*} # module-hide accepts option at any position set ::syntax(module-hide) {o* x o* x* o*} set ::syntax(module-info) {s x?} @@ -73,11 +73,11 @@ set {::syntax(module-info usergroups)} x? set {::syntax(module-info username)} x? set {::syntax(module-info version)} 1 # module-tag accepts option at any position -set ::syntax(module-tag) {p* x p* x p* x* p*} +set ::syntax(module-tag) {o* x o* x o* x* o*} set ::syntax(module-version) {x x x*} set ::syntax(module-virtual) 2 # module-warn accepts option at any position -set ::syntax(module-warn) {p* x p* x* p*} +set ::syntax(module-warn) {o* x o* x* o*} set ::syntax(modulepath-ignore) {x x*} set ::syntax(modulepath-label) 2 set ::syntax(system) {x x*} @@ -105,33 +105,36 @@ set ::subCmd(uname) {sysname nodename domain release version machine} # option set ::option(module-forbid) {--user --group --not-user --not-group --after\ - --before --message --nearly-message} + --before --message --nearly-message --regexp} set {::option(module-forbid --user)} 1 set {::option(module-forbid --group)} 1 set {::option(module-forbid --not-user)} 1 set {::option(module-forbid --not-group)} 1 set {::option(module-forbid --after)} 1 set {::option(module-forbid --before)} 1 +set {::option(module-forbid --message)} 1 +set {::option(module-forbid --nearly-message)} 1 set ::option(module-hide) {--user --group --not-user --not-group --after\ - --before --soft --hard --hidden-loaded} + --before --soft --hard --hidden-loaded --regexp} set {::option(module-hide --user)} 1 set {::option(module-hide --group)} 1 set {::option(module-hide --not-user)} 1 set {::option(module-hide --not-group)} 1 set {::option(module-hide --after)} 1 set {::option(module-hide --before)} 1 -set ::option(module-tag) {--user --group --not-user --not-group} +set ::option(module-tag) {--user --group --not-user --not-group --regexp} set {::option(module-tag --user)} 1 set {::option(module-tag --group)} 1 set {::option(module-tag --not-user)} 1 set {::option(module-tag --not-group)} 1 set ::option(module-warn) {--user --group --not-user --not-group --after\ - --before --message} + --before --message --regexp} set {::option(module-warn --user)} 1 set {::option(module-warn --group)} 1 set {::option(module-warn --not-user)} 1 set {::option(module-warn --not-group)} 1 set {::option(module-warn --after)} 1 set {::option(module-warn --before)} 1 +set {::option(module-warn --message)} 1 # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: diff --git a/tcl/mfcmd.tcl b/tcl/mfcmd.tcl index c89fd5d55..2b11d27d0 100644 --- a/tcl/mfcmd.tcl +++ b/tcl/mfcmd.tcl @@ -265,6 +265,7 @@ proc __parseDateTimeArg {opt datetime} { # parse application criteria arguments and determine if command applies proc parseApplicationCriteriaArgs {aftbef nearsec args} { set otherargs {} + set is_regexp 0 # parse argument list foreach arg $args { @@ -297,6 +298,9 @@ proc parseApplicationCriteriaArgs {aftbef nearsec args} { set nextargisval [string map {- {}} $arg]list } } + --regexp { + set is_regexp 1 + } default { lappend otherargs $arg } @@ -347,14 +351,32 @@ proc parseApplicationCriteriaArgs {aftbef nearsec args} { set afterraw {} } - return [list $apply $isnearly $afterraw $otherargs] + return [list $apply $isnearly $afterraw $otherargs $is_regexp] } -proc setModspecTag {modspec tag {props {}}} { +# parse module arguments of a module-* command: module specifications, or +# regular expressions if is_regexp is enabled, which are only checked valid +proc parseModuleSpecificationOrRegexp {is_regexp args} { + if {!$is_regexp} { + return [parseModuleSpecification 0 0 0 0 {*}$args] + } + foreach re $args { + if {[catch {regexp -- $re {}}]} { + knerror "Invalid regular expression '$re'" + } + } + return $args +} + +proc setModspecTag {modspec tag {props {}} {is_regexp 0}} { reportDebug "Set tag '$tag' with properties '$props' on module\ specification '$modspec'" - if {[isModuleFullPath $modspec]} { + if {$is_regexp} { + # no module root can be extracted from a regular expression, so these + # specs are kept apart and tested against every module + lappend ::g_moduleTagRegexp $tag $modspec $props + } elseif {[isModuleFullPath $modspec]} { # use dedicated structure for full path module specifications if {![info exists ::g_moduleTagFullPath($modspec)] || $tag ni\ $::g_moduleTagFullPath($modspec)} { @@ -401,7 +423,7 @@ proc module-forbid {args} { # parse application criteria arguments to determine if command apply lassign [parseApplicationCriteriaArgs 1 [expr {[getConf\ nearly_forbidden_days] * 86400}] {*}$args] apply isnearly after\ - otherargs + otherargs is_regexp # parse remaining argument list, do it even if command does not apply to # raise any command specification error @@ -419,7 +441,11 @@ proc module-forbid {args} { set nextargisval message } -* { - knerror "Invalid option '$arg'" + # a regular expression may start with a dash character + if {!$is_regexp} { + knerror "Invalid option '$arg'" + } + lappend modarglist $arg } default { lappend modarglist $arg @@ -446,8 +472,9 @@ proc module-forbid {args} { } # record each forbid spec after parsing them - foreach modarg [parseModuleSpecification 0 0 0 0 {*}$modarglist] { - setModspecTag $modarg forbidden $proplist + foreach modarg [parseModuleSpecificationOrRegexp $is_regexp\ + {*}$modarglist] { + setModspecTag $modarg forbidden $proplist $is_regexp } } elseif {$isnearly} { ##nagelfar ignore Found constant @@ -457,8 +484,9 @@ proc module-forbid {args} { lappend proplist message $nearlymessage } # record each nearly forbid spec after parsing them - foreach modarg [parseModuleSpecification 0 0 0 0 {*}$modarglist] { - setModspecTag $modarg nearly-forbidden $proplist + foreach modarg [parseModuleSpecificationOrRegexp $is_regexp\ + {*}$modarglist] { + setModspecTag $modarg nearly-forbidden $proplist $is_regexp } } } @@ -469,7 +497,7 @@ proc module-hide {args} { # parse application criteria arguments to determine if command apply lassign [parseApplicationCriteriaArgs 1 0 {*}$args] apply isnearly after\ - otherargs + otherargs is_regexp # parse remaining argument list, do it even if command does not apply to # raise any command specification error @@ -488,7 +516,11 @@ proc module-hide {args} { set hiddenloaded 1 } -* { - knerror "Invalid option '$arg'" + # a regular expression may start with a dash character + if {!$is_regexp} { + knerror "Invalid option '$arg'" + } + lappend modarglist $arg } default { lappend modarglist $arg @@ -503,10 +535,11 @@ proc module-hide {args} { # skip hide spec record if application criteria are not met if {$apply} { # record each hide spec after parsing them - foreach modarg [parseModuleSpecification 0 0 0 0 {*}$modarglist] { - setModspecHidingLevel $modarg $hidinglvl + foreach modarg [parseModuleSpecificationOrRegexp $is_regexp\ + {*}$modarglist] { + setModspecHidingLevel $modarg $hidinglvl $is_regexp if {$hiddenloaded} { - setModspecTag $modarg hidden-loaded + setModspecTag $modarg hidden-loaded {} $is_regexp } } } @@ -519,14 +552,18 @@ proc hide-modulefile {modfile} { proc module-tag {args} { # parse application criteria arguments to determine if command apply lassign [parseApplicationCriteriaArgs 0 0 {*}$args] apply isnearly after\ - otherargs + otherargs is_regexp # parse remaining argument list, do it even if command does not apply to # raise any command specification error foreach arg $otherargs { switch -glob -- $arg { -* { - knerror "Invalid option '$arg'" + # a regular expression may start with a dash character + if {!$is_regexp} { + knerror "Invalid option '$arg'" + } + lappend modarglist $arg } default { if {![info exists tag]} { @@ -552,8 +589,9 @@ proc module-tag {args} { # skip tag record if application criteria are not met if {$apply} { # record each hide spec after parsing them - foreach modarg [parseModuleSpecification 0 0 0 0 {*}$modarglist] { - setModspecTag $modarg $tag + foreach modarg [parseModuleSpecificationOrRegexp $is_regexp\ + {*}$modarglist] { + setModspecTag $modarg $tag {} $is_regexp } } } @@ -2546,7 +2584,7 @@ proc add-property {name value} { proc module-warn {args} { # parse application criteria arguments to determine if command apply lassign [parseApplicationCriteriaArgs 1 0 {*}$args] apply isnearly after\ - otherargs + otherargs is_regexp # parse remaining argument list, do it even if command does not apply to # raise any command specification error @@ -2561,7 +2599,11 @@ proc module-warn {args} { set nextargisval message } -* { - knerror "Invalid option '$arg'" + # a regular expression may start with a dash character + if {!$is_regexp} { + knerror "Invalid option '$arg'" + } + lappend modarglist $arg } default { lappend modarglist $arg @@ -2586,8 +2628,9 @@ proc module-warn {args} { ##nagelfar ignore Found constant set proplist [list message $message] # record each hide spec after parsing them - foreach modarg [parseModuleSpecification 0 0 0 0 {*}$modarglist] { - setModspecTag $modarg warning $proplist + foreach modarg [parseModuleSpecificationOrRegexp $is_regexp\ + {*}$modarglist] { + setModspecTag $modarg warning $proplist $is_regexp } } } diff --git a/tcl/modfind.tcl.in b/tcl/modfind.tcl.in index c564851d9..4d785080a 100644 --- a/tcl/modfind.tcl.in +++ b/tcl/modfind.tcl.in @@ -589,9 +589,27 @@ proc getModuleTag {mod full_path_mod tag} { return [list $tag $tag_props] } } + foreach {re_tag re tag_props} [getModuleRegexpTagSpecList] { + if {$re_tag eq $tag && [isModuleMatchingRegexp $re $mod]} { + return [list $tag $tag_props] + } + } return {} } +proc getModuleRegexpTagSpecList {} { + return [expr {[info exists ::g_moduleTagRegexp] ? $::g_moduleTagRegexp :\ + {}}] +} + +# test if name and version of module matches regular expression. variants of +# mod are ignored. +proc isModuleMatchingRegexp {re mod} { + set mod [getModuleNameAndVersFromVersSpec $mod] + return [expr {[isIcase] ? [regexp -nocase -- $re $mod] : [regexp -- $re\ + $mod]}] +} + proc getModuleTagRuleList {mod full_path_mod tag} { set rule_list {} lassign [getFullPathModuleTagSpec $full_path_mod $tag] tag_mod_spec\ @@ -694,6 +712,11 @@ proc getMatchingTagList {mod {known_tag_list {}}} { } } } + foreach {tag re tprops} [getModuleRegexpTagSpecList] { + if {$tag ni $tag_list && [isModuleMatchingRegexp $re $mod]} { + lappend tag_list $tag + } + } return $tag_list } @@ -1116,6 +1139,14 @@ proc getModuleHidingLevel {mod fpmod} { ::g_moduleHideFullPath($fpmod)] ? $::g_moduleHideFullPath($fpmod) :\ {-1}}] + if {[info exists ::g_moduleHideRegexp]} { + foreach {re lvl} $::g_moduleHideRegexp { + if {$lvl > $baselvl && [isModuleMatchingRegexp $re $mod]} { + set baselvl $lvl + } + } + } + set modroot [lindex [file split $mod] 0] # look if mod matches one of the hidden module specs applying to mod root if {[info exists ::g_moduleHideRoot($modroot)]} { @@ -1135,7 +1166,13 @@ proc getModuleHidingLevel {mod fpmod} { return $baselvl } -proc setModspecHidingLevel {modspec lvl} { +proc setModspecHidingLevel {modspec lvl {is_regexp 0}} { + if {$is_regexp} { + reportDebug "Record hidden module regular expression '$modspec'\ + (lvl=$lvl)" + lappend ::g_moduleHideRegexp $modspec $lvl + return + } # skip record if an higher hiding level is already set if {![info exists ::g_moduleHide($modspec)] || $lvl >\ $::g_moduleHide($modspec)} { diff --git a/testsuite/modulefiles.4/tag/.modulerc b/testsuite/modulefiles.4/tag/.modulerc index 328a46b8e..1fb0ddc44 100644 --- a/testsuite/modulefiles.4/tag/.modulerc +++ b/testsuite/modulefiles.4/tag/.modulerc @@ -158,5 +158,70 @@ if {[info exists env(TESTSUITE_FPMOD_TAG)]} { module-tag super-sticky [file dirname $ModulesCurrentModulefile] module-virtual tag/1.1 ./1.0 } + regexp1 { + module-hide --regexp {^tag/2\.} + } + regexp2 { + module-hide --hard --regexp {/2\.1$} + } + regexp3 { + module-hide --regexp {2\.0} --hidden-loaded + } + regexp4 { + module-forbid --message my-forbid-msg {^tag/2} --regexp {^tag/1\.0$} {-unk$} + } + regexp5 { + set tomorrow [clock format [expr {[clock seconds]+86400}] -format %Y-%m-%d] + module-forbid --nearly-message my-nearly-forbid-msg --after $tomorrow\ + --regexp {^tag/2} + } + regexp6 { + module-tag --regexp foo {^TAG/1} {-unk$} + module-tag bar {\.[01]$} {^tag} --regexp + module-tag foo --regexp {/2\.1} + } + regexp7 { + module-warn --regexp {-unk$} {^tag/[12]\.0$} --message my-warn-msg + } + regexp8 { + module-hide --regexp {tag/(2} + } + regexp9 { + module-forbid --regexp + } + regexp10 { + module-tag --regexp {tag/2} + } + regexp11 { + module-tag sticky --regexp {^tag/} + } + regexp12 { + module-hide --soft --regexp {^tag/2} + module-hide --regexp {^tag/2\.1} + module-hide --hard tag/2.1 + } + regexp13 { + module-hide --regexp {^tag/2} --user unknownuser + module-tag foo --not-group unknowngroup --regexp {^tag/1} + } + regexp14 { + module-forbid --message my-forbid-msg1 --regexp {^tag/2} + module-forbid --message my-forbid-msg2 --regexp {^tag/2\.0} + module-forbid --message my-forbid-msg3 tag/2.1 + } + regexp15 { + module-hide --regexp {-?2\.0$} + } + regexp16 { + module-hide --regexp --sotf {^tag/2} + } + regexp17 { + module-hide --hard {^tag/2} --regexp --user unknownuser {tag/(1} + } + regexp18 { + module-hide --regexp {^TAG/2\.0} + module-forbid --regexp {^TAG/2\.1} --message my-forbid-msg + module-warn --regexp {^TAG/1\.0$} --message my-warn-msg + } } } diff --git a/testsuite/modulefiles.lint/tag/.modulerc b/testsuite/modulefiles.lint/tag/.modulerc index 1e8b01232..fc069a4c6 100644 --- a/testsuite/modulefiles.lint/tag/.modulerc +++ b/testsuite/modulefiles.lint/tag/.modulerc @@ -11,3 +11,7 @@ if {[info exists env(TESTSUITE_LINT_TAGERR)]} { module-tag --before 2020-11-01 foo tag/5.0 module-tag --after 2020-11-01 foo tag/5.0 } +module-tag bar --regexp {^tag/5} +module-forbid --regexp {^tag/6} {-old$} +module-warn --regexp --message {text} {-old$} --user foo +module-hide {-old$} --regexp --hard diff --git a/testsuite/modulefiles.lint/tag/5.0 b/testsuite/modulefiles.lint/tag/5.0 index 1c148cdd2..06ee0e442 100644 --- a/testsuite/modulefiles.lint/tag/5.0 +++ b/testsuite/modulefiles.lint/tag/5.0 @@ -1 +1,2 @@ #%Module +module-warn --regexp --message {text} {-old$} diff --git a/testsuite/modules.20-locate/142-regexp.exp b/testsuite/modules.20-locate/142-regexp.exp new file mode 100644 index 000000000..6e6a1d8a7 --- /dev/null +++ b/testsuite/modules.20-locate/142-regexp.exp @@ -0,0 +1,390 @@ +############################################################################## +# Modules Revision 3.0 +# Providing a flexible user environment +# +# File: modules.20-locate/%M% +# Revision: %I% +# First Edition: 2026/11/16 +# Last Mod.: %U%, %G% +# +# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr +# +# Description: Testuite testsequence +# Command: +# Modulefiles: tag +# Sub-Command: avail, load, unload, switch +# +# Comment: %C{ +# Check --regexp option of module-hide, module-forbid, +# module-tag and module-warn modulefile commands +# }C% +# +############################################################################## + +skip_if_quick_mode + +set mp $modpath.4 +set mpre $modpathre.4 + +# setup specific environment +setenv_path_var MODULEPATH $mp + +# ensure we get nearly-forbidden notices +setenv_var MODULES_NEARLY_FORBIDDEN_DAYS 4 + +# ensure default tag abbreviation is defined +setenv_var MODULES_TAG_ABBREV {auto-loaded=aL:loaded=L:hidden=H:hidden-loaded=H:forbidden=F:nearly-forbidden=nF:sticky=S:super-sticky=sS:keep-loaded=kL:warning=W} + +# ensure expected results whatever the default configuration +setenv_var MODULES_AVAIL_INDEPTH 1 +setenv_var MODULES_IMPLICIT_DEFAULT 1 +setenv_var MODULES_ADVANCED_VERSION_SPEC 1 +setenv_var MODULES_SEARCH_MATCH starts_with + +# regular expressions are matched in a case sensitive way unless stated +setenv_var MODULES_ICASE never + +set rcfile $mp/tag/.modulerc + + +# +# module-hide +# + +setenv_var TESTSUITE_FPMOD_TAG regexp1 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0" +testouterr_cmd sh {avail -t tag} OK $tserr + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +testouterr_cmd sh {avail -t -a tag} OK $tserr + +# hidden module is unveiled when precisely designated +set tserr "$mp: +tag/2.1 " +testouterr_cmd sh {avail -t tag/2.1} OK $tserr + +set ans [list] +lappend ans [list set __MODULES_LMALTNAME tag/2.0&as|tag/default&as|tag/latest] +lappend ans [list set _LMFILES_ $mp/tag/2.0] +lappend ans [list set LOADEDMODULES tag/2.0] +testouterr_cmd sh {load tag/2.0} $ans {} + +# hidden modules are not selected as default version +set ans [list] +lappend ans [list set __MODULES_LMALTNAME tag/1.2.sub/1.0&as|tag/default&as|tag/latest&as|tag/1.2.sub/default&as|tag/1.2.sub/latest] +lappend ans [list set _LMFILES_ $mp/tag/1.2.sub/1.0] +lappend ans [list set LOADEDMODULES tag/1.2.sub/1.0] +testouterr_cmd sh {load tag} $ans {} + +# hard hiding +setenv_var TESTSUITE_FPMOD_TAG regexp2 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0" +testouterr_cmd sh {avail -t -a tag} OK $tserr + +testouterr_cmd sh {load tag/2.1} ERR [err_unablelocate tag/2.1] + +# hidden once loaded +setenv_var TESTSUITE_FPMOD_TAG regexp3 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1" +testouterr_cmd sh {avail -t -a tag} OK $tserr + +set ans [list] +lappend ans [list set _LMFILES_ $mp/tag/2.0] +lappend ans [list set LOADEDMODULES tag/2.0] +lappend ans [list set __MODULES_LMTAG tag/2.0&hidden-loaded] +testouterr_cmd sh {load tag/2.0} $ans {} + +# regular expression starting with dash character +setenv_var TESTSUITE_FPMOD_TAG regexp15 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1" +testouterr_cmd sh {avail -t -a tag} OK $tserr + +# unknown option is considered a regular expression +setenv_var TESTSUITE_FPMOD_TAG regexp16 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +testouterr_cmd sh {avail -t -a tag} OK $tserr + +# highest hiding level among matching regular expressions and regular module +# specifications applies +setenv_var TESTSUITE_FPMOD_TAG regexp12 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0" +testouterr_cmd sh {avail -t tag} OK $tserr +testouterr_cmd sh {avail -t -a tag} OK $tserr + +# application criteria not met +setenv_var TESTSUITE_FPMOD_TAG regexp13 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1" +testouterr_cmd sh {avail -t tag} OK $tserr + +# like module specifications, regular expressions are not checked when +# application criteria are not met +setenv_var TESTSUITE_FPMOD_TAG regexp17 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1" +testouterr_cmd sh {avail -t -a tag} OK $tserr + + +# +# module-forbid +# + +# several regular expressions +setenv_var TESTSUITE_FPMOD_TAG regexp4 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +testouterr_cmd sh {avail -t tag} OK $tserr + +testouterr_cmd sh {load tag/2.1} ERR [err_accessdenied tag/2.1 my-forbid-msg] +testouterr_cmd sh {load tag/1.0} ERR [err_accessdenied tag/1.0 my-forbid-msg] + +# nearly forbidden +setenv_var TESTSUITE_FPMOD_TAG regexp5 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +testouterr_cmd sh {avail -t tag} OK $tserr + +set ans [list] +lappend ans [list set __MODULES_LMALTNAME tag/2.1&as|tag/default&as|tag/latest] +lappend ans [list set _LMFILES_ $mp/tag/2.1] +lappend ans [list set LOADEDMODULES tag/2.1] +lappend ans [list set __MODULES_LMTAG tag/2.1&nearly-forbidden] +set tomorrow [clock format [expr {[clock seconds]+86400}] -format %Y-%m-%d] +set tserr [msg_load {tag/2.1 } [err_accessnearlydenied $tomorrow my-nearly-forbid-msg]] +testouterr_cmd sh {load tag/2.1} $ans $tserr + +# first matching regular expression wins, regular module specification has +# precedence over regular expressions +setenv_var TESTSUITE_FPMOD_TAG regexp14 + +testouterr_cmd sh {load tag/2.0} ERR [err_accessdenied tag/2.0 my-forbid-msg1] +testouterr_cmd sh {load tag/2.1} ERR [err_accessdenied tag/2.1 my-forbid-msg3] + + +# +# module-tag +# + +setenv_var TESTSUITE_FPMOD_TAG regexp6 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +testouterr_cmd sh {avail -t tag} OK $tserr + +set ans [list] +lappend ans [list set _LMFILES_ $mp/tag/1.0] +lappend ans [list set LOADEDMODULES tag/1.0] +lappend ans [list set __MODULES_LMTAG tag/1.0&bar] +testouterr_cmd sh {load tag/1.0} $ans {} + +# case insensitive match +setenv_var MODULES_ICASE search + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +testouterr_cmd sh {avail -t tag} OK $tserr +testouterr_cmd sh {load tag/1.0} $ans {} + +setenv_var MODULES_ICASE always + +set ans [list] +lappend ans [list set _LMFILES_ $mp/tag/1.0] +lappend ans [list set LOADEDMODULES tag/1.0] +lappend ans [list set __MODULES_LMTAG tag/1.0&foo&bar] +testouterr_cmd sh {load tag/1.0} $ans {} + +setenv_var MODULES_ICASE never + +# stickiness set with a regular expression is only satisfied by the reload +# of the same module +setenv_var TESTSUITE_FPMOD_TAG regexp11 + +set ans [list] +lappend ans [list set _LMFILES_ $mp/tag/1.0] +lappend ans [list set LOADEDMODULES tag/1.0] +lappend ans [list set __MODULES_LMTAG tag/1.0&sticky] +testouterr_cmd sh {load tag/1.0} $ans {} + +setenv_loaded_module [list tag/1.0] [list $mp/tag/1.0] +setenv_var __MODULES_LMTAG tag/1.0&sticky + +set tserr [msg_unload {tag/1.0 } $err_stickyunload] +testouterr_cmd sh {unload tag/1.0} ERR $tserr + +set tserr [msg_unload {tag/1.0 } $err_stickyunload]\n\n[msg_switch {tag/1.0 } tag/2.0 [err_swoff tag/1.0]] +testouterr_cmd sh {switch tag/1.0 tag/2.0} ERR $tserr + +testouterr_cmd sh {switch tag/1.0 tag/1.0} $ans {} + +unsetenv_loaded_module +unsetenv_var __MODULES_LMTAG + + +# +# module-warn +# + +setenv_var TESTSUITE_FPMOD_TAG regexp7 + +set tserr "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1" +testouterr_cmd sh {avail -t tag} OK $tserr + +set ans [list] +lappend ans [list set _LMFILES_ $mp/tag/1.0] +lappend ans [list set LOADEDMODULES tag/1.0] +lappend ans [list set __MODULES_LMTAG tag/1.0&warning] +set tserr [msg_load {tag/1.0 } "$warn_msgs: my-warn-msg"] +testouterr_cmd sh {load tag/1.0} $ans $tserr + + +# +# case sensitivity of module-hide, module-forbid and module-warn +# + +setenv_var TESTSUITE_FPMOD_TAG regexp18 + +set ans_load21 [list] +lappend ans_load21 [list set __MODULES_LMALTNAME tag/2.1&as|tag/default&as|tag/latest] +lappend ans_load21 [list set _LMFILES_ $mp/tag/2.1] +lappend ans_load21 [list set LOADEDMODULES tag/2.1] +set ans_load10 [list] +lappend ans_load10 [list set _LMFILES_ $mp/tag/1.0] +lappend ans_load10 [list set LOADEDMODULES tag/1.0] +set ans_load10_warn $ans_load10 +lappend ans_load10_warn [list set __MODULES_LMTAG tag/1.0&warning] + +set tserr_avail_sensitive "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1" +set tserr_avail_icase "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.1 " +set tserr_avail_all_icase "$mp: +tag/1.0 +tag/1.2.sub/1.0 +tag/2.0 +tag/2.1 " +set tserr_load10_warn [msg_load {tag/1.0 } "$warn_msgs: my-warn-msg"] +set tserr_load21_forbid [err_accessdenied tag/2.1 my-forbid-msg] + +# case sensitive match +testouterr_cmd sh {avail -t tag} OK $tserr_avail_sensitive +testouterr_cmd sh {avail -t -a tag} OK $tserr_avail_sensitive +testouterr_cmd sh {load tag/2.1} $ans_load21 {} +testouterr_cmd sh {load tag/1.0} $ans_load10 {} + +# case insensitive match on search contexts only +setenv_var MODULES_ICASE search + +testouterr_cmd sh {avail -t tag} OK $tserr_avail_icase +testouterr_cmd sh {avail -t -a tag} OK $tserr_avail_all_icase +testouterr_cmd sh {load tag/2.1} $ans_load21 {} +testouterr_cmd sh {load tag/1.0} $ans_load10 {} + +# case insensitive match on all contexts +setenv_var MODULES_ICASE always + +testouterr_cmd sh {avail -t tag} OK $tserr_avail_icase +testouterr_cmd sh {avail -t -a tag} OK $tserr_avail_all_icase +testouterr_cmd sh {load tag/2.1} ERR $tserr_load21_forbid +testouterr_cmd sh {load tag/1.0} $ans_load10_warn $tserr_load10_warn + +# case insensitive match enabled from command line +setenv_var MODULES_ICASE never + +testouterr_cmd sh {avail -t -i tag} OK $tserr_avail_icase +testouterr_cmd sh {avail -t -a --icase tag} OK $tserr_avail_all_icase +testouterr_cmd sh {load -i tag/2.1} ERR $tserr_load21_forbid +testouterr_cmd sh {load --icase tag/1.0} $ans_load10_warn $tserr_load10_warn + + +# +# bad specifications +# + +set ans [list] +lappend ans [list set _LMFILES_ $mp/tag/1.0] +lappend ans [list set LOADEDMODULES tag/1.0] +lappend ans [list ERR] + +setenv_var TESTSUITE_FPMOD_TAG regexp8 + +set tserr [escre [msg_moderr {Invalid regular expression 'tag/(2'} {module-hide --regexp {tag/(2}"} $rcfile 2 { }]] +testouterr_cmd_re sh {load tag/1.0} $ans $tserr + +setenv_var TESTSUITE_FPMOD_TAG regexp9 + +set tserr [escre [msg_moderr {No module specified in argument} {module-forbid --regexp"} $rcfile 2 { }]] +testouterr_cmd_re sh {load tag/1.0} $ans $tserr + +setenv_var TESTSUITE_FPMOD_TAG regexp10 + +# single argument is the tag name +set tserr [escre [msg_moderr {No module specified in argument} {module-tag --regexp {tag/2}"} $rcfile 2 { }]] +testouterr_cmd_re sh {load tag/1.0} $ans $tserr + + +# +# Cleanup +# + +reset_test_env From 78f81f49779e1441e80ff6110ce698dd517a3132 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 17 Nov 2026 08:10:53 -0600 Subject: [PATCH 3/3] Add module-hide-regex and module-forbid-regex commands Lmod provides the module-hide-regex and module-forbid-regex commands in its Tcl modulerc files to hide or forbid the modules matching a regular expression. A modulerc file using them raises an unknown command error when evaluated by Modules. Add these two commands as aliases of module-hide and module-forbid with --regexp option set, like hide-version and hide-modulefile are aliases of module-hide. They accept the same options than the command they rely on. Expressions are Tcl regular expressions whereas they are Lua patterns on Lmod. No translation is made between these syntaxes: expressions using constructs specific to Lua patterns have to be adapted. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- MIGRATING.rst | 4 + NEWS.rst | 4 + doc/source/changes.rst | 3 +- .../design/lmod-tcl-modulefile-compat.rst | 35 ++++++++ doc/source/modulefile.rst | 40 ++++++++- doc/source/other-implementations.rst | 5 +- share/emacs/lisp/modulefile-mode.el | 2 +- share/nagelfar/plugin_modulerc.tcl | 13 +-- share/nagelfar/syntaxdb_modulerc.tcl | 24 ++++++ share/vim/syntax/modulefile.vim | 3 +- tcl/interp.tcl.in | 7 +- tcl/mfcmd.tcl | 8 ++ testsuite/modulefiles.4/hide/.modulerc | 25 ++++++ testsuite/modulefiles.lint/tag/.modulerc | 2 + testsuite/modules.20-locate/150-lmod-hide.exp | 81 +++++++++++++++++++ 15 files changed, 241 insertions(+), 15 deletions(-) diff --git a/MIGRATING.rst b/MIGRATING.rst index 7df49c5c0..39aab8e41 100644 --- a/MIGRATING.rst +++ b/MIGRATING.rst @@ -123,6 +123,10 @@ When ``--regexp`` option is set, all the module arguments of the command are regular expressions. See the :ref:`Regular expression module selection` section for details. +The :mfcmd:`module-hide-regex` and :mfcmd:`module-forbid-regex` commands are +also introduced as aliases of :mfcmd:`module-hide` and :mfcmd:`module-forbid` +with ``--regexp`` option set. + v5.7 ---- diff --git a/NEWS.rst b/NEWS.rst index 42f520e9c..1024483e5 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -69,6 +69,10 @@ Modules 5.8.0 (not yet released) :mfcmd:`module-tag` and :mfcmd:`module-warn` modulefile commands to designate the modules they apply to with a regular expression matched against module name and version. +* Add :mfcmd:`module-forbid-regex` and :mfcmd:`module-hide-regex` modulerc + commands to support modulerc files written for Lmod. They are aliases of + :mfcmd:`module-forbid` and :mfcmd:`module-hide` with ``--regexp`` option + set. .. _5.7 release notes: diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 1c800d6b5..5924cb2ca 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -1187,7 +1187,8 @@ The following modulefile Tcl commands appeared on Modules 5. | 5.7 | :mfcmd:`modulepath-ignore` | +------------+-----------------------------------------------------------------+ | 5.8 | :mfcmd:`module-info modulename`, | -| | :mfcmd:`module-info moduleversion` | +| | :mfcmd:`module-info moduleversion`, | +| | :mfcmd:`module-forbid-regex`, :mfcmd:`module-hide-regex` | +------------+-----------------------------------------------------------------+ :mfcmd:`system`, :mfcmd:`is-used` diff --git a/doc/source/design/lmod-tcl-modulefile-compat.rst b/doc/source/design/lmod-tcl-modulefile-compat.rst index 6ee9e270d..cda7543ab 100644 --- a/doc/source/design/lmod-tcl-modulefile-compat.rst +++ b/doc/source/design/lmod-tcl-modulefile-compat.rst @@ -25,6 +25,8 @@ Lmod Tcl modulefile compatibility - ``family`` - ``hide-version`` - ``hide-modulefile`` + - ``module-hide-regex`` + - ``module-forbid-regex`` - See :ref:`Compatibility with Lmod Tcl modulefile` section in :ref:`modulefile(5)` man page for the current state of support. @@ -398,6 +400,39 @@ Lmod Tcl modulefile compatibility (not within modulefile) +``module-hide-regex``/``module-forbid-regex`` +--------------------------------------------- + +- Hide or forbid the modules whose name and version match a regular + expression. + +- Accept the same options than :mfcmd:`module-hide` and + :mfcmd:`module-forbid` respectively, and one or several regular expressions + +- These two commands are implemented by simply calling :mfcmd:`module-hide` + or :mfcmd:`module-forbid` with their ``--regexp`` option set + + - No specific code, behavior is the one described for ``--regexp`` option in + :ref:`module-tags` design notes + - As a consequence, an argument starting with ``-`` that is not a known + option is considered a regular expression, which is also the behavior of + Lmod for these commands + +- Regular expressions are Tcl regular expressions on Modules whereas they are + Lua patterns on Lmod + + - No translation is attempted between the two syntaxes + - Simple expressions have the same meaning on both tools: literal + characters, ``^`` and ``$`` anchors, ``.``, ``*``, ``+``, ``?`` and + bracket expressions like ``[Ff]`` + - Others have to be adapted: Lua escapes special characters with ``%`` + where Tcl uses ``\``, ``-`` is a quantifier in Lua, ``|`` alternation and + ``{}`` bounds do not exist in Lua + +- These commands are intended for use only within modulerc evaluation context + (not within modulefile) + + ``--mode`` option ----------------- diff --git a/doc/source/modulefile.rst b/doc/source/modulefile.rst index b0b5eab33..45f733f51 100644 --- a/doc/source/modulefile.rst +++ b/doc/source/modulefile.rst @@ -718,6 +718,17 @@ the *modulefile* is being loaded. .. versionchanged:: 5.8 Option ``--regexp`` added +.. mfcmd:: module-forbid-regex [options] pattern... + + Alias of :mfcmd:`module-forbid --regexp` command: forbid use + of the modules whose name and version match one of the *pattern* regular + expressions. All the options of :mfcmd:`module-forbid` are accepted. See + `Regular expression module selection`_ section below. + + .. only:: html or latex + + .. versionadded:: 5.8 + .. mfcmd:: module-help string Defines a string which is displayed in case of the invocation of the @@ -850,6 +861,17 @@ the *modulefile* is being loaded. .. versionchanged:: 5.8 Option ``--regexp`` added +.. mfcmd:: module-hide-regex [options] pattern... + + Alias of :mfcmd:`module-hide --regexp` command: hide the + modules whose name and version match one of the *pattern* regular + expressions. All the options of :mfcmd:`module-hide` are accepted. See + `Regular expression module selection`_ section below. + + .. only:: html or latex + + .. versionadded:: 5.8 + .. mfcmd:: module-info option [info-args] Provide information about the :file:`modulecmd.tcl` program's state. Some of @@ -1994,7 +2016,8 @@ for each interpretation context. | and standard Tcl commands | :mfcmd:`hide-version`, :mfcmd:`is-loaded`, | | | :mfcmd:`is-used`, :mfcmd:`lsb-release`, | | | :mfcmd:`module-alias`, :mfcmd:`module-forbid`, | -| | :mfcmd:`module-hide`, :mfcmd:`module-info`, | +| | :mfcmd:`module-forbid-regex`, :mfcmd:`module-hide`, | +| | :mfcmd:`module-hide-regex`, :mfcmd:`module-info`, | | | :mfcmd:`module-tag`, :mfcmd:`module-version`, | | | :mfcmd:`module-virtual`, :mfcmd:`module-warn`, | | | :mfcmd:`modulepath-ignore`, | @@ -2417,6 +2440,10 @@ module matching this regular expression. An error is raised if an argument is not a valid regular expression. +The :mfcmd:`module-forbid-regex` and :mfcmd:`module-hide-regex` commands are +respectively equivalent to :mfcmd:`module-forbid` and :mfcmd:`module-hide` +with ``--regexp`` option set. + .. only:: html or latex .. versionadded:: 5.8 @@ -2606,6 +2633,13 @@ user to determine whether :envvar:`MODULEPATH` is updated. The :mfcmd:`break` command does not accept any argument. A ``msg`` argument can be set on Lmod to provide a customized break error message. +The arguments of the :mfcmd:`module-forbid-regex` and +:mfcmd:`module-hide-regex` commands are Tcl regular expressions on Modules +whereas they are Lua patterns on Lmod. Simple expressions have the same +meaning on both tools (e.g., ``^foo/2`` or ``foo/.*``). Others have to be +adapted, like special characters that are escaped with ``%`` on Lmod and with +``\`` on Modules (e.g., ``foo%-app`` should be written ``foo\-app``). + The :mfcmd:`setenv`, :mfcmd:`unsetenv`, :mfcmd:`prepend-path`, :mfcmd:`append-path`, :mfcmd:`remove-path`, :mfcmd:`pushenv` and ``module`` :mfcmd:`load`, :mfcmd:`load-any`, :mfcmd:`try-load` @@ -2676,6 +2710,10 @@ the dependent module will get automatically reloaded. Modulefile commands :mfcmd:`add-property`, :mfcmd:`depends-on-any` and :mfcmd:`haveDynamicMPATH` implemented + .. versionchanged:: 5.8 + Modulefile commands :mfcmd:`module-forbid-regex` and + :mfcmd:`module-hide-regex` implemented + .. _Shell support: Shell support diff --git a/doc/source/other-implementations.rst b/doc/source/other-implementations.rst index c1557d327..ccca33592 100644 --- a/doc/source/other-implementations.rst +++ b/doc/source/other-implementations.rst @@ -115,7 +115,7 @@ the end of this section to map these equivalents. * - |lmod_version| - |modules_version| - * - ``module-forbid-regex``, ``module-hide-regex``, ``remove-property`` + * - ``remove-property`` - :mfcmd:`getvariant`, :mfcmd:`is-saved`, :mfcmd:`is-used`, :mfcmd:`lsb-release`, :mfcmd:`module-tag`, :mfcmd:`module-warn`, :mfcmd:`modulepath-ignore`, :mfcmd:`modulepath-label`, @@ -147,9 +147,6 @@ implementation. - :ref:`Change modulefile command behavior` * - `NAG file`_ - :mfcmd:`module-forbid`, :mfcmd:`module-warn` modulefile commands - * - ``module-forbid-regex``, ``module-hide-regex`` modulefile commands - - ``--regexp`` option of :mfcmd:`module-forbid` and :mfcmd:`module-hide` - modulefile commands * - Lmod + `XALT`_ - :ref:`Logging activity` * - `Hook functions`_ diff --git a/share/emacs/lisp/modulefile-mode.el b/share/emacs/lisp/modulefile-mode.el index 1b0af0957..90ecd8115 100644 --- a/share/emacs/lisp/modulefile-mode.el +++ b/share/emacs/lisp/modulefile-mode.el @@ -48,7 +48,7 @@ (define-derived-mode modulefile-mode tcl-mode "Modulefile" "Major mode for editing Modulefile scripts." (font-lock-add-keywords 'modulefile-mode - '(("\\<\\(add-property\\|always-load\\|append-path\\|chdir\\|complete\\|conflict\\|depends-on-any\\|depends-on\\|extensions\\|family\\|getenv\\|getvariant\\|haveDynamicMPATH\\|hide-modulefile\\|hide-version\\|is-avail\\|is-loaded\\|is-saved\\|is-used\\|lsb-release\\|module-alias\\|module-forbid\\|module-help\\|module-hide\\|module-info\\|module-tag\\|module-version\\|module-virtual\\|module-warn\\|module-whatis\\|module\\|modulepath-ignore\\|modulepath-label\\|prepend-path\\|prereq-all\\|prereq-any\\|prereq\\|provide\\|pushenv\\|remove-path\\|reportError\\|reportWarning\\|require-fullname\\|set-alias\\|set-function\\|setenv\\|source-sh\\|system\\|uname\\|uncomplete\\|unset-alias\\|unset-function\\|unsetenv\\|variant\\|versioncmp\\|x-resource\\)\\>" . font-lock-keyword-face)) + '(("\\<\\(add-property\\|always-load\\|append-path\\|chdir\\|complete\\|conflict\\|depends-on-any\\|depends-on\\|extensions\\|family\\|getenv\\|getvariant\\|haveDynamicMPATH\\|hide-modulefile\\|hide-version\\|is-avail\\|is-loaded\\|is-saved\\|is-used\\|lsb-release\\|module-alias\\|module-forbid-regex\\|module-forbid\\|module-help\\|module-hide-regex\\|module-hide\\|module-info\\|module-tag\\|module-version\\|module-virtual\\|module-warn\\|module-whatis\\|module\\|modulepath-ignore\\|modulepath-label\\|prepend-path\\|prereq-all\\|prereq-any\\|prereq\\|provide\\|pushenv\\|remove-path\\|reportError\\|reportWarning\\|require-fullname\\|set-alias\\|set-function\\|setenv\\|source-sh\\|system\\|uname\\|uncomplete\\|unset-alias\\|unset-function\\|unsetenv\\|variant\\|versioncmp\\|x-resource\\)\\>" . font-lock-keyword-face)) ) (font-lock-add-keywords 'modulefile-mode '(("\\<\\(ModulesVersion\\|ModulesCurrentModulefile\\|ModuleToolVersion\\|ModuleVariant\\|ModuleTool\\)\\>" . font-lock-preprocessor-face)) diff --git a/share/nagelfar/plugin_modulerc.tcl b/share/nagelfar/plugin_modulerc.tcl index 7bf4a7d30..da8c308fc 100644 --- a/share/nagelfar/plugin_modulerc.tcl +++ b/share/nagelfar/plugin_modulerc.tcl @@ -38,16 +38,19 @@ proc statementRaw {stmt info} { if {[regexp {^(module-forbid|module-hide|module-tag|module-warn)\s}\ $stmt]} { set res [stripRegexpLeadingDash $stmt] + } elseif {[regexp {^(module-forbid-regex|module-hide-regex)\s} $stmt]} { + set res [stripRegexpLeadingDash $stmt 1] } return $res } -# when --regexp option is set, module arguments are regular expressions that -# may start with a dash character. Nagelfar would report them as bad options, -# so this leading dash is removed unless argument looks like a long option -proc stripRegexpLeadingDash {stmt} { +# when --regexp option is set or implied (is_regexp), module arguments are +# regular expressions that may start with a dash character. Nagelfar would +# report them as bad options, so this leading dash is removed unless argument +# looks like a long option +proc stripRegexpLeadingDash {stmt {is_regexp 0}} { set res {} - if {[regexp {\s--regexp(\s|$)} $stmt] && [regsub -all\ + if {($is_regexp || [regexp {\s--regexp(\s|$)} $stmt]) && [regsub -all\ {(\s[\{"]?)-(?!-[a-z])} $stmt {\1} newstmt]} { set res [list replace $newstmt] } diff --git a/share/nagelfar/syntaxdb_modulerc.tcl b/share/nagelfar/syntaxdb_modulerc.tcl index 13ba22ac2..2c5b6daf7 100644 --- a/share/nagelfar/syntaxdb_modulerc.tcl +++ b/share/nagelfar/syntaxdb_modulerc.tcl @@ -31,7 +31,9 @@ is-used lsb-release module-alias module-forbid +module-forbid-regex module-hide +module-hide-regex module-info module-tag module-version @@ -53,8 +55,12 @@ set ::syntax(lsb-release) s set ::syntax(module-alias) 2 # module-forbid accepts option at any position set ::syntax(module-forbid) {o* x o* x* o*} +# module-forbid-regex accepts option at any position +set ::syntax(module-forbid-regex) {o* x o* x* o*} # module-hide accepts option at any position set ::syntax(module-hide) {o* x o* x* o*} +# module-hide-regex accepts option at any position +set ::syntax(module-hide-regex) {o* x o* x* o*} set ::syntax(module-info) {s x?} set {::syntax(module-info alias)} 1 set {::syntax(module-info command)} x? @@ -114,6 +120,16 @@ set {::option(module-forbid --after)} 1 set {::option(module-forbid --before)} 1 set {::option(module-forbid --message)} 1 set {::option(module-forbid --nearly-message)} 1 +set ::option(module-forbid-regex) {--user --group --not-user --not-group\ + --after --before --message --nearly-message} +set {::option(module-forbid-regex --user)} 1 +set {::option(module-forbid-regex --group)} 1 +set {::option(module-forbid-regex --not-user)} 1 +set {::option(module-forbid-regex --not-group)} 1 +set {::option(module-forbid-regex --after)} 1 +set {::option(module-forbid-regex --before)} 1 +set {::option(module-forbid-regex --message)} 1 +set {::option(module-forbid-regex --nearly-message)} 1 set ::option(module-hide) {--user --group --not-user --not-group --after\ --before --soft --hard --hidden-loaded --regexp} set {::option(module-hide --user)} 1 @@ -122,6 +138,14 @@ set {::option(module-hide --not-user)} 1 set {::option(module-hide --not-group)} 1 set {::option(module-hide --after)} 1 set {::option(module-hide --before)} 1 +set ::option(module-hide-regex) {--user --group --not-user --not-group\ + --after --before --soft --hard --hidden-loaded} +set {::option(module-hide-regex --user)} 1 +set {::option(module-hide-regex --group)} 1 +set {::option(module-hide-regex --not-user)} 1 +set {::option(module-hide-regex --not-group)} 1 +set {::option(module-hide-regex --after)} 1 +set {::option(module-hide-regex --before)} 1 set ::option(module-tag) {--user --group --not-user --not-group --regexp} set {::option(module-tag --user)} 1 set {::option(module-tag --group)} 1 diff --git a/share/vim/syntax/modulefile.vim b/share/vim/syntax/modulefile.vim index 62be8640e..fcea93dde 100644 --- a/share/vim/syntax/modulefile.vim +++ b/share/vim/syntax/modulefile.vim @@ -18,7 +18,8 @@ syn keyword modCommand add-property always-load append-path chdir complete conf syn keyword modCommand depends-on depends-on-any extensions family getenv getvariant syn keyword modCommand haveDynamicMPATH hide-modulefile hide-version is-avail is-loaded syn keyword modCommand is-saved is-used lsb-release module module-alias module-forbid -syn keyword modCommand module-help module-hide module-info module-tag module-version +syn keyword modCommand module-forbid-regex module-help module-hide module-hide-regex +syn keyword modCommand module-info module-tag module-version syn keyword modCommand module-virtual module-warn module-whatis modulepath-ignore modulepath-label syn keyword modCommand prepend-path prereq prereq-all prereq-any provide pushenv syn keyword modCommand remove-path reportError reportWarning require-fullname set-alias diff --git a/tcl/interp.tcl.in b/tcl/interp.tcl.in index c4ac809fa..a7ee71aed 100644 --- a/tcl/interp.tcl.in +++ b/tcl/interp.tcl.in @@ -105,7 +105,7 @@ proc initModfileModeAliases {mode auto aliasesVN aliasesPassArgVN\ # the evaluation mode set ::g_modfileEvalModes {load unload display help test whatis refresh\ scan} - ##nagelfar ignore #50 Too long line + ##nagelfar ignore #52 Too long line array set g_modfilePerModeAliases { add-property {add-property nop reportCmd nop nop nop nop nop} always-load {always-load nop reportCmd nop nop nop nop always-load-sc} @@ -129,8 +129,10 @@ module-verbosity {nimp nimp reportCmd nop nop module-version {module-version module-version module-version module-version module-version module-version nop nop } module-virtual {module-virtual module-virtual module-virtual module-virtual module-virtual module-virtual nop nop } module-forbid {module-forbid module-forbid module-forbid module-forbid module-forbid module-forbid nop nop } +module-forbid-regex {module-forbid-regex module-forbid-regex module-forbid-regex module-forbid-regex module-forbid-regex module-forbid-regex nop nop} module-help {nop nop reportCmd module-help nop nop nop nop } module-hide {module-hide module-hide module-hide module-hide module-hide module-hide nop nop } +module-hide-regex {module-hide-regex module-hide-regex module-hide-regex module-hide-regex module-hide-regex module-hide-regex nop nop } module-tag {module-tag module-tag module-tag module-tag module-tag module-tag nop nop } module-warn {module-warn module-warn module-warn module-warn module-warn module-warn nop nop } module-whatis {nop nop reportCmd nop nop module-whatis nop nop } @@ -578,7 +580,8 @@ proc execute-modulerc {modfile modname modspec} { module-info modulepath-ignore modulepath-ignore modulepath-label\ modulepath-label setModulesVersion setModulesVersion\ getModuleContent getModuleContent lsb-release lsb-release\ - module-warn module-warn] + module-warn module-warn module-forbid-regex module-forbid-regex\ + module-hide-regex module-hide-regex] if {[getConf source_cache]} { set ::g_modrcAliases(source) sourceModfileCmd diff --git a/tcl/mfcmd.tcl b/tcl/mfcmd.tcl index 2b11d27d0..9f54b19a1 100644 --- a/tcl/mfcmd.tcl +++ b/tcl/mfcmd.tcl @@ -549,6 +549,14 @@ proc hide-modulefile {modfile} { module-hide $modfile } +proc module-hide-regex {args} { + module-hide --regexp {*}$args +} + +proc module-forbid-regex {args} { + module-forbid --regexp {*}$args +} + proc module-tag {args} { # parse application criteria arguments to determine if command apply lassign [parseApplicationCriteriaArgs 0 0 {*}$args] apply isnearly after\ diff --git a/testsuite/modulefiles.4/hide/.modulerc b/testsuite/modulefiles.4/hide/.modulerc index a8b10262d..854755c81 100644 --- a/testsuite/modulefiles.4/hide/.modulerc +++ b/testsuite/modulefiles.4/hide/.modulerc @@ -37,5 +37,30 @@ if {[info exists env(TESTSUITE_HIDE)]} { hide_version4 { hide-version hid } + hide_regex_bad1 { + module-hide-regex + } + hide_regex_bad2 { + module-hide-regex {hide/(1} + } + hide_regex1 { + module-hide-regex {^hide/1$} + } + hide_regex2 { + module-hide-regex --hard {-unk$} {^HIDE/2} + } + hide_regex3 { + module-hide-regex {^hide/} --user unknownuser + } + forbid_regex_bad1 { + module-forbid-regex --message my-forbid-msg + } + forbid_regex1 { + module-forbid-regex {-unk$} --message my-forbid-msg {^hide/2} + } + forbid_regex2 { + set tomorrow [clock format [expr {[clock seconds]+86400}] -format %Y-%m-%d] + module-forbid-regex --after $tomorrow {^hide/1} + } } } diff --git a/testsuite/modulefiles.lint/tag/.modulerc b/testsuite/modulefiles.lint/tag/.modulerc index fc069a4c6..e2b75c1ca 100644 --- a/testsuite/modulefiles.lint/tag/.modulerc +++ b/testsuite/modulefiles.lint/tag/.modulerc @@ -15,3 +15,5 @@ module-tag bar --regexp {^tag/5} module-forbid --regexp {^tag/6} {-old$} module-warn --regexp --message {text} {-old$} --user foo module-hide {-old$} --regexp --hard +module-hide-regex --soft {-old$} {^tag/7} +module-forbid-regex {^tag/7} --message {text} {-old$} diff --git a/testsuite/modules.20-locate/150-lmod-hide.exp b/testsuite/modules.20-locate/150-lmod-hide.exp index 9feea2075..954cf9d9d 100644 --- a/testsuite/modules.20-locate/150-lmod-hide.exp +++ b/testsuite/modules.20-locate/150-lmod-hide.exp @@ -160,6 +160,87 @@ set tserr "$mp:\nhide/1\nhide/2" testouterr_cmd sh {avail -t hide} OK $tserr +# +# module-hide-regex +# + +setenv_var MODULES_ICASE never + +set ans [list] +lappend ans [list set _LMFILES_ $mp/hide/1] +lappend ans [list set LOADEDMODULES hide/1] +lappend ans [list ERR] + +setenv_var TESTSUITE_HIDE hide_regex_bad1 + +set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 41}] +set tserr [escre [msg_moderr {No module specified in argument} {module-hide --regexp {*}$args"} $mp/hide/.modulerc $line_num { }]] +testouterr_cmd_re sh {load hide/1} $ans $tserr + +setenv_var TESTSUITE_HIDE hide_regex_bad2 + +set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 44}] +set tserr [escre [msg_moderr {Invalid regular expression 'hide/(1'} {module-hide --regexp {*}$args"} $mp/hide/.modulerc $line_num { }]] +testouterr_cmd_re sh {load hide/1} $ans $tserr + +setenv_var TESTSUITE_HIDE hide_regex1 + +set tserr "$mp:\nhide/2" +testouterr_cmd sh {avail -t hide} OK $tserr + +set tserr "$mp:\nhide/1 \nhide/2" +testouterr_cmd sh {avail -t -a hide} OK $tserr + +# options of module-hide, regular expression starting with dash character +setenv_var TESTSUITE_HIDE hide_regex2 + +set tserr "$mp:\nhide/1\nhide/2" +testouterr_cmd sh {avail -t -a hide} OK $tserr + +setenv_var MODULES_ICASE always + +set tserr "$mp:\nhide/1" +testouterr_cmd sh {avail -t -a hide} OK $tserr +testouterr_cmd sh {load hide/2} ERR [err_unablelocate hide/2] + +setenv_var MODULES_ICASE never + +# application criteria not met +setenv_var TESTSUITE_HIDE hide_regex3 + +set tserr "$mp:\nhide/1\nhide/2" +testouterr_cmd sh {avail -t hide} OK $tserr + + +# +# module-forbid-regex +# + +setenv_var TESTSUITE_HIDE forbid_regex_bad1 + +set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 56}] +set tserr [escre [msg_moderr {No module specified in argument} {module-forbid --regexp {*}$args"} $mp/hide/.modulerc $line_num { }]] +testouterr_cmd_re sh {load hide/1} $ans $tserr + +setenv_var TESTSUITE_HIDE forbid_regex1 + +testouterr_cmd sh {load hide/2} ERR [err_accessdenied hide/2 my-forbid-msg] + +set ans [list] +lappend ans [list set _LMFILES_ $mp/hide/1] +lappend ans [list set LOADEDMODULES hide/1] +testouterr_cmd sh {load hide/1} $ans {} + +# nearly forbidden +setenv_var TESTSUITE_HIDE forbid_regex2 +setenv_var MODULES_NEARLY_FORBIDDEN_DAYS 4 + +lappend ans [list set __MODULES_LMTAG hide/1&nearly-forbidden] +set tomorrow [clock format [expr {[clock seconds]+86400}] -format %Y-%m-%d] +set tserr [msg_load {hide/1 } [err_accessnearlydenied $tomorrow]] +testouterr_cmd sh {load hide/1} $ans $tserr + + # # Cleanup #