@@ -129,13 +129,10 @@ Modulecmd startup
129129^^^^^^^^^^^^^^^^^
130130
131131Upon invocation :file: `modulecmd.tcl ` sources a site-specific configuration
132- script if it exists. The location for this script is
133- |file etcdir_siteconfig |. An additional siteconfig script may be
134- specified with the :envvar: `MODULES_SITECONFIG ` environment variable, if
135- allowed by :file: `modulecmd.tcl ` configuration, and will be loaded if it
136- exists after |file etcdir_siteconfig |. Siteconfig is a Tcl script that enables
137- to supersede any global variable or procedure definition of
138- :file: `modulecmd.tcl `.
132+ script if it exists. Siteconfig script is a Tcl script located at
133+ |file etcdir_siteconfig |. It enables to supersede any global variable or
134+ procedure definition of :file: `modulecmd.tcl `. See :ref: `Site-specific
135+ configuration` for detailed information.
139136
140137Afterward, :file: `modulecmd.tcl ` sources rc files which contain global,
141138user and *modulefile * specific setups. These files are interpreted as
@@ -844,7 +841,9 @@ Module Sub-Commands
844841
845842 .. mconfig :: extra_siteconfig
846843
847- Additional site-specific configuration script location.
844+ Additional site-specific configuration script location. See
845+ :ref: `Site-specific configuration ` section for details.
846+
848847
849848 This configuration option is unset by default. The
850849 :envvar: `MODULES_SITECONFIG ` environment variable is defined by
@@ -1165,7 +1164,9 @@ Module Sub-Commands
11651164
11661165 .. mconfig :: siteconfig
11671166
1168- Primary site-specific configuration script location.
1167+ Primary site-specific configuration script location. See
1168+ :ref: `Site-specific configuration ` section for details.
1169+
11691170
11701171 Default value is |file etcdir_siteconfig |. It can be changed at installation
11711172 time with :instopt: `--prefix ` or :instopt: `--etcdir ` options. The value of
@@ -2599,6 +2600,152 @@ target also applies to stash collection.
25992600 .. versionchanged :: 5.2
26002601 Stash collection introduced
26012602
2603+ .. _Site-specific configuration :
2604+
2605+ Site-specific configuration
2606+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2607+
2608+ Siteconfig, the site-specific configuration script, is a way to extend
2609+ :file: `modulecmd.tcl `. Siteconfig is a Tcl script. Its location is
2610+ |file etcdir_siteconfig |.
2611+
2612+ When :file: `modulecmd.tcl ` is invoked it sources siteconfig script if it
2613+ exists. Any global variable or procedure of :file: `modulecmd.tcl ` can be
2614+ redefined in siteconfig.
2615+
2616+ An additional siteconfig script may be specified through the
2617+ :mconfig: `extra_siteconfig ` configuration option. The
2618+ :envvar: `MODULES_SITECONFIG ` environment variable is defined by
2619+ :subcmd: `config ` sub-command when setting :mconfig: `extra_siteconfig `. If it
2620+ exists the extra siteconfig is sourced by :file: `modulecmd.tcl ` right after
2621+ main siteconfig script.
2622+
2623+ Hooks
2624+ """""
2625+
2626+ Siteconfig relies on the ability of the Tcl language to overwrite previously
2627+ defined variables and procedures. Sites may deploy their own Tcl code in
2628+ siteconfig to adapt :file: `modulecmd.tcl ` to their specific needs. The
2629+ ``trace `` Tcl command may especially be used to define hooks that are run when
2630+ entering or leaving a given procedure, or when a variable is read or written.
2631+ See :manpage: `trace(n)` man page for detailed information. The following
2632+ example setup a procedure that is executed before each modulefile evaluation:
2633+
2634+ .. code-block :: tcl
2635+
2636+ proc beforeEval {cmdstring code result op} {
2637+ # code to run right before each modulefile evaluation
2638+ }
2639+ trace add execution execute-modulefile enter beforeEval
2640+
2641+ Siteconfig hook variables
2642+ """""""""""""""""""""""""
2643+
2644+ Some Tcl variables can be defined in siteconfig script with special hook
2645+ meaning. The following variables are recognized:
2646+
2647+ .. sitevar :: modulefile_extra_vars
2648+
2649+ List of variable names and associated values to setup in modulefile
2650+ evaluation context. These variables can be accessed when modulefile is
2651+ executed. In case code in a modulefile changes the value of such variable,
2652+ its value is reset to the one defined in :sitevar: `modulefile_extra_vars `
2653+ prior the evaluation of the next modulefile.
2654+
2655+ .. code-block :: tcl
2656+
2657+ set modulefile_extra_vars {myvar 1 othervar {some text}}
2658+
2659+ In the above siteconfig example, :sitevar: `modulefile_extra_vars ` sets the
2660+ ``myvar `` and ``othervar `` variables in the modulefile evaluation context
2661+ with respectively ``1 `` and ``some text `` as value.
2662+
2663+ .. only :: html
2664+
2665+ .. versionadded :: 5.2
2666+
2667+ .. sitevar :: modulefile_extra_cmds
2668+
2669+ List of command and associated local procedure to setup in modulefile
2670+ evaluation context. These commands can be called from the modulefile to
2671+ execute associated procedure. In case a modulefile changes the definition
2672+ of such command, its definition is bound again on the procedure defined in
2673+ :sitevar: `modulefile_extra_cmds ` prior the evaluation of the next modulefile.
2674+
2675+ .. code-block :: tcl
2676+
2677+ proc mycmd {} {
2678+ # Tcl code
2679+ }
2680+ proc anotherproc {args} {
2681+ # Tcl code
2682+ }
2683+ set modulefile_extra_cmds {mycmd mycmd othercmd anotherproc}
2684+
2685+ In the above siteconfig example, :sitevar: `modulefile_extra_cmds ` sets the
2686+ ``mycmd `` and ``othercmd `` commands in the modulefile evaluation context and
2687+ bind them respectively to the ``mycmd `` and ``anotherproc `` procedures
2688+ defined in siteconfig script.
2689+
2690+ .. only :: html
2691+
2692+ .. versionadded :: 5.2
2693+
2694+ .. sitevar :: modulerc_extra_vars
2695+
2696+ List of variable names and associated values to setup in modulerc evaluation
2697+ context. These variables can be accessed when modulerc is executed. In case
2698+ code in a modulerc changes the value of such variable, its value
2699+ is reset to the one defined in :sitevar: `modulerc_extra_vars ` prior the
2700+ evaluation of the next modulerc.
2701+
2702+ .. code-block :: tcl
2703+
2704+ set modulerc_extra_vars {myvar 1 othervar {some text}}
2705+
2706+ In the above siteconfig example, :sitevar: `modulerc_extra_vars ` sets the
2707+ ``myvar `` and ``othervar `` variables in the modulerc evaluation context with
2708+ respectively ``1 `` and ``some text `` as value.
2709+
2710+ .. only :: html
2711+
2712+ .. versionadded :: 5.2
2713+
2714+ .. sitevar :: modulerc_extra_cmds
2715+
2716+ List of command and associated local procedure to setup in modulerc
2717+ evaluation context. These commands can be called from the modulerc to execute
2718+ associated procedure. In case a modulerc changes the definition of such
2719+ command, its definition is bound again on the procedure defined in
2720+ :sitevar: `modulerc_extra_cmds ` prior the evaluation of the next modulerc.
2721+
2722+ .. code-block :: tcl
2723+
2724+ proc mycmd {} {
2725+ # Tcl code
2726+ }
2727+ proc anotherproc {args} {
2728+ # Tcl code
2729+ }
2730+ set modulerc_extra_cmds {mycmd mycmd othercmd anotherproc}
2731+
2732+ In the above siteconfig example, :sitevar: `modulerc_extra_cmds ` sets the
2733+ ``mycmd `` and ``othercmd `` commands in the modulerc evaluation context and
2734+ bind them respectively to the ``mycmd `` and ``anotherproc `` procedures
2735+ defined in siteconfig script.
2736+
2737+
2738+ .. only :: html
2739+
2740+ .. versionadded :: 5.2
2741+
2742+ .. only :: html
2743+
2744+ .. versionadded :: 4.1
2745+
2746+ .. versionchanged :: 4.3
2747+ Additional site-specific configuration script introduced
2748+
26022749
26032750EXIT STATUS
26042751-----------
@@ -3730,7 +3877,8 @@ ENVIRONMENT
37303877.. envvar :: MODULES_SITECONFIG
37313878
37323879 Location of a site-specific configuration script to source into
3733- :file: `modulecmd.tcl `. See also `Modulecmd startup `_ section.
3880+ :file: `modulecmd.tcl `. See :ref: `Site-specific configuration ` section for
3881+ details.
37343882
37353883 This environment variable value supersedes the default value set in the
37363884 :mconfig: `extra_siteconfig ` configuration option. It can be defined with the
@@ -3974,7 +4122,9 @@ FILES
39744122
39754123 The site-specific configuration script of :file: `modulecmd.tcl `. An
39764124 additional configuration script could be defined using the
3977- :envvar: `MODULES_SITECONFIG ` environment variable.
4125+ :envvar: `MODULES_SITECONFIG ` environment variable. See :ref: `Site-specific
4126+ configuration` for detailed information.
4127+
39784128
39794129|file etcdir_rc |
39804130
@@ -4008,5 +4158,5 @@ FILES
40084158SEE ALSO
40094159--------
40104160
4011- :ref: `ml(1) `, :ref: `modulefile(4) `
4161+ :ref: `ml(1) `, :ref: `modulefile(4) `, :manpage: `trace(n)`
40124162
0 commit comments