From 6c2faaebcf7a047ac9df90053e2960abae5cf073 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Mon, 6 May 2024 10:19:03 -0400 Subject: [PATCH] feat: expose integer Tutor version parts to templates --- changelog.d/20241107_164816_kyle_tutor_version_parts.md | 1 + tutor/env.py | 3 +++ 2 files changed, 4 insertions(+) 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..10d6f22ca9 --- /dev/null +++ b/changelog.d/20241107_164816_kyle_tutor_version_parts.md @@ -0,0 +1 @@ +- [Feature] Add integer variables `TUTOR_VERSION_MAJOR`, `TUTOR_VERSION_MINOR`, and `TUTOR_VERSION_PATCH` 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). diff --git a/tutor/env.py b/tutor/env.py index fef5f2cbed..75d1eac904 100644 --- a/tutor/env.py +++ b/tutor/env.py @@ -64,6 +64,9 @@ def _prepare_environment() -> None: ("HOST_USER_ID", utils.get_user_id()), ("TUTOR_APP", __app__.replace("-", "_")), ("TUTOR_VERSION", __version__), + ("TUTOR_VERSION_MAJOR", int(__version__.split('.')[0])), + ("TUTOR_VERSION_MINOR", int(__version__.split('.')[1])), + ("TUTOR_VERSION_PATCH", int(__version__.split('.')[2])), ("is_docker_rootless", utils.is_docker_rootless), ], )