From afb85aaab6b14344a2fdde548eb744ddc667b4fb Mon Sep 17 00:00:00 2001 From: Alejandro Cardenas Date: Fri, 15 Dec 2023 04:31:35 -0500 Subject: [PATCH] feat: add CONFIG INTERACTIVE action New hook Action that allows tutor plugins to interact with the configuration at the time of the interactive questionnaire that happens during `tutor local/dev launch`. --- .../20231214_141533_alecar.main_survey_report_plugin.md | 1 + tutor/hooks/catalog.py | 6 ++++++ tutor/interactive.py | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 changelog.d/20231214_141533_alecar.main_survey_report_plugin.md diff --git a/changelog.d/20231214_141533_alecar.main_survey_report_plugin.md b/changelog.d/20231214_141533_alecar.main_survey_report_plugin.md new file mode 100644 index 0000000..4b7472f --- /dev/null +++ b/changelog.d/20231214_141533_alecar.main_survey_report_plugin.md @@ -0,0 +1 @@ +- [Feature] add `CONFIG_INTERACTIVE` action that allows tutor plugins to interact with the configuration at the time of the interactive questionnaire that happens during tutor local launch. (by @Alec4r). diff --git a/tutor/hooks/catalog.py b/tutor/hooks/catalog.py index 56deed4..463e4d6 100644 --- a/tutor/hooks/catalog.py +++ b/tutor/hooks/catalog.py @@ -57,6 +57,12 @@ class Actions: #: :parameter str name: docker-compose project name. COMPOSE_PROJECT_STARTED: Action[[str, Config, str]] = Action() + #: Triggered after all interactive questions have been asked. + #: You should use this action if you want to add new questions. + #: + #: :parameter dict config: project configuration. + CONFIG_INTERACTIVE: Action[[Config]] = Action() + #: This action is called at the end of the tutor.config.load_full function. #: Modifying this object will not trigger changes in the configuration. #: For all purposes, it should be considered read-only. diff --git a/tutor/interactive.py b/tutor/interactive.py index 820268a..d85f991 100644 --- a/tutor/interactive.py +++ b/tutor/interactive.py @@ -3,7 +3,7 @@ from typing import List, Optional import click from . import config as tutor_config -from . import env, exceptions, fmt +from . import env, exceptions, fmt, hooks from .types import Config, get_typed @@ -149,6 +149,8 @@ def ask_questions(config: Config, run_for_prod: Optional[bool] = None) -> None: defaults, ) + hooks.Actions.CONFIG_INTERACTIVE.do(config) + def ask(question: str, key: str, config: Config, defaults: Config) -> None: default = get_typed(defaults, key, str)