Skip to content

Commit e72ddf1

Browse files
authored
feat: Add ENV_SAVED Action (#1302)
Adds an ENV_SAVED Action hook that allows hooking into the save mechanism and running custom code after saving an environemnt.
1 parent 12a5a61 commit e72ddf1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Feature] Add ENV_SAVED Action that allows hooks to run after a save
2+
operation. (by @xitij2000)

tutor/env.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ def save(root: str, config: Config) -> None:
342342
save_all_from(src, os.path.join(root_env, dst), config)
343343

344344
upgrade_obsolete(root)
345+
346+
config_copy = deepcopy(config)
347+
hooks.Actions.ENV_SAVED.do(root_env, config_copy)
348+
if config_copy != config:
349+
fmt.echo_alert(
350+
"A plugin just modified the config during the ENV_SAVED hook. "
351+
"This could have unintended consequences."
352+
)
353+
345354
fmt.echo_info(f"Environment generated in {base_dir(root)}")
346355

347356

tutor/hooks/catalog.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ def run_this_on_start(root, config, name):
9494
#: :parameter kwargs: job named arguments.
9595
DO_JOB: Action[[str, Any]] = Action()
9696

97+
#: This action is called at the end of the tutor.env.save function after all
98+
#: the changes to the environment have been applied, all obsolete config has
99+
#: been upgraded.
100+
#: Modifying the config object will not trigger changes in the configuration.
101+
#: For all purposes, it should be considered read-only.
102+
#:
103+
#: :parameter str root: project root.
104+
#: :parameter dict config: project configuration.
105+
ENV_SAVED: Action[[str, Config]] = Action()
106+
97107
#: Triggered when a single plugin needs to be loaded. Only plugins that have previously been
98108
#: discovered can be loaded (see :py:data:`CORE_READY`).
99109
#:

0 commit comments

Comments
 (0)