From b662e9e4a38df321c45c6f663cac7fcefc9ff0e0 Mon Sep 17 00:00:00 2001 From: Danyal Faheem <138459282+Danyal-Faheem@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:30:57 +0500 Subject: [PATCH 1/2] fix: attach container stdin on tutor dev start (#1152) This fixes breakpoint bugging as it is currently described in the docs. --- ...5_211837_danyal.faheem_add_dev_attach_command.md | 1 + docs/tutorials/edx-platform.rst | 2 ++ tutor/commands/compose.py | 13 ++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelog.d/20241205_211837_danyal.faheem_add_dev_attach_command.md diff --git a/changelog.d/20241205_211837_danyal.faheem_add_dev_attach_command.md b/changelog.d/20241205_211837_danyal.faheem_add_dev_attach_command.md new file mode 100644 index 0000000000..73f6b9f0cc --- /dev/null +++ b/changelog.d/20241205_211837_danyal.faheem_add_dev_attach_command.md @@ -0,0 +1 @@ +- [Bugfix] Fix breakpoint debugging by attaching container stdin when running tutor dev start for a single service. (by @Danyal-Faheem) \ No newline at end of file diff --git a/docs/tutorials/edx-platform.rst b/docs/tutorials/edx-platform.rst index cd66d0893e..a5cd084816 100644 --- a/docs/tutorials/edx-platform.rst +++ b/docs/tutorials/edx-platform.rst @@ -139,6 +139,8 @@ To debug a local edx-platform repository, first, start development in detached m # Or, debugging CMS: tutor dev start cms +To detach from the service without shutting it down, use ``Ctrl+p`` followed with ``Ctrl+q``. + Running edx-platform unit tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tutor/commands/compose.py b/tutor/commands/compose.py index 6c156ff210..c275630c23 100644 --- a/tutor/commands/compose.py +++ b/tutor/commands/compose.py @@ -245,15 +245,26 @@ def start( services: list[str], ) -> None: command = ["up", "--remove-orphans"] + attach = len(services) == 1 and not detach if build: command.append("--build") - if detach: + # We have to run the container in detached mode first to attach to it + if detach or attach: command.append("-d") + else: + fmt.echo_info("ℹ️ To exit logs without stopping the containers, use ctrl+z") # Start services config = tutor_config.load(context.root) context.job_runner(config).docker_compose(*command, *services) + if attach: + fmt.echo_info( + f"""Attaching to service {services[0]} +ℹ️ To detach without stopping the service, use ctrl+p followed by ctrl+q""" + ) + context.job_runner(config).docker_compose("attach", *services) + @click.command(help="Stop a running platform") @click.argument("services", metavar="service", nargs=-1) From d547f5ba41135bf660a8411160a53075a642d4d3 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Mon, 9 Dec 2024 23:42:41 -0500 Subject: [PATCH 2/2] feat: expose integer Tutor version parts to templates (#1060) We expose the TUTOR_MAJOR_VERSION and TUTOR_MINOR_VERSION template variables, parsed from TUTOR_VERSION. This is convenient for maintainers of plugins which target multiple Tutor/Open edX versions. We do not expose TUTOR_VERSION_PATCH because (1) plugins shouldn't really need to look at the PATCH version and (2) we don't want to prevent Tutor from ever using non-integer patch suffixes (like alpha, beta, rc, etc.) if there were ever a need for that. --- changelog.d/20241107_164816_kyle_tutor_version_parts.md | 1 + tutor/env.py | 5 +++++ tutor/hooks/catalog.py | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog.d/20241107_164816_kyle_tutor_version_parts.md diff --git a/changelog.d/20241107_164816_kyle_tutor_version_parts.md b/changelog.d/20241107_164816_kyle_tutor_version_parts.md new file mode 100644 index 0000000000..acd6e9d827 --- /dev/null +++ b/changelog.d/20241107_164816_kyle_tutor_version_parts.md @@ -0,0 +1 @@ +- [Feature] Add integer variables `TUTOR_VERSION_MAJOR` and `TUTOR_VERSION_MINOR` to the template context. These are parsed from the existing `TUTOR_VERSION` string variable, which takes the format `"MAJOR.MINOR.PATCH"`. We add them as a convenience to developers who need to maintain version-agnostic Tutor plugins (by @michaelwheeler and @kdmccormick). diff --git a/tutor/env.py b/tutor/env.py index 1b61d7a926..2e71387abd 100644 --- a/tutor/env.py +++ b/tutor/env.py @@ -64,6 +64,11 @@ def _prepare_environment() -> None: ("HOST_USER_ID", utils.get_user_id()), ("TUTOR_APP", __app__.replace("-", "_")), ("TUTOR_VERSION", __version__), + # We assume that TUTOR_VERSION is always MAJOR.MINOR.PATCH. + # We assume that MAJOR and MINOR are both integers. + # We make no assumptions about PATCH, and thus do not parse it for plugins to use. + ("TUTOR_VERSION_MAJOR", int(__version__.split(".")[0])), + ("TUTOR_VERSION_MINOR", int(__version__.split(".")[1])), ("TUTOR_BRANCH_IS_MAIN", __version_suffix__ == "main"), ("is_docker_rootless", utils.is_docker_rootless), ], diff --git a/tutor/hooks/catalog.py b/tutor/hooks/catalog.py index acbb81e59f..d31163cb4c 100644 --- a/tutor/hooks/catalog.py +++ b/tutor/hooks/catalog.py @@ -351,7 +351,9 @@ def your_filter_callback(some_data): #: #: - ``HOST_USER_ID``: the numerical ID of the user on the host. #: - ``TUTOR_APP``: the app name ("tutor" by default), used to determine the dev/local project names. - #: - ``TUTOR_VERSION``: the current version of Tutor. + #: - ``TUTOR_VERSION``: the current version of Tutor, as a string in the form MAJOR.MINOR.PATCH. + #: - ``TUTOR_VERSION_MAJOR``: the MAJOR part of TUTOR_VESRION, as an integer. + #: - ``TUTOR_VERSION_MINOR``: the MINOR part of TUTOR_VERSION, as an integer. #: - ``iter_values_named``: a function to iterate on variables that start or end with a given string. #: - ``iter_mounts``: a function that yields compose-compatible bind-mounts for any given service. #: - ``iter_mounted_directories``: iterate on bind-mounted directory names.