Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/linux_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .hunspell.en.dic
Original file line number Diff line number Diff line change
Expand Up @@ -1339,3 +1339,5 @@ OSX
BAWT
HTTPS
mirrorEnvVarChange
PYTHONPATH
pythonpath
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 or latex

.. versionadded:: 5.7

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

Set modulecmd.tcl to automatically apply automated modulefiles handling
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' \
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
15 changes: 15 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,6 +53,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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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") ;;
Expand Down
4 changes: 4 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions doc/source/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -130,8 +137,17 @@ Python:

.. parsed-literal::

import os
exec(open("\ |initdir|\ /python.py").read(), globals())
from env_modules import module
module("load", "modulefile", "modulefile", "...")

Alternative initialization for Python if ``env_modules`` script is not part of
an enabled Python module directory:

.. parsed-literal::

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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
File renamed without changes.
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 @@ -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]} {
Expand Down
22 changes: 22 additions & 0 deletions testsuite/install.00-init/030-options.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
Loading
Loading