| 1 |
.. _top-priority-values: |
| 2 |
|
| 3 |
Top priority environment variable values |
| 4 |
======================================== |
| 5 |
|
| 6 |
Multiple modulefiles may alter the same environment variable. It may be |
| 7 |
wanted that among those modulefiles one should have the priority over the |
| 8 |
others and the value it sets should persist even if another modulefile |
| 9 |
loaded after attempts to alter the variable. |
| 10 |
|
| 11 |
When using the :mfcmd:`setenv` modulefile command, a *top priority value* |
| 12 |
should persist over later setenv tries. On :mfcmd:`append-path` modulefile |
| 13 |
command, this top priority value should stay last position and for |
| 14 |
:mfcmd:`prepend-path` modulefile command, value should stay first position. |
| 15 |
|
| 16 |
Implementation |
| 17 |
-------------- |
| 18 |
|
| 19 |
*Top priority values* are implemented by the use of a site-specific |
| 20 |
configuration that supersedes the definition of the ``setenv``, |
| 21 |
``append-path`` and ``prepend-path`` commands to introduce a ``--top`` |
| 22 |
argument. This argument enables a value set with this flag on to hold top |
| 23 |
priority and thus cannot be altered unless by another top priority value. |
| 24 |
|
| 25 |
For ``append-path`` command, ``--top`` ensure value will stay at last position |
| 26 |
in path-like variable. Same goes for ``prepend-path`` where ``--top`` ensure |
| 27 |
first position in path-like variable. |
| 28 |
|
| 29 |
.. literalinclude:: ../../example/top-priority-values/siteconfig.tcl |
| 30 |
:caption: siteconfig.tcl |
| 31 |
:lines: 17-115 |
| 32 |
|
| 33 |
**Compatible with Modules v4.2+** |
| 34 |
|
| 35 |
Installation |
| 36 |
------------ |
| 37 |
|
| 38 |
Create site-specific configuration directory if it does not exist yet: |
| 39 |
|
| 40 |
.. parsed-literal:: |
| 41 |
|
| 42 |
$ mkdir \ |etcdir| |
| 43 |
|
| 44 |
Then copy there the site-specific configuration script of this recipe: |
| 45 |
|
| 46 |
.. parsed-literal:: |
| 47 |
|
| 48 |
$ cp example/top-priority-values/siteconfig.tcl \ |etcdir|\ / |
| 49 |
|
| 50 |
.. note:: |
| 51 |
|
| 52 |
Defined location for the site-specific configuration script may vary from |
| 53 |
one installation to another. To determine the expected location for this |
| 54 |
file on your setup, check the value of the ``siteconfig`` option on Modules |
| 55 |
version 4.3 or above:: |
| 56 |
|
| 57 |
$ module config siteconfig |
| 58 |
|
| 59 |
On older version of Modules, check the ``modulecmd.tcl`` script:: |
| 60 |
|
| 61 |
$ grep '^set g_siteconfig ' $MODULES_CMD |
| 62 |
|
| 63 |
Usage example |
| 64 |
------------- |
| 65 |
|
| 66 |
With a ``bar/1`` modulefile that sets environment variables in a regular way: |
| 67 |
|
| 68 |
.. literalinclude:: ../../example/top-priority-values/modulefiles/bar/1 |
| 69 |
:caption: bar/1 |
| 70 |
|
| 71 |
And a ``foo/1`` modulefile that sets the same variables than ``bar/1`` but |
| 72 |
with the ``--top`` priority flag: |
| 73 |
|
| 74 |
.. literalinclude:: ../../example/top-priority-values/modulefiles/foo/1 |
| 75 |
:caption: foo/1 |
| 76 |
|
| 77 |
Enable the modulepath where the example modulefiles are located:: |
| 78 |
|
| 79 |
$ module use example/top-priority-values/modulefiles |
| 80 |
|
| 81 |
Load ``foo/1`` then ``bar/1`` modulefiles and check value of the environment |
| 82 |
variable set:: |
| 83 |
|
| 84 |
$ module load foo/1 bar/1 |
| 85 |
$ echo $TESTVAR |
| 86 |
topvalue |
| 87 |
$ echo $TESTPATH |
| 88 |
topprevalue:prevalue:postvalue:toppostvalue |
| 89 |
|
| 90 |
.. vim:set tabstop=2 shiftwidth=2 expandtab autoindent: |