| 1 |
.. _new-features-without-breaking-old-module: |
| 2 |
|
| 3 |
Use new features without breaking old module command |
| 4 |
==================================================== |
| 5 |
|
| 6 |
When working on large infrastructure, sometimes the ``module`` command is not |
| 7 |
deployed with the same version everywhere. You may have for instance some old |
| 8 |
cluster that still uses Modules version 3.2 and a newer supercomputer where |
| 9 |
the latest version of Modules 4 is available. In such situation it may |
| 10 |
however be desired to share the same modulefile catalog. |
| 11 |
|
| 12 |
People providing software that build software and generate the modulefiles to |
| 13 |
access them fall in a similar situation: a large variety of Modules version |
| 14 |
may be in use by the end-users of their build product. |
| 15 |
|
| 16 |
This recipe describes how to use features from the latest version of Modules 4 |
| 17 |
in modulefiles without breaking the use of these modulefiles from older |
| 18 |
Modules version. |
| 19 |
|
| 20 |
Implementation |
| 21 |
-------------- |
| 22 |
|
| 23 |
The Tcl language provides some introspection mechanisms that help to know what |
| 24 |
Tcl procedures are available. In the modulefile or modulerc evaluation |
| 25 |
context, it helps to determine what Tcl modulefile commands are known. So by |
| 26 |
crafting a conditional test using such mechanism (with Tcl ``info commands`` |
| 27 |
command) it is possible to test if a new feature is available prior using it. |
| 28 |
|
| 29 |
.. literalinclude:: ../../example/new-features-without-breaking-old-module/modulefiles/.modulerc |
| 30 |
:language: tcl |
| 31 |
:caption: .modulerc |
| 32 |
|
| 33 |
**Compatible with Modules v3.2+** |
| 34 |
|
| 35 |
Starting version 4.7 of Modules, two new Tcl variables are introduced in the |
| 36 |
modulefile and modulerc evaluation context: :mfvar:`ModuleTool` and |
| 37 |
:mfvar:`ModuleToolVersion`. These two variables help to determine respectively |
| 38 |
what is the module implementation running and what is its version. With this |
| 39 |
knowledge it is possible to adapt modulefile and modulerc code to cope with a |
| 40 |
behavior changing over module versions or with different behaviors between |
| 41 |
different module implementation. The Tcl modulefile command |
| 42 |
:mfcmd:`versioncmp` has been added along to help comparing software version |
| 43 |
number (e.g. ``4.10`` is newer than ``4.7``). |
| 44 |
|
| 45 |
Starting its version ``8.4.8``, the Lmod_ project also supports the |
| 46 |
:mfvar:`ModuleTool` and :mfvar:`ModuleToolVersion` variables and the |
| 47 |
:mfcmd:`versioncmp` modulefile command. It enables having modulefiles |
| 48 |
compatible with both module implementations without restricting yourself from |
| 49 |
using the advanced features from both projects. |
| 50 |
|
| 51 |
.. _Lmod: https://github.com/TACC/Lmod |
| 52 |
|
| 53 |
**Compatible with Modules v4.7+** |
| 54 |
|
| 55 |
Usage example |
| 56 |
------------- |
| 57 |
|
| 58 |
For this recipe, a *foo* module is available in version *1.1* and *1.2*. |
| 59 |
Version *1.1* is outdated and it has been decided to hide and forbid it |
| 60 |
starting October 2020. For that, the new :mfcmd:`module-hide` and |
| 61 |
:mfcmd:`module-forbid` modulefile commands introduced in Modules 4.6 are used. |
| 62 |
|
| 63 |
Enable the modulepath where the example modulefiles are located:: |
| 64 |
|
| 65 |
$ module use example/new-features-without-breaking-old-module/modulefiles |
| 66 |
|
| 67 |
By using the conditional test code in the modulepath rc file (see |
| 68 |
`Implementation`_ section above), the two new modulefile commands are not |
| 69 |
used. So older versions of Modules still in use do not benefit from the |
| 70 |
dynamic hiding and forbidding features however no error are obtained on |
| 71 |
these setups:: |
| 72 |
|
| 73 |
$ module -V | grep ^VERSION= |
| 74 |
VERSION=3.2.13 |
| 75 |
$ module avail -t foo |
| 76 |
/path/to/example/new-features-without-breaking-old-module/modulefiles: |
| 77 |
foo/1.1 |
| 78 |
foo/1.2 |
| 79 |
|
| 80 |
Yet the dynamic hiding and forbidding features are enabled for setup using |
| 81 |
Modules 4.6 or newer version:: |
| 82 |
|
| 83 |
$ module -V |
| 84 |
Modules Release 4.6.0 (2020-09-16) |
| 85 |
$ module avail -t foo |
| 86 |
/path/to/example/new-features-without-breaking-old-module/modulefiles: |
| 87 |
foo/1.2 |
| 88 |
|
| 89 |
Now take a look at *bar* module which provides a version for each Unix group |
| 90 |
the current user is member of. User group membership can be retrieved with the |
| 91 |
``usergroups`` sub-command of :mfcmd:`module-info` starting Modules version |
| 92 |
4.6. With older version of Modules, the external command ``groups`` has to be |
| 93 |
used to get this information. By using the :mfvar:`ModuleTool` and |
| 94 |
:mfvar:`ModuleToolVersion` Tcl variables it will be possible to determine |
| 95 |
if ``usergroups`` sub-command is available on ``module-info``. |
| 96 |
|
| 97 |
.. literalinclude:: ../../example/new-features-without-breaking-old-module/modulefiles/bar/.modulerc |
| 98 |
:language: tcl |
| 99 |
:caption: bar/.modulerc |
| 100 |
|
| 101 |
Querying available *bar* module versions should match the list of groups of |
| 102 |
current user:: |
| 103 |
|
| 104 |
$ groups |
| 105 |
grp1 grp2 |
| 106 |
$ module avail -t bar |
| 107 |
/path/to/example/new-features-without-breaking-old-module/modulefiles: |
| 108 |
bar/grp1 |
| 109 |
bar/grp2 |
| 110 |
|
| 111 |
.. note:: |
| 112 |
|
| 113 |
As the new Tcl variables are introduced in Modules 4.7, the use of the new |
| 114 |
``usergroups`` sub-command will only be triggered starting Modules 4.7. |
| 115 |
|
| 116 |
.. vim:set tabstop=2 shiftwidth=2 expandtab autoindent: |