Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose integer Tutor version parts to templates #1060

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
1 change: 1 addition & 0 deletions changelog.d/20241107_164816_kyle_tutor_version_parts.md
Original file line number Diff line number Diff line change
@@ -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).
5 changes: 5 additions & 0 deletions tutor/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down
4 changes: 3 additions & 1 deletion tutor/hooks/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading