modulecmd: derive prefix from directory of init scripts

This commit is contained in:
2025-01-09 09:49:15 +01:00
parent 7047c82e75
commit 756c00b921
4 changed files with 47 additions and 53 deletions
+10 -7
View File
@@ -1,13 +1,16 @@
import os, re, subprocess
#
# :FIXME:
# - add error handling
# - needs testing!
#
import subprocess, pathlib
def module(*args):
os.environ['PMODULES_MODULEFILES_DIR']='modulefiles'
pm_home=os.environ['PMODULES_HOME']
os.environ['PMODULES_DIR']=pm_home
modulecmd=os.path.join(pm_home, 'bin', 'modulecmd')
dir=pathlib.Path(__file__).parent
modulecmd=pathlib.PurePath.joinpath(dir, '..', 'bin', 'modulecmd').resolve()
if type(args[0]) == type([]):
args = args[0]
cmd = [modulecmd, 'python'] + args[0]
else:
cmd = [modulecmd, 'python'] + list(args)
(output, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
(output, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
exec(output)
+19 -20
View File
@@ -8,19 +8,11 @@ if [ ${BASH_VERSINFO:-0} -lt 3 ]; then
return 1
fi
############################################################################
# some sanity checks
#
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
#############################################################################
# initialize bash completion
#
if [[ -r "${PMODULES_HOME}/init/bash_completion" ]]; then
source "${PMODULES_HOME}/init/bash_completion"
if [[ -r "${BASH_SOURCE[0]%/*}/bash_completion" ]]; then
source "${BASH_SOURCE[0]%/*}/bash_completion"
fi
#############################################################################
@@ -30,23 +22,30 @@ unset MODULE_VERSION
unset MODULE_VERSION_STACK
unset MODULESHOME
declare -x PMODULES_DIR="${PMODULES_HOME}"
#############################################################################
# implement module comand as shell function
#
module() {
unset BASH_ENV
local output="$("${PMODULES_HOME}/bin/modulecmd" bash "$@")"
eval "${output}"
}
declare -- _dname_=$(dirname "${BASH_SOURCE[0]}")
declare -- PMODULES_HOME="$(cd "${_dname_}/.." && pwd -L)"
unset _dname_
declare -- _cmd_="module() {
unset BASH_ENV
local output=\"\$(\"${PMODULES_HOME}/bin/modulecmd\" bash \"\$@\")\"
eval \"\${output}\"
}"
eval "$(echo "${_cmd_}")"
export -f module
modbuild(){
"${PMODULES_HOME}/bin/modbuild" "$@"
}
_cmd_="modbuild(){
\"${PMODULES_HOME}/bin/modbuild\" \"\$@\"
}"
eval "$(echo "${_cmd_}")"
export -f modbuild
unset _cmd_
# Local Variables:
# mode: sh
# sh-basic-offset: 8
+2 -2
View File
@@ -40,9 +40,9 @@ if (! $?DefaultGroups ) then
endif
foreach group ( ${DefaultGroups} )
if ( "${MODULEPATH}" == "" ) then
setenv MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
setenv MODULEPATH "${PMODULES_ROOT}/${group}/modulefiles"
else
setenv MODULEPATH "${MODULEPATH}:${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
setenv MODULEPATH "${MODULEPATH}:${PMODULES_ROOT}/${group}/modulefiles"
endif
end
+16 -24
View File
@@ -1,19 +1,9 @@
#!/bin/zsh
############################################################################
# some sanity checks
#
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
#############################################################################
# initialize zsh completion
#
#if [[ -r "${PMODULES_HOME}/init/bash_completion" ]]; then
# source "${PMODULES_HOME}/init/bash_completion"
#fi
# :FIXME:
#############################################################################
# legacy...
@@ -21,27 +11,29 @@ fi
unset MODULE_VERSION
unset MODULE_VERSION_STACK
unset MODULESHOME
unset PMODULES_ENV
declare -x PMODULES_DIR="${PMODULES_HOME}"
#############################################################################
# implement module comand as shell function
#
module() {
eval $("${PMODULES_HOME}/bin/modulecmd" bash "$@")
}
declare -- PMODULES_HOME=$0:A:h:h
declare -- _cmd_="module() {
unset BASH_ENV
local output=\"\$(\"${PMODULES_HOME}/bin/modulecmd\" zsh \"\$@\")\"
eval \"\${output}\"
}"
eval "$(echo "${_cmd_}")"
export -f module
modbuild(){
(
eval $("${PMODULES_HOME}/bin/modulecmd" bash load System:bash)
"${PMODULES_HOME}/bin/modbuild" "$@"
)
}
_cmd_="modbuild(){
\"${PMODULES_HOME}/bin/modbuild\" \"\$@\"
}"
eval "$(echo "${_cmd_}")"
export -f modbuild
unset _cmd_
# Local Variables:
# mode: sh
# sh-basic-offset: 8