@@ -108,6 +108,106 @@ another modulefile
108108 Currently Loaded Modulefiles:
109109 1) foo/1.0
110110
111+ Module variants
112+ ---------------
113+
114+ :ref: `Module variants ` is a new mechanism that allows to pass arguments to
115+ evaluated modulefiles in order to achieve different environment variable or
116+ module requirement setup with a single modulefile.
117+
118+ Variant specification relies on the :ref: `Advanced module version specifiers `
119+ mechanism, which leverages the `variant syntax `_ of the `Spack `_ package
120+ manager:
121+
122+ .. _variant syntax : https://spack.readthedocs.io/en/latest/basic_usage.html#variants
123+
124+ .. parsed-literal ::
125+
126+ :ps: `$ ` module config advanced_version_spec 1
127+ :ps: `$ ` module load -v bar/1.2 toolchain=a -debug
128+ Loading :sgrhi: `bar/1.2 `:sgrse:`{ `:sgrva:`-debug `:sgrse:`: `:sgrva:`toolchain=a `:sgrse:`} `
129+
130+ Variants are defined in modulefile with the :mfcmd: `variant ` command, which
131+ defines the variant type and its accepted values:
132+
133+ .. code-block :: tcl
134+
135+ #%Module4.8
136+ variant toolchain a b c
137+ variant --boolean --default off debug
138+
139+ # select software build depending on variant values
140+ set suffix -[getvariant toolchain]
141+ if {$ModuleVariant(debug)} {
142+ append suffix -dbg
143+ }
144+
145+ prepend-path PATH /path/to/bar-1.2$suffix/bin
146+ prepend-path LD_LIBRARY_PATH /path/to/bar-1.2$suffix/lib
147+
148+ The *bar/1.2 * modulefile defines a ``toolchain `` variant, which accepts the
149+ ``a ``, ``b `` and ``c `` values, and a ``debug `` Boolean variant, which is set
150+ ``off `` by default. Once these two variants are declared, their value
151+ specified on module designation are instantiated in the :mfvar: `ModuleVariant `
152+ array variable which could also be queried with the :mfcmd: `getvariant `
153+ modulefile command. Selected variant values enable to define a specific
154+ installation build path for the *bar/1.2 * software.
155+
156+ If a variant is not specified when designating module and if this variant is
157+ not declared with a default value, an error is obtained:
158+
159+ .. parsed-literal ::
160+
161+ :ps: `$ ` module purge
162+ :ps: `$ ` module load :noparse: `[email protected] ` 163+ Loading :sgrhi: `bar/1.2 `
164+ :sgrer: `ERROR `: No value specified for variant 'toolchain'
165+ Allowed values are: a b c
166+
167+ Once module is loaded, selected variants are reported on the :subcmd: `list `
168+ sub-command output:
169+
170+ .. parsed-literal ::
171+
172+ :ps: `$ ` module load :noparse: `[email protected] ` toolchain=b 173+ :ps: `$ ` module list
174+ Currently Loaded Modulefiles:
175+ 1) bar/1.2\ :sgrse: `{ `:sgrva:`-debug `:sgrse:`: `:sgrva:`toolchain=b `:sgrse:`} `
176+
177+ Key:
178+ :sgrse: `{ `:sgrva:`-variant `:sgrse:`} `\=\ :sgrse: `{ `:sgrva:`variant=off `:sgrse:`} ` :sgrse: `{ `:sgrva:`variant=value `:sgrse:`} `
179+
180+ .. note :: The default value of the :instopt:`--with-list-output` installation
181+ option has been updated to include variant information.
182+
183+ Variant specification could be used where the :ref: `Advanced module version
184+ specifiers` is supported. For instance a module may express a dependency over
185+ a specific module variant:
186+
187+ .. parsed-literal ::
188+
189+ :ps: `$ ` module show foo/2.1 toolchain=c
190+ -------------------------------------------------------------------
191+ :sgrhi: `/path/to/modulfiles/foo/2.1 `:
192+
193+ :sgrcm: `variant ` toolchain a b c
194+ :sgrcm: `prereq ` :noparse: `[email protected] toolchain= `:sgrva:`{toolchain} ` 195+ :sgrcm: `prepend-path ` PATH /path/to/foo-2.1-:sgrva: `{toolchain} `/bin
196+ :sgrcm: `prepend-path ` LD_LIBRARY_PATH /path/to/foo-2.1-:sgrva: `{toolchain} `/lib
197+ -------------------------------------------------------------------
198+
199+ In this example, *foo/2.1 * module depends on *bar/1.2 * and the same toolchain
200+ variant should be selected for both modules in order to load two software
201+ builds that are compatible between each other.
202+
203+ .. parsed-literal ::
204+
205+ :ps: `$ ` module purge
206+ :ps: `$ ` module config auto_handling 1
207+ :ps: `$ ` module load foo/2.1 toolchain=a
208+ Loading :sgrhi: `foo/2.1 `:sgrse:`{ `:sgrva:`toolchain=a `:sgrse:`} `
209+ :sgrin: `Loading requirement `: bar/1.2\ :sgrse: `{ `:sgrva:`-debug `:sgrse:`: `:sgrva:`toolchain=a `:sgrse:`} `
210+
111211
112212 From v4.6 to v4.7
113213=================
0 commit comments