diff --git a/pylib/anki/utils.py b/pylib/anki/utils.py index 817d7ade8..1604acbf9 100644 --- a/pylib/anki/utils.py +++ b/pylib/anki/utils.py @@ -323,6 +323,19 @@ def int_version() -> int: return year_num * 10_000 + month_num * 100 + patch_num +def int_version_to_str(ver: int) -> str: + if ver <= 99: + return f"2.1.{ver}" + else: + year = ver // 10_000 + month = (ver // 100) % 100 + patch = ver % 100 + out = f"{year:02}.{month:02}" + if patch: + out += f".{patch}" + return out + + # these two legacy aliases are provided without deprecation warnings, as add-ons that want to support # old versions could not use the new name without catching cases where it doesn't exist point_version = int_version diff --git a/pylib/tests/test_utils.py b/pylib/tests/test_utils.py new file mode 100644 index 000000000..93517be35 --- /dev/null +++ b/pylib/tests/test_utils.py @@ -0,0 +1,10 @@ +# Copyright: Ankitects Pty Ltd and contributors +# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +from anki.utils import int_version_to_str + + +def test_int_version_to_str(): + assert int_version_to_str(23) == "2.1.23" + assert int_version_to_str(230900) == "23.09" + assert int_version_to_str(230901) == "23.09.1" diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index 40a100f0a..1a90c8c1f 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -31,6 +31,7 @@ import aqt.main from anki.collection import AddonInfo from anki.httpclient import HttpClient from anki.lang import without_unicode_isolation +from anki.utils import int_version_to_str from aqt import gui_hooks from aqt.qt import * from aqt.utils import ( @@ -825,10 +826,12 @@ class AddonsDialog(QDialog): def compatible_string(self, addon: AddonMeta) -> str: min = addon.min_version if min is not None and min > _current_version: - return f"Anki >= 2.1.{min}" + ver = int_version_to_str(min) + return f"Anki >= {ver}" else: max = abs(addon.max_version) - return f"Anki <= 2.1.{max}" + ver = int_version_to_str(max) + return f"Anki <= {ver}" def should_grey(self, addon: AddonMeta) -> bool: return not addon.enabled or not addon.compatible()