From c8b6db986b92361d898e621862336c46b76a992d Mon Sep 17 00:00:00 2001 From: Byron Boulton Date: Mon, 10 Nov 2025 09:54:28 -0500 Subject: [PATCH 1/5] Make it more Pythonic to import env_modules.module Renaming python.py to env_modules.py. On Linux, symlink python.py to point to env_modules.py for backward compatibility. Windows doesn't typically support unix-style symlinks, but we don't need to worry about that since the Windows installations of Environment Modules never had python.py. Signed-off-by: Byron Boulton --- init/.gitignore | 2 +- init/Makefile | 7 ++++--- init/{python.py.in => env_modules.py.in} | 0 3 files changed, 5 insertions(+), 4 deletions(-) rename init/{python.py.in => env_modules.py.in} (100%) diff --git a/init/.gitignore b/init/.gitignore index e58033ea0..3bda98b78 100644 --- a/init/.gitignore +++ b/init/.gitignore @@ -5,7 +5,7 @@ /csh /tcsh /perl.pm -/python.py +/env_modules.py /ruby.rb /lisp /cmake diff --git a/init/Makefile b/init/Makefile index 518142900..675c57935 100644 --- a/init/Makefile +++ b/init/Makefile @@ -11,7 +11,7 @@ INSTALL_DATA = $(INSTALL) -m 644 SH_LIKE = sh ksh bash zsh profile.sh CSH_LIKE = csh tcsh tcsh_completion profile.csh -OTHER = perl.pm python.py ruby.rb lisp tcl fish cmake r.R pwsh.ps1 +OTHER = perl.pm env_modules.py ruby.rb lisp tcl fish cmake r.R pwsh.ps1 # example modulefiles to install EXAMPLE_MODFILES_SRCDIR := ../share/modulefiles @@ -247,6 +247,7 @@ endif $(INSTALL_DIR) '$(DESTDIR)$(zshcompletiondir)' $(INSTALL_DIR) '$(DESTDIR)$(modulefilesdir)' $(INSTALL_DATA) $(ALL_SHELLS) '$(DESTDIR)$(initdir)/' + ln -f -s env_modules.py '$(DESTDIR)$(initdir)/python.py' ifeq ($(windowssupport),y) $(INSTALL_DATA) cmd.cmd '$(DESTDIR)$(initdir)/' endif @@ -277,7 +278,7 @@ ifeq ($(versioning),y) endif uninstall: - rm -f $(foreach initscript,$(ALL_SHELLS),'$(DESTDIR)$(initdir)/$(initscript)') + rm -f $(foreach initscript,$(ALL_SHELLS) python.py,'$(DESTDIR)$(initdir)/$(initscript)') ifeq ($(windowssupport),y) rm -f '$(DESTDIR)$(initdir)/cmd.cmd' endif @@ -325,7 +326,7 @@ ifeq ($(VERBOSE),1) V = 1 endif # let verbose by default the install/clean/test and other specific non-build targets -$(V).SILENT: sh ksh bash zsh csh tcsh fish perl.pm python.py ruby.rb lisp tcl \ +$(V).SILENT: sh ksh bash zsh csh tcsh fish perl.pm env_modules.py ruby.rb lisp tcl \ cmake r.R bash_completion tcsh_completion zsh-functions/_module profile.sh \ profile.csh modulespath initrc $(EXAMPLE_MODFILES_SRCDIR)/modules \ $(EXAMPLE_MODFILES_SRCDIR)/version pwsh.ps1 diff --git a/init/python.py.in b/init/env_modules.py.in similarity index 100% rename from init/python.py.in rename to init/env_modules.py.in From 741f84fe261ca5d0904ff3c5a1cba288894b9516 Mon Sep 17 00:00:00 2001 From: Byron Boulton Date: Mon, 10 Nov 2025 13:59:12 -0500 Subject: [PATCH 2/5] doc: describe initialization of PYTHONPATH Signed-off-by: Byron Boulton Signed-off-by: Xavier Delaruelle --- INSTALL.rst | 19 +++++++++++++++++++ doc/source/module.rst | 14 ++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/INSTALL.rst b/INSTALL.rst index d0b6af65b..4c3250071 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -504,6 +504,15 @@ instance :instopt:`--disable-set-manpath<--enable-set-manpath>`): .. versionadded:: 4.2 +.. instopt:: --enable-append-pythonpath + + Append rather prepend init directory to the PYTHONPATH environment variable + when the :instopt:`--enable-set-pythonpath` option is enabled. (default=no) + + .. only:: html or latex + + .. versionadded:: 5.7 + .. instopt:: --enable-auto-handling Set modulecmd.tcl to automatically apply automated modulefiles handling @@ -830,6 +839,16 @@ instance :instopt:`--disable-set-manpath<--enable-set-manpath>`): .. versionadded:: 4.0 +.. instopt:: --enable-set-pythonpath + + Prepend init directory defined by the :instopt:`--initdir` option to the + PYTHONPATH environment variable in the shell initialization scripts. + (default=yes) + + .. only:: html or latex + + .. versionadded:: 5.7 + .. instopt:: --enable-set-shell-startup Set when module function is defined the shell startup file to ensure that the diff --git a/doc/source/module.rst b/doc/source/module.rst index fbde31ccf..4579756b8 100644 --- a/doc/source/module.rst +++ b/doc/source/module.rst @@ -128,10 +128,20 @@ Perl: Python: +Default installation should have added |file initdir| to the :envvar:`PYTHONPATH` environment variable allowing initialization as follows + +.. parsed-literal:: + + from env_modules import module + module("load", "modulefile", "modulefile", "...") + +Otherwise + .. parsed-literal:: - import os - exec(open("\ |initdir|\ /python.py").read(), globals()) + import sys + sys.path.insert(1, "\ |initdir|\ ") + from env_modules import module module("load", "modulefile", "modulefile", "...") Ruby: From ee8de6c625d5092a7ad5cc61748a959975387df7 Mon Sep 17 00:00:00 2001 From: Byron Boulton Date: Fri, 14 Nov 2025 08:33:34 -0500 Subject: [PATCH 3/5] Implement PYTHONPATH initialization Adding the initdir to PYTHONPATH allows users to "import" the "module" function in Python scripts. Signed-off-by: Byron Boulton --- Makefile | 12 ++++++++++++ Makefile.inc.in | 2 ++ configure | 14 +++++++++++++- site.exp.in | 2 ++ tcl/subcmd.tcl.in | 5 +++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c137c0ada..7c5043867 100644 --- a/Makefile +++ b/Makefile @@ -236,6 +236,16 @@ ifeq ($(appendbinpath),y) else setappendbinpath := prepend endif +ifeq ($(setpythonpath),y) + setsetpythonpath := +else + setsetpythonpath := \# +endif +ifeq ($(appendpythonpath),y) + setappendpythonpath := append +else + setappendpythonpath := prepend +endif ifeq ($(setmanpath),y) setsetmanpath := else @@ -499,6 +509,8 @@ sed -e 's|@prefix@|$(prefix)|g' \ -e 's|@setmanpath@|$(setsetmanpath)|g' \ -e 's|@appendmanpath@|$(setappendmanpath)|g' \ -e 's|@usemanpath@|$(setusemanpath)|g' \ + -e 's|@setpythonpath@|$(setsetpythonpath)|g' \ + -e 's|@appendpythonpath@|$(setappendpythonpath)|g' \ -e 's|@notusemanpath@|$(setnotusemanpath)|g' \ -e 's|@shellcompsource@|$(shellcompsource)|g' \ -e 's|@tcllintercmd@|$(tcllintercmd)|g' \ diff --git a/Makefile.inc.in b/Makefile.inc.in index 5e8cb279b..6aca1ca78 100644 --- a/Makefile.inc.in +++ b/Makefile.inc.in @@ -48,6 +48,8 @@ libdir32 := @libdir32@ # enable or not some specific definition setmanpath := @setmanpath@ appendmanpath := @appendmanpath@ +setpythonpath := @setpythonpath@ +appendpythonpath := @appendpythonpath@ setbinpath := @setbinpath@ appendbinpath := @appendbinpath@ setmodulespath := @setmodulespath@ diff --git a/configure b/configure index cc524fdea..66b5ade05 100755 --- a/configure +++ b/configure @@ -41,7 +41,8 @@ listterseoutput editor variantshortcut bashcompletiondir fishcompletiondir \ zshcompletiondir tcllinter tcllinteropts nagelfardatadir nagelfaraddons \ stickypurge uniquenameloaded abortonerror sourcecache logger loggeropts \ loggedevents conflictunload spideroutput spiderterseoutput spiderindepth \ -emacsdatadir emacsaddons requirevia compressedchangelog paginate initenvvars" +emacsdatadir emacsaddons requirevia compressedchangelog paginate initenvvars \ +setpythonpath appendpythonpath" libarglist=() # flags to know if argument has been specified on command-line @@ -52,6 +53,8 @@ defloggeropts=1 prefix=/usr/local/Modules setmanpath=y appendmanpath=n +setpythonpath=y +appendpythonpath=n setbinpath=y appendbinpath=n setmodulespath=n @@ -244,6 +247,8 @@ Optional Features: specify finer constraints on module version. [yes] --enable-append-binpath append rather prepend bindir to PATH [no] --enable-append-manpath append rather prepend mandir to MANPATH [no] + --enable-append-pythonpath + append rather prepend initdir to PYTHONPATH [no] --enable-auto-handling set modulecmd.tcl to automatically apply automated modulefiles handling actions, like loading the pre-requisites of a modulefile when loading this @@ -316,6 +321,7 @@ Optional Features: stored in this modulepath [no] --enable-set-binpath set bindir to PATH in init scripts [yes] --enable-set-manpath set mandir to MANPATH in init scripts [yes] + --enable-set-pythonpath set initdir to PYTHONPATH in init scripts [yes] --enable-set-shell-startup set when module function is defined the shell startup file to ensure that the module function is @@ -737,6 +743,12 @@ for arg in "$@"; do --enable-append-manpath*|--disable-append-manpath) # shellcheck disable=SC2034 appendmanpath=$(get_feature_value "$arg") ;; + --enable-set-pythonpath*|--disable-set-pythonpath) + # shellcheck disable=SC2034 + setpythonpath=$(get_feature_value "$arg") ;; + --enable-append-pythonpath*|--disable-append-pythonpath) + # shellcheck disable=SC2034 + appendpythonpath=$(get_feature_value "$arg") ;; --enable-set-binpath*|--disable-set-binpath) # shellcheck disable=SC2034 setbinpath=$(get_feature_value "$arg") ;; diff --git a/site.exp.in b/site.exp.in index 32be6167f..dc7963f58 100644 --- a/site.exp.in +++ b/site.exp.in @@ -32,6 +32,8 @@ set install_libdir32 "@libdir32@" set install_setmanpath "@setmanpath@" set install_appendmanpath "@appendmanpath@" set install_usemanpath "@usemanpath@" +set install_setpythonpath "@setpythonpath@" +set install_appendpythonpath "@appendpythonpath@" set install_setbinpath "@setbinpath@" set install_appendbinpath "@appendbinpath@" set install_examplemodulefiles "@examplemodulefiles@" diff --git a/tcl/subcmd.tcl.in b/tcl/subcmd.tcl.in index 8cee80aa7..9ccec93cf 100644 --- a/tcl/subcmd.tcl.in +++ b/tcl/subcmd.tcl.in @@ -2170,6 +2170,11 @@ proc cmdModuleAutoinit {} { @setmanpath@} } + # add Modules init directory to PYTHONPATH if enabled + @setpythonpath@if {{@initdir@} ni [split [get-env PYTHONPATH] :]} { + @setpythonpath@ @appendpythonpath@-path PYTHONPATH {@initdir@} + @setpythonpath@} + # source shell completion script if available, not installed in default # completion locations and only if shell is interactive if {[getState shell] in {@shellcompsource@} && [getState is_stderr_tty]} { From 290af7d15d997ed5228789b4ea74717586ae1696 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 4 Jul 2026 18:29:40 +0200 Subject: [PATCH 4/5] doc: extend --enable-set-pythonpath documentation Signed-off-by: Xavier Delaruelle --- .hunspell.en.dic | 2 ++ NEWS.rst | 15 +++++++++++++++ doc/source/changes.rst | 4 ++++ doc/source/module.rst | 12 +++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.hunspell.en.dic b/.hunspell.en.dic index 9865fb336..aa1876c98 100644 --- a/.hunspell.en.dic +++ b/.hunspell.en.dic @@ -1339,3 +1339,5 @@ OSX BAWT HTTPS mirrorEnvVarChange +PYTHONPATH +pythonpath diff --git a/NEWS.rst b/NEWS.rst index 064796da6..fbfea814a 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -111,6 +111,21 @@ Modules 5.7.0 (not yet released) * Also consider ``-`` in addition to ``.`` as a version number separator character when selecting a module with the :mconfig:`extended_default` mechanism. (fix issue #619) +* Rename Modules initialization script for Python ``env_modules.py`` to make + it a proper Python module name. +* Rename the Python initialization script to :file:`env_modules.py` so that it + uses a valid Python module name. Generates a :file:`python.py` symlink onto + :file:`env_modules.py` to preserve compatibility. (contribution from Byron + Boulton) +* Install: introduce the :instopt:`--enable-set-pythonpath` installation + option to prepend Modules ``init`` directory to the :envvar:`PYTHONPATH` + environment variable during Modules initialization. This option is enabled + by default and make it easier to import the ``env_modules`` Python module. + (fix issue #483 with contribution from Byron Boulton) +* Install: add the :instopt:`--enable-append-pythonpath` installation option, + which causes :instopt:`--enable-set-pythonpath` to append the Modules + ``init`` directory to :envvar:`PYTHONPATH` instead of prepending it. + (contribution from Byron Boulton) .. _5.6 release notes: diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 825220fdb..1965ad1c6 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -1010,6 +1010,10 @@ The following module sub-commands appeared on Modules 5. Starting Modules 5.5, definition of :command:`mogui` shell alias or function is added on this sub-command. + Starting Modules 5.7, initialization directory is added to ``PYTHONPATH`` + environment variable unless installation option + :instopt:`--disable-set-pythonpath<--enable-set-pythonpath>` is used. + :subcmd:`lint` Starting Modules 5.6, readable modulecache files are also linted when no diff --git a/doc/source/module.rst b/doc/source/module.rst index 4579756b8..ef308ac7b 100644 --- a/doc/source/module.rst +++ b/doc/source/module.rst @@ -89,11 +89,18 @@ time if :command:`mogui-cmd` command is found in :envvar:`PATH`. changes performed in the GUI is applied onto the shell session that executed :command:`mogui`. +The installation location of the ``env_modules`` Python module may also be +added to the :envvar:`PYTHONPATH` environment variable during initialization, +unless the :instopt:`--enable-append-pythonpath` installation option has been +disabled. + .. only:: html or latex .. versionchanged:: 5.5 Definition of :command:`mogui` alias or function added + .. versionchanged:: 5.7 + Update of :envvar:`PYTHONPATH` environment variable added Examples of initialization ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -128,14 +135,13 @@ Perl: Python: -Default installation should have added |file initdir| to the :envvar:`PYTHONPATH` environment variable allowing initialization as follows - .. parsed-literal:: from env_modules import module module("load", "modulefile", "modulefile", "...") -Otherwise +Alternative initialization for Python if ``env_modules`` script is not part of +an enabled Python module directory: .. parsed-literal:: From 3a47d8a15d981427c668bb41bc8c56234d9735ad Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sun, 5 Jul 2026 00:06:30 +0200 Subject: [PATCH 5/5] ts: adapt tests for --enable-set-pythonpath Signed-off-by: Xavier Delaruelle --- .github/workflows/linux_tests.yaml | 2 + testsuite/install.00-init/030-options.exp | 22 +++++++ testsuite/modules.50-cmds/400-source-sh.exp | 62 ++++++++++++++++--- testsuite/modules.70-maint/120-autoinit.exp | 25 ++++++++ testsuite/modules.70-maint/310-sh-to-mod.exp | 29 +++++++-- .../modules.70-maint/311-eval-sh-to-mod.exp | 29 +++++++-- 6 files changed, 153 insertions(+), 16 deletions(-) diff --git a/.github/workflows/linux_tests.yaml b/.github/workflows/linux_tests.yaml index 1276a9eac..43211eadc 100644 --- a/.github/workflows/linux_tests.yaml +++ b/.github/workflows/linux_tests.yaml @@ -21,6 +21,7 @@ jobs: --enable-quarantine-support --disable-set-binpath --disable-set-manpath + --disable-set-pythonpath COVERAGE: y EXTRA_SCRIPT_PRETEST: make install-testmodulerc install-testetcrc install-testmodspath-empty install-testmoguicmd EXTRA_SCRIPT_POSTTEST: make uninstall-testconfig @@ -386,6 +387,7 @@ jobs: --with-tclsh=/usr/local/bin/tclsh9.1 --prefix=/tmp/modules --with-tcl=/usr/local/lib + --enable-append-pythonpath --enable-append-manpath --enable-append-binpath --with-bin-search-path=/usr/bin:/bin diff --git a/testsuite/install.00-init/030-options.exp b/testsuite/install.00-init/030-options.exp index ba3420027..68c0c2266 100644 --- a/testsuite/install.00-init/030-options.exp +++ b/testsuite/install.00-init/030-options.exp @@ -267,6 +267,28 @@ if {[string length $nafelgar_script]} { testall_cmd sh "module config tcl_linter $nafelgar_script; module lint --redirect $testsuite_modpath.3/lcompat/.version" $tserr {} 0 } + +# test Python module is found if PYTHONPATH is defined +if {$install_setpythonpath eq {y} && [info exists shell_path(python)]} { + # create a temporary script that checks import of module command + # cannot pass the code as argument to python command due to the intermediate processing done by bin/install_* script + set temp_script $env(TESTSUITEDIR)/tempt_script.py + set fid [open $temp_script w] + puts $fid "from env_modules import module\nmodule('list', '-t')" + close $fid + + if {$install_loadedmodules ne ""} { + set tserr "$cur_loaded\n[join $lm_list {.*\n}]" + } else { + set tserr $no_loaded + } + + testall_cmd_re sh "$shell_path(python) $temp_script" {} $tserr 0 + + file delete $temp_script +} + + # # Clean up variables used in this test case # diff --git a/testsuite/modules.50-cmds/400-source-sh.exp b/testsuite/modules.50-cmds/400-source-sh.exp index ed1551156..e4e245d31 100644 --- a/testsuite/modules.50-cmds/400-source-sh.exp +++ b/testsuite/modules.50-cmds/400-source-sh.exp @@ -1602,6 +1602,16 @@ setenv_var TESTSUITE_SHTOMOD_MODULE 1 setenv_var MODULES_SET_SHELL_STARTUP 0 setenv_var MODULES_CMD [file normalize $env(TESTSUITEDIR)/../modulecmd.tcl] +# prepare things if PYTHONPATH is configured by autoinit +if {[is_conf_enabled setpythonpath]} { + unsetenv_var PYTHONPATH + if {[string first { } $install_initdir] != -1} { + set initdirenc "{$install_initdir}" + } else { + set initdirenc $install_initdir + } +} + set lmsourceshpath {} # setup simpler MANPATH value for tests if autoinit adds Modules man location to MANPATH if {$install_setmanpath eq {y}} { @@ -1685,9 +1695,20 @@ if {$is_modules_defined} { set extraans {} } if {$install_versioning eq {y}} { -lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ testsuite\ yes$extraans] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ PYTHONPATH\ $initdirenc\|setenv\ testsuite\ yes$extraans] + } else { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ testsuite\ yes$extraans] + } } else { -lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ testsuite\ yes$extraans] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ PYTHONPATH\ $initdirenc\|setenv\ testsuite\ yes$extraans] + } else { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ testsuite\ yes$extraans] + } +} +if {[is_conf_enabled setpythonpath]} { + lappend ans [list set PYTHONPATH $install_initdir] } if {$install_versioning eq {y}} { lappend ans [list set MODULE_VERSION $install_version] @@ -1740,8 +1761,11 @@ if {$install_versioning eq {y}} { append tserr "setenv\t\tMODULE_VERSION $install_version setenv\t\tMODULE_VERSION_STACK $install_version\n" } -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar -setenv\t\ttestsuite yes$extratserr +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr "\nsetenv\t\ttestsuite yes$extratserr module-whatis\tsource-sh/1 -------------------------------------------------------------------" testouterr_cmd sh {display source-sh/1} OK $tserr @@ -1781,9 +1805,20 @@ lappend ans [list set _LMFILES_ $mp/source-sh/1] lappend ans [list set LOADEDMODULES source-sh/1] lappend ans [list set MODULES_COLLECTION_TARGET bar] if {$install_versioning eq {y}} { -lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ PYTHONPATH\ $initdirenc$extraans] + } else { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + } } else { -lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ PYTHONPATH\ $initdirenc$extraans] + } else { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + } +} +if {[is_conf_enabled setpythonpath]} { + lappend ans [list set PYTHONPATH $install_initdir] } if {$install_versioning eq {y}} { lappend ans [list set MODULE_VERSION $install_version] @@ -1819,9 +1854,20 @@ lappend ans [list set _LMFILES_ $modpath/setenv/1.0:$mp/source-sh/1] lappend ans [list set LOADEDMODULES setenv/1.0:source-sh/1] lappend ans [list set MODULES_COLLECTION_TARGET bar] if {$install_versioning eq {y}} { -lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ PYTHONPATH\ $initdirenc$extraans] + } else { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULE_VERSION\ $install_version\|setenv\ MODULE_VERSION_STACK\ $install_version\|setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + } } else { -lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ PYTHONPATH\ $initdirenc$extraans] + } else { + lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar$extraans] + } +} +if {[is_conf_enabled setpythonpath]} { + lappend ans [list set PYTHONPATH $install_initdir] } if {$install_versioning eq {y}} { lappend ans [list set MODULE_VERSION $install_version] diff --git a/testsuite/modules.70-maint/120-autoinit.exp b/testsuite/modules.70-maint/120-autoinit.exp index 8567f6363..834d01ebb 100644 --- a/testsuite/modules.70-maint/120-autoinit.exp +++ b/testsuite/modules.70-maint/120-autoinit.exp @@ -901,6 +901,16 @@ if {$install_setbinpath eq {y}} { setenv_path_var MODULEPATH $modpath.3 setenv_loaded_module [list foo/1.0] [list $modpath.3/foo/1.0] +# setup PYTHONPATH if changed by autoinit +if {[is_conf_enabled setpythonpath]} { + setenv_var PYTHONPATH /tmp + if {[is_conf_enabled appendpythonpath]} { + set updatedpythonpath /tmp:$install_initdir + } else { + set updatedpythonpath $install_initdir:/tmp + } +} + # ensure ml is set disabled as if modrc1 initrc were previously evaluated # since modulepath and modules are loaded, initrc will not be evaluated by autoinit if {$modrc1_exinstalled} { @@ -912,6 +922,11 @@ foreach set_shell_startup [list {} 0 1] { setenv_var MODULES_SET_SHELL_STARTUP $set_shell_startup foreach shell $supported_shells { + # skip one case where variable definition order is scrambled (not interesting to increase test complexity for this one test) + if {[is_conf_enabled setpythonpath] && $shell eq {ksh} && $set_shell_startup eq {1}} { + continue + } + switch -- $shell { {lisp} { testouterr_cmd "lisp" "autoinit" "ERR" "$err_lisp" @@ -942,6 +957,9 @@ foreach set_shell_startup [list {} 0 1] { lappend ans [list set BASH_ENV $install_initdir/bash] } lappend ans [list set MODULESHOME $moduleshome] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set PYTHONPATH $updatedpythonpath] + } if {$shell eq {ksh}} { lappend ans [list set FPATH $install_initdir/ksh-functions] } @@ -965,6 +983,9 @@ foreach set_shell_startup [list {} 0 1] { lappend ans [list set BASH_ENV $install_initdir/bash] } lappend ans [list set MODULESHOME $moduleshome] + if {[is_conf_enabled setpythonpath]} { + lappend ans [list set PYTHONPATH $updatedpythonpath] + } if {$shell eq {ksh}} { lappend ans [list set FPATH $install_initdir/ksh-functions] } @@ -990,6 +1011,10 @@ set tserr "$err_loinconsist _LMFILES_=" testouterr_cmd_re bash autoinit ERR $tserr +# ensure PYTHONPATH is already initialized for Modules +if {[is_conf_enabled setpythonpath]} { + setenv_var PYTHONPATH $install_initdir +} # coherent environment state with loaded module that defines volatile components setenv_path_var MODULEPATH $modpath.3 diff --git a/testsuite/modules.70-maint/310-sh-to-mod.exp b/testsuite/modules.70-maint/310-sh-to-mod.exp index c9b5cf7bc..646024455 100644 --- a/testsuite/modules.70-maint/310-sh-to-mod.exp +++ b/testsuite/modules.70-maint/310-sh-to-mod.exp @@ -70,6 +70,16 @@ foreach var [array names -glob FOO*] { unsetenv_var $var } +# prepare things if PYTHONPATH is configured by autoinit +if {[is_conf_enabled setpythonpath]} { + unsetenv_var PYTHONPATH + if {[string first { } $install_initdir] != -1} { + set initdirenc "{$install_initdir}" + } else { + set initdirenc $install_initdir + } +} + # expected script env changes set tsvarpre "prepend-path\tFOOPATH /path/to/dir1 /path/to/dir2 /path/to/dir3 prepend-path\tFOOPATHCB /path/to/dir1 /path/to/d\\{r2 /path/to/dir3 @@ -826,8 +836,11 @@ if {$install_versioning eq {y}} { setenv\t\tMODULE_VERSION_STACK $install_version\n" } append tserr $tsvarsetwpath -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar -setenv\t\ttestsuite yes" +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr "\nsetenv\t\ttestsuite yes" set tserrbash "$tserr$extratserr" foreach sh $shtomod_avail_shells { # unset module definition on bash when module is predefined @@ -851,7 +864,11 @@ if {$install_versioning eq {y}} { setenv\t\tMODULE_VERSION_STACK $install_version\n" } append tserr $tsvarsetwpath -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar$extratserr" +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr $extratserr testouterr_shtomod bash {} OK $tserr # module is loaded prior sh-to-mod @@ -863,7 +880,11 @@ if {$install_versioning eq {y}} { setenv\t\tMODULE_VERSION_STACK $install_version\n" } append tserr $tsvarsetwpath -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar$extratserr" +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr $extratserr testouterr_shtomod bash {} OK $tserr diff --git a/testsuite/modules.70-maint/311-eval-sh-to-mod.exp b/testsuite/modules.70-maint/311-eval-sh-to-mod.exp index 2f3e6360c..f0f34f979 100644 --- a/testsuite/modules.70-maint/311-eval-sh-to-mod.exp +++ b/testsuite/modules.70-maint/311-eval-sh-to-mod.exp @@ -71,6 +71,16 @@ foreach var [array names -glob FOO*] { unsetenv_var $var } +# prepare things if PYTHONPATH is configured by autoinit +if {[is_conf_enabled setpythonpath]} { + unsetenv_var PYTHONPATH + if {[string first { } $install_initdir] != -1} { + set initdirenc "{$install_initdir}" + } else { + set initdirenc $install_initdir + } +} + # expected script env changes set tsvarpre "prepend-path\tFOOPATH /path/to/dir1 /path/to/dir2 /path/to/dir3 prepend-path\tFOOPATHCB /path/to/dir1 /path/to/d\\{r2 /path/to/dir3 @@ -495,8 +505,11 @@ if {$install_versioning eq {y}} { setenv\t\tMODULE_VERSION_STACK $install_version\n" } append tserr $tsvarsetwpath -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar -setenv\t\ttestsuite yes" +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr "\nsetenv\t\ttestsuite yes" set tserrbash "$tserr$extratserr" foreach sh $shtomod_avail_shells { # unset module definition on bash when module is predefined @@ -514,7 +527,11 @@ if {$install_versioning eq {y}} { setenv\t\tMODULE_VERSION_STACK $install_version\n" } append tserr $tsvarsetwpath -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar$extratserr" +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr $extratserr testouterr_shtomod bash-eval {} OK $tserr # module is loaded prior sh-to-mod @@ -526,7 +543,11 @@ if {$install_versioning eq {y}} { setenv\t\tMODULE_VERSION_STACK $install_version\n" } append tserr $tsvarsetwpath -append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar$extratserr" +append tserr "setenv\t\tMODULES_COLLECTION_TARGET bar" +if {[is_conf_enabled setpythonpath]} { + append tserr "\nsetenv\t\tPYTHONPATH $initdirenc" +} +append tserr $extratserr testouterr_shtomod bash-eval {} OK $tserr