From fcf37f8b44a0ca964b07a091749cd698d6e71569 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Wed, 28 Apr 2021 16:52:58 +0000 Subject: [PATCH 1/6] Pmodule modulefile: remove Pmodules bin dir from PATH in some cases it might happen that we have a Pmodules bin directory in PATH. This has to be removed if we load a Pmodule module. (cherry picked from commit d23fdf930a523796de8562dfb91a76cccd9b6ef1) --- Pmodules/modulefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Pmodules/modulefile b/Pmodules/modulefile index 65aa4c1..2a9311d 100644 --- a/Pmodules/modulefile +++ b/Pmodules/modulefile @@ -8,3 +8,15 @@ module-maintainer "Achim Gsell " module-help " Pmodules are a hierarchical module environment based on Environment Modules. " + +# +# It might be that '${PMODULES_ROOT}/Tools/Pmodules/VERSION' is in PATH. +# Why? With older version the PATH might have been set without loading +# a module. +# +if { [module-info mode load] } { + set PATH ":$::env(PATH):" + if { [regexp -- {.*:(.*/Pmodules/[^:]*):} $PATH -> str] } { + remove-path PATH $str + } +} From 2faf42a4e046250b936f9ac2dcd9f664b5df5a17 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 6 May 2021 07:27:28 +0000 Subject: [PATCH 2/6] modulefile: bugfix in modifying PATH (cherry picked from commit d25663a32e7d9f3453be59fb94bd971d72ea2b61) --- Pmodules/modulefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Pmodules/modulefile b/Pmodules/modulefile index 2a9311d..1893fdb 100644 --- a/Pmodules/modulefile +++ b/Pmodules/modulefile @@ -17,6 +17,8 @@ Pmodules are a hierarchical module environment based on Environment Modules. if { [module-info mode load] } { set PATH ":$::env(PATH):" if { [regexp -- {.*:(.*/Pmodules/[^:]*):} $PATH -> str] } { - remove-path PATH $str + if { [string compare $str $PREFIX/bin] != 0 } { + remove-path PATH $str + } } } From daead01197aec7ef060b076edd75af765abfbbfd Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 6 May 2021 07:25:26 +0000 Subject: [PATCH 3/6] modulecmd: save environment after unloading a module (cherry picked from commit 9a0d55ed85b3ce769eef0315dc82dd74d63a8fa0) --- Pmodules/modulecmd.bash.in | 1 + 1 file changed, 1 insertion(+) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 124c95d..f630ddf 100755 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -642,6 +642,7 @@ subcommand_unload() { PMODULES_HOME=${saved_home} export_env 'PMODULES_HOME' fi + g_env_must_be_saved='yes' } ############################################################################## From dc1ad90c70a16a6e2c4bebf0564140359ed100e6 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 6 May 2021 11:28:10 +0200 Subject: [PATCH 4/6] modulecmd: align columns in sub-cmd avail --- Pmodules/modulecmd.bash.in | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) mode change 100755 => 100644 Pmodules/modulecmd.bash.in diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in old mode 100755 new mode 100644 index f630ddf..a49cdb9 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -875,14 +875,15 @@ subcommand_avail() { human_readable_output() { output_header - local -i column=$cols - local -i colsize=16 - for ((i=0; i<${#mods[@]}; i+=3 )); do + local -a available_modules=() + local mod='' + local -i max_length=1 + for ((i=0; i<${#mods[@]}; i+=3)); do if [[ ${verbosity_lvl} == 'verbose' ]]; then local release=${mods[i+1]} case ${mods[i+1]} in stable ) - mod=${mods[i]} + mod="${mods[i]}" ;; * ) mod="${mods[i]}(${release:0:1})" @@ -891,9 +892,17 @@ subcommand_avail() { else mod=${mods[i]} fi + local -i n=${#mod} + (( n > max_length )) && (( max_length=n )) + available_modules+=("${mod}") + done + IFS=$'\n' available_modules=($(sort <<<"${available_modules[*]}")) + unset IFS + local -i span=$(( max_length / 16 + 1 )) # compute column size + local -i colsize=$(( span * 16 )) # as multiple of 16 + local -i column=$cols # force a line-break + for mod in "${available_modules[@]}"; do local -i len=${#mod} - local -i span=$(( len / 16 + 1 )) - local -i colsize=$(( span * 16 )) if (( column+len >= cols )); then printf -- "\n" 1>&2 column=0 From e3299a1afa236804bb57352710a4c09270fce8d4 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 6 May 2021 14:22:30 +0200 Subject: [PATCH 5/6] modulecmd: sub-cmd avail: pass group as argument to output function --- Pmodules/modulecmd.bash.in | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index a49cdb9..2534bab 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -818,9 +818,7 @@ subcommand_avail() { cols=$(tput cols) output_header() { - local caption=${dir/${PMODULES_ROOT}\/} - local caption=${caption/\/${PMODULES_MODULEFILES_DIR}/: } - local caption=${caption/: \//: } + local caption="$1" let i=($cols-${#caption})/2-2 printf -- "%0.s-" $(seq 1 $i) 1>&2 printf -- " %s " "${caption}" 1>&2 @@ -829,7 +827,7 @@ subcommand_avail() { } terse_output() { - output_header + output_header "$1" for (( i=0; i<${#mods[@]}; i+=3 )); do local mod=${mods[i]} local release=${mods[i+1]} @@ -855,7 +853,7 @@ subcommand_avail() { # # :FIXME: for the time being, this is the same as terse_output! long_output() { - output_header + output_header "$1" for (( i=0; i<${#mods[@]}; i+=3 )); do local mod=${mods[i]} local release=${mods[i+1]} @@ -873,7 +871,7 @@ subcommand_avail() { } human_readable_output() { - output_header + output_header "$1" local -a available_modules=() local mod='' @@ -968,7 +966,7 @@ subcommand_avail() { "${opt_use_releases}" \ "${dir}" [[ ${#mods[@]} == 0 ]] && continue - ${output_function} + ${output_function} "${group}" done done } From 6318a0a59186c3a7e0a9f69a9caa66ab3fb0161b Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 6 May 2021 14:23:55 +0200 Subject: [PATCH 6/6] modulecmd: sub-cmd avail: group argument added It's now possible to list available modules in certain groups only. --- Pmodules/modulecmd.bash.in | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 2534bab..fa4cf9b 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -917,18 +917,15 @@ subcommand_avail() { } local pattern=() local output_function='human_readable_output' - local opt_all_groups='no' local opt_use_releases="${UsedReleases}" + local -A opt_groups=() + local val='' while (($# > 0)); do case $1 in - -H | --help ) + -H | --help | -\? ) print_help "${subcommand}" ;; - -a | --all ) - opt_all_groups='yes' - opt_use_releases="${PMODULES_DEFINED_RELEASES}" - ;; - --all-releases ) + -a | --all | --all-releases ) opt_use_releases="${PMODULES_DEFINED_RELEASES}" ;; -h | --human ) @@ -943,6 +940,15 @@ subcommand_avail() { -m | --machine ) output_function='machine_output' ;; + -g | --group | --group=* ) + if [[ $1 == --group=* ]]; then + val="${1/--group=}" + else + val="$2" + shift + fi + opt_groups[${val}]=1 + ;; -- | '' ) ;; * ) @@ -960,6 +966,11 @@ subcommand_avail() { local string for string in "${pattern[@]}"; do for dir in "${modulepath[@]}"; do + local group="${dir/${PMODULES_ROOT}\/}" + group="${group%%/*}" + if (( ${#opt_groups[@]} > 0 )) && [[ ! -v opt_groups[${group}] ]]; then + continue + fi get_available_modules \ mods \ "${string}" \