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
4 changes: 4 additions & 0 deletions .hunspell.en.dic
Original file line number Diff line number Diff line change
Expand Up @@ -1634,3 +1634,7 @@ defineModStartNbProc
isIcase
CVE
backport
moduleversion
myModuleFullName
myModuleName
myModuleVersion
3 changes: 3 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Modules 5.8.0 (not yet released)
designated by :instopt:`--with-tcl` when :instopt:`--with-tclsh` is not set,
so that installed scripts run with the same Tcl the extension library is
built against. (fix issue #717)
* Add :mfcmd:`module-info modulename<module-info>` and :mfcmd:`module-info
moduleversion<module-info>` modulefile commands to get the name part and
the version part of currently evaluating modulefile. (fix issue #713)


.. _5.7 release notes:
Expand Down
3 changes: 3 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,9 @@ The following modulefile Tcl commands appeared on Modules 5.
+------------+-----------------------------------------------------------------+
| 5.7 | :mfcmd:`modulepath-ignore` |
+------------+-----------------------------------------------------------------+
| 5.8 | :mfcmd:`module-info modulename<module-info>`, |
| | :mfcmd:`module-info moduleversion<module-info>` |
+------------+-----------------------------------------------------------------+

:mfcmd:`system`, :mfcmd:`is-used`

Expand Down
9 changes: 9 additions & 0 deletions doc/source/cookbook/module-info-name-return-basename.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ as once loaded this module is identified by its full pathname. This recipe
describes a way to get back the behavior of Modules compatibility version for
the ``module-info name`` modulefile command.

.. note::

Starting Modules 5.8, the :mfcmd:`module-info moduleversion<module-info>`
modulefile command returns the part of the module name after its last
``/`` character, which is the file basename when module is specified as a
full path. It can be used instead of this recipe when the goal is to get
this basename rather than to change the result of :mfcmd:`module-info
name<module-info>`.

Implementation
--------------

Expand Down
43 changes: 43 additions & 0 deletions doc/source/modulefile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,45 @@ the *modulefile* is being loaded.
``refresh``, ``nonpersist`` (alias of ``refresh``), ``display``, ``help``,
``test``, ``whatis`` or ``scan``.

**module-info modulename**

Return the name of currently evaluating *modulefile* without its version
part, which is the string returned by :mfcmd:`module-info
name<module-info>` without the last ``/`` character and what follows it.
Returns ``app`` for a *modulefile* named ``app/1.2.3`` and ``compiler/gcc``
for ``compiler/gcc/12.1``. Returns the full name if it contains no ``/``
character.

If currently evaluating *modulefile* has been specified as a full path,
:mfcmd:`module-info name<module-info>` returns this full path, so
:mfcmd:`module-info modulename<module-info>` returns the directory part of
this path.

.. only:: html or latex

.. versionadded:: 5.8

**module-info moduleversion**

Return the version of currently evaluating *modulefile*, which is the part
after the last ``/`` character of the string returned by
:mfcmd:`module-info name<module-info>`. Returns ``1.2.3`` for a
*modulefile* named ``app/1.2.3`` and ``12.1`` for ``compiler/gcc/12.1``.
Returns an empty string if the name contains no ``/`` character.

Symbolic versions and aliases are resolved as for :mfcmd:`module-info
name<module-info>`, so the version of the resolved *modulefile* is
returned. Variants are not included in the returned string.

If currently evaluating *modulefile* has been specified as a full path,
:mfcmd:`module-info name<module-info>` returns this full path, so
:mfcmd:`module-info moduleversion<module-info>` returns the file basename of
this path.

.. only:: html or latex

.. versionadded:: 5.8

**module-info name**

Return the name of the *modulefile*. This is not the full pathname for
Expand All @@ -886,6 +925,10 @@ the *modulefile* is being loaded.
See :mfcmd:`getvariant` command or :mfvar:`ModuleVariant` array variable to
get defined variant values for currently evaluating *modulefile*.

See :mfcmd:`module-info modulename<module-info>` and :mfcmd:`module-info
moduleversion<module-info>` to get separately the name and version parts of
the returned string.

**module-info shell** [shellname]

Return the current shell under which :file:`modulecmd.tcl` was invoked if
Expand Down
11 changes: 9 additions & 2 deletions doc/source/other-implementations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ table highlights features that are unique to each implementation.
* Handle modulefile outside modulepath
* :ref:`Case insensitive module load<Insensitive case>`
* Automatic ``latest`` and ``loaded`` symbols
* ``alias``, ``command``, ``loaded``, ``tags``, ``usergroups`` and
``username`` sub-commands of :mfcmd:`module-info`
* ``alias``, ``command``, ``loaded``, ``modulename``,
``moduleversion``, ``tags``, ``usergroups`` and ``username``
sub-commands of :mfcmd:`module-info`
* :ref:`Super-sticky modules<Sticky modules>`
* :ref:`Fine-tuned output configuration<--output>`
* :ref:`Editing modulefiles`
Expand Down Expand Up @@ -217,6 +218,12 @@ implementation.
- |foo@5.0:7.0|_
* - ``latest("foo")``
- |foo@latest|_
* - ``myModuleFullName()``
- :mfcmd:`module-info name<module-info>`
* - ``myModuleName()``
- :mfcmd:`module-info modulename<module-info>`
* - ``myModuleVersion()``
- :mfcmd:`module-info moduleversion<module-info>`

.. _Irreversible module actions: https://lmod.readthedocs.io/en/latest/370_irreversible.html
.. _NAG file: https://lmod.readthedocs.io/en/latest/140_deprecating_modules.html
Expand Down
40 changes: 37 additions & 3 deletions doc/source/user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,42 @@ This allows users to write:

:ps:`$` module load openmpi %gcc

``module-info``
^^^^^^^^^^^^^^^

The :mfcmd:`module-info` modulefile command provides information about the
current evaluation context, like the name of the module being evaluated or
the evaluation mode.

The :mfcmd:`module-info name<module-info>` sub-command returns the full name
of the evaluating module, like ``app/1.2.3``. Modulefiles often need only
the version part of this name, to build an installation path for instance.
The :mfcmd:`module-info moduleversion<module-info>` sub-command returns this
part, what follows the last ``/`` character of the module name, and the
:mfcmd:`module-info modulename<module-info>` sub-command returns what comes
before this character.

For example:

.. code-block:: tcl

#%Module

set prefix /opt/[module-info modulename]/[module-info moduleversion]
prepend-path PATH $prefix/bin

For a module named ``compiler/gcc/12.1``, :mfcmd:`module-info
modulename<module-info>` returns ``compiler/gcc`` and :mfcmd:`module-info
moduleversion<module-info>` returns ``12.1``. If the module name contains no
``/`` character, the full name is returned as name part and the version part
is an empty string.

.. tip::

Symbolic versions and aliases are resolved before the modulefile is
evaluated, so these sub-commands always report the name of the resolved
modulefile.

Advanced manipulations
----------------------

Expand Down Expand Up @@ -1085,9 +1121,7 @@ name being evaluated.

#%Module

set version [lindex [split [module-info name] /] end]

setenv APP_VERSION $version
setenv APP_VERSION [module-info moduleversion]

Module logger
^^^^^^^^^^^^^
Expand Down
8 changes: 5 additions & 3 deletions share/nagelfar/syntaxdb_modulefile.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ set {::syntax(module-info alias)} 1
set {::syntax(module-info command)} x?
set {::syntax(module-info loaded)} 1
set {::syntax(module-info mode)} x?
set {::syntax(module-info modulename)} 0
set {::syntax(module-info moduleversion)} 0
set {::syntax(module-info name)} 0
set {::syntax(module-info shell)} x?
set {::syntax(module-info shelltype)} x?
Expand Down Expand Up @@ -240,9 +242,9 @@ set ::subCmd(module) {add load add-any load-any swap switch try-add try-load\
initadd initload initclear initlist initprepend initunload initrm\
initswap initswitch list purge reload restore save savelist saverm disable\
saveshow describe apropos keyword search test update whatis}
set ::subCmd(module-info) {alias command loaded mode name shell shelltype\
specified symbols tags type usergroups username version user trace\
tracepat flags}
set ::subCmd(module-info) {alias command loaded mode modulename moduleversion\
name shell shelltype specified symbols tags type usergroups username\
version user trace tracepat flags}
set ::subCmd(uname) {sysname nodename domain release version machine}

# option
Expand Down
8 changes: 5 additions & 3 deletions share/nagelfar/syntaxdb_modulerc.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ set {::syntax(module-info alias)} 1
set {::syntax(module-info command)} x?
set {::syntax(module-info loaded)} 1
set {::syntax(module-info mode)} x?
set {::syntax(module-info modulename)} 0
set {::syntax(module-info moduleversion)} 0
set {::syntax(module-info name)} 0
set {::syntax(module-info shell)} x?
set {::syntax(module-info shelltype)} x?
Expand Down Expand Up @@ -96,9 +98,9 @@ set {::return(module-info flags)} int

# subCmd
set ::subCmd(lsb-release) {id release codename}
set ::subCmd(module-info) {alias command loaded mode name shell shelltype\
specified symbols tags type usergroups username version user trace\
tracepat flags}
set ::subCmd(module-info) {alias command loaded mode modulename moduleversion\
name shell shelltype specified symbols tags type usergroups username\
version user trace tracepat flags}
set ::subCmd(uname) {sysname nodename domain release version machine}

# option
Expand Down
19 changes: 19 additions & 0 deletions tcl/mfcmd.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ proc module-info {what {more {}}} {
name {
return [currentState modulename]
}
modulename {
set modname [currentState modulename]
set idx [string last / $modname]
# whole name is the name part if it has no version separator
if {$idx == -1} {
return $modname
} else {
return [string range $modname 0 $idx-1]
}
}
moduleversion {
set modname [currentState modulename]
set idx [string last / $modname]
if {$idx == -1} {
return {}
} else {
return [string range $modname $idx+1 end]
}
}
specified {
return [currentState specifiedname]
}
Expand Down
9 changes: 9 additions & 0 deletions testsuite/modulefiles.5/.modulerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#%Module
if {[info exists env(TESTSUITE_INFO_MODULENAME)]} {
switch -- $env(TESTSUITE_INFO_MODULENAME) {
sym {
module-version info-name/1.2.3 sym
module-alias info-name-alias info-name/sub/2.0
}
}
}
4 changes: 4 additions & 0 deletions testsuite/modulefiles.5/info-name/1.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#%Module
setenv TS_NAME [module-info name]
setenv TS_MODULENAME [module-info modulename]
setenv TS_MODULEVERSION [module-info moduleversion]
4 changes: 4 additions & 0 deletions testsuite/modulefiles.5/info-name/1.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#%Module
setenv TS_NAME [module-info name]
setenv TS_MODULENAME [module-info modulename]
setenv TS_MODULEVERSION [module-info moduleversion]
4 changes: 4 additions & 0 deletions testsuite/modulefiles.5/info-name/sub/2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#%Module
setenv TS_NAME [module-info name]
setenv TS_MODULENAME [module-info modulename]
setenv TS_MODULEVERSION [module-info moduleversion]
4 changes: 4 additions & 0 deletions testsuite/modulefiles.5/info-noversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#%Module
setenv TS_NAME [module-info name]
setenv TS_MODULENAME [module-info modulename]
setenv TS_MODULEVERSION [module-info moduleversion]
Loading
Loading