Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

.. versionadded:: 5.7

.. instopt:: --enable-auto-handling

Set modulecmd.tcl to automatically apply automated modulefiles handling
Expand Down Expand Up @@ -799,6 +808,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

.. versionadded:: 5.7

.. instopt:: --enable-set-shell-startup

Set when module function is defined the shell startup file to ensure that the
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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
Expand Down Expand Up @@ -479,6 +489,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' \
Expand Down
2 changes: 2 additions & 0 deletions Makefile.inc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down
13 changes: 12 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ listterseoutput editor variantshortcut bashcompletiondir fishcompletiondir \
zshcompletiondir tcllinter tcllinteropts nagelfardatadir nagelfaraddons \
stickypurge uniquenameloaded abortonerror sourcecache logger loggeropts \
loggedevents conflictunload spideroutput spiderterseoutput spiderindepth \
emacsdatadir emacsaddons requirevia"
emacsdatadir emacsaddons requirevia setpythonpath appendpythonpath"
libarglist=()

# flags to know if argument has been specified on command-line
Expand All @@ -52,6 +52,8 @@ defloggeropts=1
prefix=/usr/local/Modules
setmanpath=y
appendmanpath=n
setpythonpath=y
appendpythonpath=n
setbinpath=y
appendbinpath=n
setmodulespath=n
Expand Down Expand Up @@ -237,6 +239,9 @@ Optional Features:
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-set-manpath set mandir to MANPATH in init scripts [yes]
--enable-append-manpath append rather prepend mandir to MANPATH [no]
--enable-set-pythonpath set initdir to PYTHONPATH in init scripts [yes]
--enable-append-pythonpath
append rather prepend initdir to PYTHONPATH [no]
--enable-set-binpath set bindir to PATH in init scripts [yes]
--enable-append-binpath append rather prepend bindir to PATH [no]
--enable-modulespath, --enable-dotmodulespath
Expand Down Expand Up @@ -720,6 +725,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") ;;
Expand Down
14 changes: 12 additions & 2 deletions doc/source/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion init/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/csh
/tcsh
/perl.pm
/python.py
/env_modules.py
/ruby.rb
/lisp
/cmake
Expand Down
7 changes: 4 additions & 3 deletions init/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -246,6 +246,7 @@ endif
$(INSTALL_DIR) '$(DESTDIR)$(zshcompletiondir)'
$(INSTALL_DIR) '$(DESTDIR)$(modulefilesdir)'
$(INSTALL_DATA) $(ALL_SHELLS) '$(DESTDIR)$(initdir)/'
ln -s env_modules.py '$(DESTDIR)$(initdir)/python.py'
ifeq ($(windowssupport),y)
$(INSTALL_DATA) cmd.cmd '$(DESTDIR)$(initdir)/'
endif
Expand Down Expand Up @@ -276,7 +277,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
Expand Down Expand Up @@ -324,7 +325,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
1 change: 0 additions & 1 deletion init/python.py.in → init/env_modules.py.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import os, sys, re, subprocess

# define modules runtime quarantine configuration
Expand Down
2 changes: 2 additions & 0 deletions site.exp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
Expand Down
5 changes: 5 additions & 0 deletions tcl/subcmd.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,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]} {
Expand Down