Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/20251111_011520_kshitij_env_saved_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Feature] Add ENV_SAVED Action that allows hooks to run after a save operation.

9 changes: 9 additions & 0 deletions tutor/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ def save(root: str, config: Config) -> None:
save_all_from(src, os.path.join(root_env, dst), config)

upgrade_obsolete(root)

config_copy = deepcopy(config)
hooks.Actions.ENV_SAVED.do(root_env, config_copy)
if config_copy != config:
fmt.echo_alert(
"A plugin just modified the config during the ENV_SAVED hook. "
"This could have unintended consequences."
)

fmt.echo_info(f"Environment generated in {base_dir(root)}")


Expand Down
10 changes: 10 additions & 0 deletions tutor/hooks/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def run_this_on_start(root, config, name):
#: :parameter kwargs: job named arguments.
DO_JOB: Action[[str, Any]] = Action()

#: This action is called at the end of the tutor.env.save function after all
#: the changes to the environment have been applied, all obsolete config has
#: been upgraded.
#: Modifying the config object will not trigger changes in the configuration.
#: For all purposes, it should be considered read-only.
#:
#: :parameter str root: project root.
#: :parameter dict config: project configuration.
ENV_SAVED: Action[[str, Config]] = Action()

#: Triggered when a single plugin needs to be loaded. Only plugins that have previously been
#: discovered can be loaded (see :py:data:`CORE_READY`).
#:
Expand Down