tutor icon indicating copy to clipboard operation
tutor copied to clipboard

feat: expose integer Tutor version parts to templates

Open kdmccormick opened this issue 1 year ago • 6 comments

WIP

@michaelwheeler

kdmccormick avatar May 06 '24 14:05 kdmccormick

For some context, this is related to a question that I brought up during the Tutor Users' Group about writing plugins that support multiple Tutor versions. We're currently doing something along the lines of...

{% if TUTOR_VERSION.startswith("14.") %}
# Do something for Tutor v14 only...
{% else %}
# Do something for Tutor versions after 14...
{% endif %}

But having major/minor/patch versions available to the context as integers would allow more precision and flexibility.

michaelwheeler avatar May 09 '24 17:05 michaelwheeler

@michaelwheeler I'd like to understand better your use case. Have you considered having multiple branches for your plugin, one for every major release?

regisb avatar Jun 10 '24 12:06 regisb

Have you considered having multiple branches for your plugin, one for every major release?

In our team, managing multiple branches for our plugins felt like more overhead than adding an occasional conditional. We also think it will slightly simplify the process of upgrading to a newer named release.

michaelwheeler avatar Jun 13 '24 16:06 michaelwheeler

I think this would useful to have as an option for plugin authors, particularly for cases where the plugins don't change that much between releases.

arbrandes avatar Jun 13 '24 17:06 arbrandes

Right. I'm still not sure if it makes sense to add these settings to Tutor core. You do know that you could define these variables in your own plugin by adding a callback to the ENV_TEMPLATE_VARIABLES filter, right?

regisb avatar Jun 14 '24 06:06 regisb

You do know that you could define these variables in your own plugin by adding a callback to the ENV_TEMPLATE_VARIABLES filter, right?

I didn't know that!

It still feels to me like Tutor should provide the variable, since the version is a property of Tutor itself, but if that's undesirable for other reasons then maybe ENV_TEMPLATE_VARIABLES can get me where I need to go.

michaelwheeler avatar Jun 18 '24 14:06 michaelwheeler

Sorry for the delay @michaelwheeler. I think this is ready to go. Can you review it and try it out with one of your plugins?

kdmccormick avatar Nov 07 '24 22:11 kdmccormick

I think this is ready to go. Can you review it and try it out with one of your plugins?

Yep, thanks! I'll try to take a look before the end of next week.

michaelwheeler avatar Nov 08 '24 21:11 michaelwheeler

Hey @kdmccormick, I tested this out and things work as expected from my perspective. Thanks!

michaelwheeler avatar Nov 15 '24 20:11 michaelwheeler

@michaelwheeler Would you have any objection to me removing TUTOR_VERSION_PATCH from this PR? You'd still have TUTOR_VERSION_MAJOR and TUTOR_VERSION_MINOR, but the patch version would remain unavailable to plugin authors without manually parsing TUTOR_VERSION.

My thinking is that it would be nice, as maintainers, to have some flexibility with the patch version. We don't currently use alpha/beta suffixes or release candidates (19.2.3a, 19.2.rc1, etc.) but I can't say for sure that we never will, so I'd rather not encourage plugin authors to rely on it always being an integer.

kdmccormick avatar Nov 18 '24 14:11 kdmccormick

Would you have any objection to me removing TUTOR_VERSION_PATCH from this PR?

No objection @kdmccormick. In practice I suspect I would only ever be using TUTOR_VERSION_MAJOR.

michaelwheeler avatar Nov 18 '24 15:11 michaelwheeler