Add stable hook API for modulefile and modulerc evaluation - #668
Merged
Conversation
Describes an add-hook command with 4 initial events (before/after modulefile and modulerc evaluation) to replace the trace/proc-rename technique currently needed for site code to run around evaluation, which breaks on internal changes across upgrades. Relates to envmodules#607 Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Add an add-hook <event> <procedure> command, usable from siteconfig.tcl, to register site procedures to run around modulefile and modulerc evaluation. This replaces the trace/rename techniques described in the Hooks section of module.rst for the events it covers, without removing them: they remain available for anything add-hook does not (yet) support. Four events are introduced: before-modulefile-eval, after-modulefile-eval, before-modulerc-eval and after-modulerc-eval. Several procedures can register on the same event; they run in their registration order. A hook procedure error is caught and reported but does not abort the running module command nor prevent other registered procedures from running, since these hooks fire on nearly every module invocation. The hook registration list, add-hook command and dispatch helper live in init.tcl.in rather than interp.tcl.in: the mechanism itself is generic, not tied to modulefile/modulerc evaluation, those are just the first 4 events it supports. The two modulefile events also carry modspec, the module specification as it was passed to the internal evaluation call prior to resolution, alongside the already-resolved modname/modnamevr. Fixes envmodules#607 Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Test error handling around add-hook and the four hook events (unknown event name, hook procedure called with too few or too many arguments, Tcl code error in a hook procedure, error on one procedure not affecting others registered on the same event or the wrapped evaluation), the modulefile/modulerc argument contract, hooks running across the different module evaluation modes on both success and failure, hooks firing for global/user rc files as modulefile events rather than modulerc events, and the examples given in module.rst. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Document add-hook and its four events (before-modulefile-eval, after-modulefile-eval, before-modulerc-eval, after-modulerc-eval) in the Hooks section of module.rst, using the new mhook Sphinx object type; demote the existing trace/rename technique to an advanced, lower-level fallback for what add-hook does not cover. Frame the design doc and siteconfig.tcl example generically around the Hook API rather than around these first 4 events, add a hook-events-per-release table to changes.rst, and record the feature in NEWS.rst. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Add a v5.7 entry describing the new add-hook siteconfig command and its four events, alongside the other new-feature highlights for this release. Note that these four events are only the first ones introduced, with more expected as real site needs come up. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Add doc/source/devel/add-new-hook-event.rst, following the existing add-new-sub-command.rst/add-new-config-option.rst howtos, to guide contributors through adding a new add-hook event: declaring it, picking its touch point and argument contract, documenting it, and covering it in the testsuite. Reference it from the developer notes list in CONTRIBUTING.rst, from the Hook API entry in MIGRATING.rst, and record it in NEWS.rst. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
Add a cookbook recipe showing a before-modulefile-eval hook that copies, with rsync, the application directory of a module hosted on a network share to local disk the first time it is loaded, tracked with a marker file so later loads skip the copy. The modulepath root .modulerc tags a module 'remote' while its application directory has not been synced yet, and the 'remote' tag is added to non_exportable_tags so it does not stick once the module is actually loaded. Configuration for this tag (abbreviation, color, non_exportable_tags) is set with module config calls in the initrc configuration file, evaluated once when the module shell function initializes with autoinit -- the only context a global rc file evaluated by Modules can call module config from, since such a file is otherwise re-evaluated ahead of every other module command afterward. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add-hook <event> <procedure>siteconfig command with four initial events (before-modulefile-eval,after-modulefile-eval,before-modulerc-eval,after-modulerc-eval), replacing thetrace/procedure-rename techniques for most needs without removing themdoc/source/design/hook-api.rst), the command/events (module.rst), the new-feature highlight (MIGRATING.rst), and a contributor guide for adding further hook events (doc/source/devel/add-new-hook-event.rst)sync-remote-appdir) demonstrating a real-world use of the hook to sync an application directory from a network share on first loadFixes #607