From 10d069cb1494872c7efc87fd46898b7918b62116 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Tue, 28 Mar 2023 15:40:35 +0200 Subject: [PATCH] Python support added --- Pmodules/Pmodules.py | 14 ++++++++++++++ Pmodules/libpmodules.bash.in | 5 +++-- Pmodules/modulecmd.bash.in | 6 ++++++ build | 2 ++ config/versions.conf | 2 +- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Pmodules/Pmodules.py diff --git a/Pmodules/Pmodules.py b/Pmodules/Pmodules.py new file mode 100644 index 0000000..68993e5 --- /dev/null +++ b/Pmodules/Pmodules.py @@ -0,0 +1,14 @@ +import os, re, subprocess + +def module(*args): + os.environ['PMODULES_MODULEFILES_DIR']='modulefiles' + os.environ['PMODULES_CONFIG_DIR']='config' + pm_home=os.environ['PMODULES_HOME'] + os.environ['PMODULES_DIR']=pm_home + modulecmd=os.path.join(pm_home, 'bin', 'modulecmd') + if type(args[0]) == type([]): + args = args[0] + else: + cmd = [modulecmd, 'python'] + list(args) + (output, error) = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate() + exec(output) diff --git a/Pmodules/libpmodules.bash.in b/Pmodules/libpmodules.bash.in index fb08a3b..14c2a7d 100644 --- a/Pmodules/libpmodules.bash.in +++ b/Pmodules/libpmodules.bash.in @@ -10,8 +10,9 @@ declare -A Help=() # initialize help text of 'module --version' Help['version']=" -Pmodules @PMODULES_VERSION@ using Tcl Environment Modules @MODULES_VERSION@ -Copyright GNU GPL v2 +Pmodules @PMODULES_VERSION@ +using Tcl Environment Modules +VERSION = @MODULES_VERSION@ " # diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 1a823a5..9e902b5 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -55,6 +55,9 @@ export_env() { csh | tcsh ) local -r fmt="setenv %s \"%s\"; " ;; + python ) + local -r fmt="os.environ['%s'] = '%s'\n" + ;; * ) std::die 1 "Unsupported shell -- ${Shell}\n" ;; @@ -2284,6 +2287,9 @@ case "$1" in csh | tcsh ) declare Shell='csh' ;; + python ) + declare Shell='python' + ;; * ) std::die 1 "${CMD}: unsupported shell -- $1\n" ;; diff --git a/build b/build index 4b43780..2c0ae64 100755 --- a/build +++ b/build @@ -40,6 +40,7 @@ get_version() { } declare -rx PMODULES_VERSION=$(get_version 'Pmodules') +declare -rx MODULES_VERSION=$(get_version 'modules') #----------------------------------------------------------------------------- # @@ -507,6 +508,7 @@ pmodules::install() { install -m 0644 "${SRC_DIR}/bash" "${PMODULES_HOME}/init" install -m 0644 "${SRC_DIR}/bash_completion" "${PMODULES_HOME}/init" install -m 0644 "${SRC_DIR}/csh" "${PMODULES_HOME}/init" + install -m 0644 "${SRC_DIR}/Pmodules.py" "${PMODULES_HOME}/init" install -m 0644 "${SRC_DIR}/zsh" "${PMODULES_HOME}/init" install -m 0644 "${SRC_DIR}/libpbuild.bash" "${PMODULES_HOME}/lib" diff --git a/config/versions.conf b/config/versions.conf index 4fc0bef..4e1f11d 100644 --- a/config/versions.conf +++ b/config/versions.conf @@ -3,7 +3,7 @@ coreutils 8.31 findutils 4.7.0 getopt 1.1.6 gettext 0.21 -modules 3.2.10.1 +modules 3.2.10.2 Pmodules 1.0.0rc15 Tcl 8.6.13 tcllib 1.21