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
6 changes: 6 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ Modules 5.8.0 (not yet released)
evaluated with :mfcmd:`source-sh` modulefile command or :subcmd:`sh-to-mod`
sub-command. ``umask`` element is added to the ``--ignore`` option of
:mfcmd:`source-sh`.
* Add the :option:`--ignore` option to the :subcmd:`sh-to-mod` sub-command
to ignore the changes made by the evaluated shell script on specified shell
elements, like done by the ``--ignore`` option of :mfcmd:`source-sh`
modulefile command. (fix issue #532)
* Fix :command:`ml` command to correctly call a sub-command when command
line switches like :option:`--tag` are set before the sub-command name.


.. _5.7 release notes:
Expand Down
5 changes: 5 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@ The following command line switches appeared on Modules 5.
| 5.7 | :option:`-p`, :option:`-P`, |
| | :option:`--no-modulepath-ignore` |
+------------+-----------------------------------------------------------------+
| 5.8 | :option:`--ignore` |
+------------+-----------------------------------------------------------------+

:option:`--output`

Expand Down Expand Up @@ -1009,6 +1011,9 @@ The following module sub-commands appeared on Modules 5.

Shell mode ``bash-eval`` is introduced on Modules version ``5.4``.

Starting Modules 5.8, the :option:`--ignore` option is added to ignore the
changes made by shell script on specified shell elements.

:subcmd:`source`

Starting Modules 5.2, this sub-command accepts modulefile specification as
Expand Down
4 changes: 4 additions & 0 deletions doc/source/design/source-shell-script-in-modulefile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ Specification
- ``umask`` (added in version 5.8)

- Shell elements changed by sourced script and listed on ``--ignore`` option are ignored (no modulefile command relative to these changes are produced)
- Option is also available on ``sh-to-mod`` sub-command starting version 5.8

- Set before the sub-command name, ``--ignore`` and its value are moved right after this name
- Set after the *shell* argument, they are left in place as they are then arguments for the script

- **FUTURE**: this feature may be extended to translate environment changes made by tools like Spack, Lmod or pkg-config. It may provide this way bridges between different realms.

Expand Down
23 changes: 22 additions & 1 deletion doc/source/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ switches are accepted:
search query string and module specification on all sub-commands and
modulefile Tcl commands.

.. option:: --ignore LIST

On :subcmd:`sh-to-mod` sub-command, ignore the changes made by the evaluated
shell script on the shell elements in *LIST*. *LIST* corresponds to the
concatenation of multiple shell elements separated by colon character
(``:``). Accepted shell elements are: ``envvar``, ``alias``, ``function``,
``chdir``, ``complete`` and ``umask``.

.. only:: html or latex

.. versionadded:: 5.8

.. option:: --ignore-cache

Ignore module cache.
Expand Down Expand Up @@ -2788,7 +2800,7 @@ Module Sub-Commands
:option:`--terse`/:option:`-t` added to get one output line per
*module-whatis* line

.. subcmd:: sh-to-mod shell script [arg...]
.. subcmd:: sh-to-mod [--ignore LIST] shell script [arg...]

Evaluate with *shell* the designated *script* with defined *arguments* to
find out the environment changes it does. Environment prior and after
Expand All @@ -2811,6 +2823,12 @@ Module Sub-Commands
is not sourced but the output resulting from its execution is evaluated to
determine the environment changes it does.

The :option:`--ignore` option accepts a *LIST* of shell elements whose
changes made by *script* should be ignored, like the ``--ignore`` option of
:mfcmd:`source-sh` modulefile command. No modulefile command is produced for
the changes made on these elements. :option:`--ignore` and its value should
be set before *shell*, otherwise they are considered arguments of *script*.

.. note:: *shell* is run in non-interactive mode without loading any shell
configuration or profile. As a result, script does not have access to
transient definitions that are only available in interactive sessions or
Expand Down Expand Up @@ -2838,6 +2856,9 @@ Module Sub-Commands
.. versionchanged:: 5.8
Support for tracking file mode creation mask changes added

.. versionchanged:: 5.8
Option :option:`--ignore` added

.. subcmd:: show modulefile...

See :subcmd:`display`.
Expand Down
2 changes: 2 additions & 0 deletions init/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ comp_isavail_opts := -i --icase
comp_lint_opts := -a -i --all --icase
comp_modtosh_opts := --auto --no-auto --force -f --icase -i
comp_purge_opts := --force -f
comp_shtomod_opts := --ignore
comp_reload_opts := --force -f
comp_reset_opts := --force -f
comp_restore_opts := --force -f
Expand Down Expand Up @@ -183,6 +184,7 @@ sed -e 's|@prefix@|$(prefix)|g' \
-e 's|@comp_isavail_opts@|$(comp_isavail_opts)|g' \
-e 's|@comp_lint_opts@|$(comp_lint_opts)|g' \
-e 's|@comp_modtosh_opts@|$(comp_modtosh_opts)|g' \
-e 's|@comp_shtomod_opts@|$(comp_shtomod_opts)|g' \
-e 's|@comp_purge_opts@|$(comp_purge_opts)|g' \
-e 's|@comp_reload_opts@|$(comp_reload_opts)|g' \
-e 's|@comp_reset_opts@|$(comp_reset_opts)|g' \
Expand Down
12 changes: 10 additions & 2 deletions init/bash_completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ _module() {
-*) COMPREPLY=( $(compgen -W "@comp_source_opts@" -- "$cur") );;
*) ;; # let readline handle the completion
esac;;
-h|--help|-V|--version|--dumpname|refresh|sh-to-mod|state|stashclear|cacheclear)
sh-to-mod) case "$cur" in
-*) _module_comgen_words "@comp_shtomod_opts@" "$cur";;
*) ;; # let readline handle the completion
esac;;
-h|--help|-V|--version|--dumpname|refresh|state|stashclear|cacheclear)
;;
append-path|prepend-path)
COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
Expand Down Expand Up @@ -211,7 +215,11 @@ if type -t ml >/dev/null; then
-*) COMPREPLY=( $(compgen -W "@comp_source_opts@" -- "$cur") );;
*) ;; # let readline handle the completion
esac;;
-h|--help|-V|--version|--dumpname|refresh|sh-to-mod|state|stashclear|cacheclear)
sh-to-mod) case "$cur" in
-*) _module_comgen_words "@comp_shtomod_opts@" "$cur";;
*) ;; # let readline handle the completion
esac;;
-h|--help|-V|--version|--dumpname|refresh|state|stashclear|cacheclear)
;;
append-path|prepend-path)
COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
Expand Down
1 change: 1 addition & 0 deletions init/fish_completion
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ complete -c module -l no-modulepath-ignore --description 'Do not apply modulepat
complete -c module -l append --description 'Append directory to MODULEPATH'
complete -c module -l prepend --description 'Prepend directory to MODULEPATH'
complete -c module -l priority --description 'Set priority of path element'
complete -c module -l ignore --description 'Ignore kinds of environment change made by script'
complete -c module -l timer --description 'Report execution times'
complete -c module -l redirect --description 'Send output to stdout'
complete -c module -l no-redirect --description 'Send output to stderr'
2 changes: 1 addition & 1 deletion init/tcsh_completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ complete module 'C,/*,f,' 'C,.*,f,' 'C,~/*,f,' \
'n/paths/`_module_avail; echo "@comp_mfile_opts@"`/' \
'n/path/`_module_avail; echo "@comp_mfile_opts@"`/' \
'n/edit/`_module_avail`/' \
'n/sh-to-mod/n/' \
"n/sh-to-mod/(@comp_shtomod_opts@)/" \
'n/source/f/' \
"n/append-path/(@comp_path_opts@)/" \
"n/prepend-path/(@comp_path_opts@)/" \
Expand Down
5 changes: 5 additions & 0 deletions init/zsh-functions/_module.in
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ _module() {
'(-i --icase)'{-i,--icase}'[Case insensitive match]' \
"*::modulefile:{_module_notloaded_mods $cur}" && ret=0
;;
(sh-to-mod)
_arguments \
'--ignore[Ignore kinds of environment change made by script]' \
&& ret=0
;;
(source)
_arguments \
'--auto[Enable automated module handling mode]' \
Expand Down
39 changes: 35 additions & 4 deletions tcl/main.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ proc parseModuleCommandArgs {topcall cmd ignerr ml_spec args} {
--output {
knerror "Missing value for '$arg' option"
}
--ignore {
# switch and its value are parsed by sh-to-mod sub-command
if {$cmd eq {sh-to-mod}} {
lappend otherargs $arg
} else {
if {!$ignerr} {
knerror "Unsupported option '$arg' on $cmd sub-command"
}
set ignore_next_arg 1
}
}
default {
lappend otherargs $arg
}
Expand Down Expand Up @@ -557,8 +568,10 @@ proc ml {args} {
}
set margs $args
} else {
# first argument was command name
set margs [lrange $args 1 end]
# withdraw command name from argument list: it is not the first
# argument if some switches are set before it
set cmdidx [lsearch -exact $args [lindex $fargs 0]]
set margs [lreplace $args $cmdidx $cmdidx]
}

# directly call module procedure if sub-command spotted as first argument
Expand Down Expand Up @@ -675,6 +688,7 @@ if {[catch {
# extract options and command switches from other args
set otherargv {}
set extraargv {}
set firstargv {}
set ddelimarg 0
# split first arg if multi-word string detected for compat with previous
# doc on module usage with scripting language: module('load mod1 mod2')
Expand All @@ -690,6 +704,9 @@ if {[catch {
} elseif {[info exists nextargisotherargv]} {
lappend otherargv $arg
unset nextargisotherargv
} elseif {[info exists nextargisfirstargv]} {
lappend firstargv $arg
unset nextargisfirstargv
} elseif {[info exists nextargisval]} {
##nagelfar vartype nextargisval varName
set $nextargisval $arg
Expand Down Expand Up @@ -808,6 +825,18 @@ if {[catch {
lappend otherargv $arg
set nextargisotherargv 1
}
--ignore {
# set before sub-command name, switch and its value are moved
# right after this name. set after, they are kept in place as
# they may be arguments of the script passed to sh-to-mod
if {[llength $otherargv]} {
lappend otherargv $arg
set nextargisotherargv 1
} else {
lappend firstargv $arg
set nextargisfirstargv 1
}
}
append-path - prepend-path - remove-path {
# detect *-path commands to say -d means --delim, not --default
set ddelimarg 1
Expand Down Expand Up @@ -882,7 +911,8 @@ if {[catch {
}
}

if {[info exists nextargisextraargv]} {
if {[info exists nextargisextraargv] || [info exists\
nextargisfirstargv]} {
reportErrorAndExit "Missing value for '$prevarg' option\nTry 'module\
--help' for more information."
}
Expand All @@ -900,7 +930,8 @@ if {[catch {
}

setState subcmd [lindex $otherargv 0]
set otherargv [list {*}[lreplace $otherargv 0 0] {*}$extraargv]
set otherargv [list {*}$firstargv {*}[lreplace $otherargv 0 0]\
{*}$extraargv]
setState subcmd_args $otherargv
# call ml frontend if it is asked command
if {[getState subcmd] eq {ml}} {
Expand Down
24 changes: 15 additions & 9 deletions tcl/mfcmd.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,9 @@ proc sh-to-mod {elt_ignored_list args} {
return $modcontent
}

proc parseSourceShArgs {args} {
# parse arguments of source-sh modulefile command or sh-to-mod sub-command,
# which is designated by cmd
proc parseSourceShArgs {cmd args} {
set elt_ignored_list {}

set i 0
Expand Down Expand Up @@ -2013,8 +2015,12 @@ proc parseSourceShArgs {args} {
}

if {![info exists shell] || $i == [llength $args]} {
knerror "wrong # args: should be \"source-sh ?--ignore? ?eltlist? shell\
script ?arg ...?\""
if {$cmd eq {sh-to-mod}} {
knerrorModule 1 "Unexpected number of args for '$cmd' command"
} else {
knerror "wrong # args: should be \"source-sh ?--ignore? ?eltlist?\
shell script ?arg ...?\""
}
}

set script_args [lassign [lrange $args $i end] script]
Expand All @@ -2034,8 +2040,8 @@ proc parseSourceShArgs {args} {
}

proc source-sh {args} {
lassign [parseSourceShArgs {*}$args] elt_ignored_list shell script\
script_args
lassign [parseSourceShArgs source-sh {*}$args] elt_ignored_list shell\
script script_args
# evaluate script and get the environment changes it performs translated
# into modulefile commands
set shtomodargs [list $shell $script {*}$script_args]
Expand All @@ -2056,8 +2062,8 @@ proc source-sh {args} {

# undo source-sh in unload mode
proc source-sh-un {args} {
lassign [parseSourceShArgs {*}$args] elt_ignored_list shell script\
script_args
lassign [parseSourceShArgs source-sh {*}$args] elt_ignored_list shell\
script script_args
set shtomodargs [list $shell $script {*}$script_args]
# find commands resulting from source-sh evaluation recorded in env
set modcontent [getLoadedSourceShScriptContent [currentState modulename]\
Expand All @@ -2074,8 +2080,8 @@ proc source-sh-un {args} {

# report underlying modulefile cmds in display mode
proc source-sh-di {args} {
lassign [parseSourceShArgs {*}$args] elt_ignored_list shell script\
script_args
lassign [parseSourceShArgs source-sh {*}$args] elt_ignored_list shell\
script script_args
set shtomodargs [list $shell $script {*}$script_args]

# if module loaded, get as much content from environment as possible
Expand Down
5 changes: 4 additions & 1 deletion tcl/report.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ Other commands:
config [--dump-state|name [val]|--reset name]
Display or set Modules configuration
state [name] Display Modules state
sh-to-mod shell shellscript [arg ...]
sh-to-mod [--ignore LIST] shell shellscript [arg ...]
Make modulefile from script env changes
mod-to-sh [-f] [-i] [--auto|--no-auto] shell modulefile [...]
Make shell code from modulefile env changes
Expand Down Expand Up @@ -2209,6 +2209,9 @@ Switches:
sub-commands)
--priority N Set priority of path elements (on 'use', 'prepend-path' or
'append-path' sub-commands)
--ignore LIST Ignore kinds of environment change made by script on
'sh-to-mod' sub-command (LIST is made of element names
separated by ':')
--index Given value is an index in the variable's list, instead of
a value to look up (on 'remove-path' sub-command)

Expand Down
6 changes: 4 additions & 2 deletions tcl/subcmd.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -2668,11 +2668,13 @@ proc cmdModuleConfig {dump_state args} {
}

proc cmdModuleShToMod {args} {
set scriptargs [lassign $args shell script]
lassign [parseSourceShArgs sh-to-mod {*}$args] elt_ignored_list shell\
script script_args

# evaluate script and get the environment changes it performs translated
# into modulefile commands
set modcontent [sh-to-mod {} {*}$args]
set modcontent [sh-to-mod $elt_ignored_list $shell $script\
{*}$script_args]

# output resulting modulefile
if {[llength $modcontent]} {
Expand Down
10 changes: 10 additions & 0 deletions testsuite/completion.00-init/021-bash.exp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ foreach subcmd $help_subcmds {
## zero completions, not just an ambiguous one
set got [completion_bash_inline "module $subcmd -"]
completion_assert_eq $got "\a"
} elseif {[llength $expected] == 1} {
## a single option is completed inline by the first Tab, so there is
## no listing to get: check the text inserted after the typed '-'
set got [completion_bash_inline "module $subcmd -"]
completion_assert_eq -[string trim $got] [lindex $expected 0]
} else {
## 'config' is the only sub-command whose every option is long-form
## only ('--dump-state'/'--reset', no '-x' short forms): from a
Expand Down Expand Up @@ -363,6 +368,11 @@ foreach subcmd $help_subcmds {
if {[llength $expected] == 0} {
set got [completion_bash_inline "ml $subcmd -"]
completion_assert_eq $got "\a"
} elseif {[llength $expected] == 1} {
## a single option is completed inline by the first Tab, so there is
## no listing to get: check the text inserted after the typed '-'
set got [completion_bash_inline "ml $subcmd -"]
completion_assert_eq -[string trim $got] [lindex $expected 0]
} else {
set dash [expr {$subcmd eq {config} ? {--} : {-}}]
set got [completion_bash_list "ml $subcmd $dash"]
Expand Down
5 changes: 5 additions & 0 deletions testsuite/completion.00-init/031-zsh.exp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ foreach subcmd $help_subcmds {
## nothing to insert
set got [completion_zsh_inline "module $subcmd -"]
completion_assert_eq $got "\a"
} elseif {[llength $expected] == 1} {
## a single option is completed inline by the first Tab, so there is
## no listing to get: check the text inserted after the typed '-'
set got [completion_zsh_inline "module $subcmd -"]
completion_assert_eq -[string trim $got] [lindex $expected 0]
} else {
## 'config' is the only sub-command whose every option is long-form
## only ('--dump-state'/'--reset', no '-x' short forms): from a
Expand Down
Loading
Loading