From 511b64678376145b99c330c9863352780e3ae570 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 6 Oct 2026 10:03:35 +0200 Subject: [PATCH] setup: a four-part hotfix version cannot break the version code Versions are read as their first three numbers everywhere; the one place that was not (the version compiled into an engine binary, `engine=0.1.40.1`) now accepts an optional fourth number. A test pins that a hotfix tag keeps finding the engine zips: the checkout's v release first, the latest release second. --- setup.py | 2 +- tools/test_setup_hotfix_tag.py | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tools/test_setup_hotfix_tag.py diff --git a/setup.py b/setup.py index 9d0f995b..ee657ce7 100644 --- a/setup.py +++ b/setup.py @@ -3319,7 +3319,7 @@ def engine_version(exe: Path) -> tuple: v = str(meta.get("version") or "") if not v: # the version compiled into the binary: 0.1.13 and newer try: # carry it, so a binary without it is older - m = re.search(rb"engine=(\d+\.\d+\.\d+)\n", Path(exe).read_bytes()) + m = re.search(rb"engine=(\d+\.\d+\.\d+)(?:\.\d+)?\n", Path(exe).read_bytes()) v = m.group(1).decode() if m else "0.1.12" except OSError: v = "0" diff --git a/tools/test_setup_hotfix_tag.py b/tools/test_setup_hotfix_tag.py new file mode 100644 index 00000000..47b41bd4 --- /dev/null +++ b/tools/test_setup_hotfix_tag.py @@ -0,0 +1,47 @@ +"""A four-part hotfix version (0.1.40.1) cannot break setup: versions are read as their first three numbers, the +engine zips are looked for under the checkout's own v tag first and the latest release second, and +a binary that says `engine=0.1.40.1` is read as 0.1.40. + + python -m unittest tools.test_setup_hotfix_tag +""" +from __future__ import annotations + +import sys +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT)) +sys.path.insert(0, str(ROOT / "tools")) +import setup # noqa: E402 + + +class HotfixTag(unittest.TestCase): + def test_a_four_part_version_is_read_as_its_first_three_numbers(self): + ver = tuple(int(x) for x in "0.1.40.1".split(".")[:3] if x.isdigit()) + self.assertEqual(ver, (0, 1, 40)) + self.assertGreaterEqual(ver, setup.MIN_ENGINE) + + def test_the_engine_zips_are_found_for_a_hotfix_tag(self): + # a hotfix that keeps CMakeLists.txt at the engine's version: the v0.1.40 release still holds the zips + bases = setup.prebuilt_bases(setup.PREBUILT_URL) + self.assertEqual(bases[0], setup.PREBUILT_TAG_URL.format(version=setup.source_version())) + self.assertEqual(bases[-1], setup.PREBUILT_URL) + # and if a four-part project version ever exists, its tag is tried first, the latest release is the fallback + with mock.patch.object(setup, "source_version", return_value="0.1.40.1"): + self.assertEqual(setup.prebuilt_bases(setup.PREBUILT_URL), + ["https://github.com/Niko1221/Strata/releases/download/v0.1.40.1/", setup.PREBUILT_URL]) + + def test_an_engine_that_says_four_parts_is_read_as_three(self): + with tempfile.TemporaryDirectory() as d: + exe = Path(d) / "strata.exe" + exe.write_bytes(b"MZ\x00engine=0.1.40.1\n\x00") + self.assertEqual(setup.engine_version(exe), (0, 1, 40)) + exe.write_bytes(b"MZ\x00engine=0.1.40\n\x00") + self.assertEqual(setup.engine_version(exe), (0, 1, 40)) + + +if __name__ == "__main__": + unittest.main()