[extensions-web/wip/gnome-40] extensions: add support for new GNOME version scheme
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web/wip/gnome-40] extensions: add support for new GNOME version scheme
- Date: Sat, 19 Dec 2020 17:52:11 +0000 (UTC)
commit e2ef6470ea7c795d515bf22786cd32cda460f5bd
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Sat Dec 19 21:06:01 2020 +0400
extensions: add support for new GNOME version scheme
See-Also: https://discourse.gnome.org/t/new-gnome-versioning-scheme/4235
.../migrations/0007_auto_20201219_2046.py | 18 ++++++++++
sweettooth/extensions/models.py | 31 +++++++++++-----
sweettooth/extensions/tests.py | 41 +++++++++++++++++++++-
3 files changed, 81 insertions(+), 9 deletions(-)
---
diff --git a/sweettooth/extensions/migrations/0007_auto_20201219_2046.py
b/sweettooth/extensions/migrations/0007_auto_20201219_2046.py
new file mode 100644
index 00000000..23e9bd70
--- /dev/null
+++ b/sweettooth/extensions/migrations/0007_auto_20201219_2046.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.13 on 2020-12-19 20:46
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('extensions', '0006_auto_20191123_2146'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='shellversion',
+ name='minor',
+ field=models.IntegerField(),
+ ),
+ ]
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 432350b9..a125b0ec 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -196,27 +196,41 @@ class InvalidShellVersion(Exception):
def parse_version_string(version_string):
+ prerelease_versions = {
+ 'alpha': -3,
+ 'beta': -2,
+ 'rc': -1,
+ }
version = version_string.split('.')
+ version_parts = len(version)
+
+ if version_parts < 2 or version_parts > 4:
+ raise InvalidShellVersion()
try:
major, minor = version[:2]
- major, minor = int(major), int(minor)
+ major = int(major)
+ # GNOME 40+
+ # https://discourse.gnome.org/t/new-gnome-versioning-scheme/4235
+ if major >= 40 and minor in prerelease_versions.keys():
+ minor = prerelease_versions.get(minor)
+ else:
+ minor = int(minor)
except ValueError:
raise InvalidShellVersion()
- if len(version) in (3, 4):
+ if version_parts in (3, 4):
# 3.0.1, 3.1.4
try:
point = int(version[2])
except ValueError:
raise InvalidShellVersion()
- elif len(version) == 2 and minor % 2 == 0:
- # 3.0, 3.2
- point = -1
else:
- # Two-digit odd versions are illegal: 3.1, 3.3
- raise InvalidShellVersion()
+ point = -1
+ if major < 40 and minor % 2 != 0:
+ # Two-digit pre-40 odd versions are illegal: 3.1, 3.3
+ raise InvalidShellVersion()
return major, minor, point
@@ -239,7 +253,8 @@ class ShellVersionManager(models.Manager):
class ShellVersion(models.Model):
major = models.PositiveIntegerField()
- minor = models.PositiveIntegerField()
+ # -3: alpha, -2: beta, -1: rc
+ minor = models.IntegerField()
# -1 is a flag for the stable release matching
point = models.IntegerField()
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index c239cd60..4f2abc4c 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -348,6 +348,34 @@ class ShellVersionTest(TestCase):
self.assertEqual(version.minor, 2)
self.assertEqual(version.point, -1)
+ self.assertEqual(lookup_version("40.alpha"), None)
+ version = get_version("40.alpha")
+ self.assertEqual(lookup_version("40.alpha"), version)
+ self.assertEqual(version.major, 40)
+ self.assertEqual(version.minor, -3)
+ self.assertEqual(version.point, -1)
+
+ self.assertEqual(lookup_version("51.6"), None)
+ version = get_version("51.6")
+ self.assertEqual(lookup_version("51.6"), version)
+ self.assertEqual(version.major, 51)
+ self.assertEqual(version.minor, 6)
+ self.assertEqual(version.point, -1)
+
+ self.assertEqual(lookup_version("123.rc"), None)
+ version = get_version("123.rc")
+ self.assertEqual(lookup_version("123.rc"), version)
+ self.assertEqual(version.major, 123)
+ self.assertEqual(version.minor, -1)
+ self.assertEqual(version.point, -1)
+
+ self.assertEqual(lookup_version("41.3"), None)
+ version = get_version("41.3")
+ self.assertEqual(lookup_version("41.3"), version)
+ self.assertEqual(version.major, 41)
+ self.assertEqual(version.minor, 3)
+ self.assertEqual(version.point, -1)
+
version1 = get_version("3.2.2")
self.assertEqual(lookup_version("3.2.2.1"), version1)
@@ -357,6 +385,9 @@ class ShellVersionTest(TestCase):
with self.assertRaises(models.InvalidShellVersion):
lookup_version("3.1")
+ with self.assertRaises(models.InvalidShellVersion):
+ lookup_version("3.beta")
+
def test_bad_shell_versions(self):
with self.assertRaises(models.InvalidShellVersion):
models.parse_version_string("3")
@@ -370,6 +401,9 @@ class ShellVersionTest(TestCase):
with self.assertRaises(models.InvalidShellVersion):
models.parse_version_string("3.2.a")
+ with self.assertRaises(models.InvalidShellVersion):
+ models.parse_version_string("40.teta")
+
class DownloadExtensionTest(BasicUserTestCase, TestCase):
def download(self, uuid, shell_version):
url = reverse('extensions-shell-download', kwargs=dict(uuid=uuid))
@@ -695,6 +729,9 @@ class QueryExtensionsTest(BasicUserTestCase, TestCase):
v = models.ExtensionVersion.objects.create(extension=extension, status=models.STATUS_ACTIVE)
v.parse_metadata_json({"shell-version": ["3.20.0"]})
+ v = models.ExtensionVersion.objects.create(extension=extension, status=models.STATUS_ACTIVE)
+ v.parse_metadata_json({"shell-version": ["3.38.0", "40.alpha", "42.3"]})
+
self.assertEqual(views.grab_proper_extension_version(extension, "3.17.1").version, 3)
self.assertEqual(views.grab_proper_extension_version(extension, "3.20.0").version, 4)
self.assertEqual(views.grab_proper_extension_version(extension, "3.2.0"), None)
@@ -715,4 +752,6 @@ class QueryExtensionsTest(BasicUserTestCase, TestCase):
self.assertEqual(views.grab_proper_extension_version(extension, "3.18.3", True).version, 3)
self.assertEqual(views.grab_proper_extension_version(extension, "3.20.0", True).version, 4)
self.assertEqual(views.grab_proper_extension_version(extension, "3.24.0", True).version, 4)
- self.assertEqual(views.grab_proper_extension_version(extension, "4.14.0", True).version, 4)
+ self.assertEqual(views.grab_proper_extension_version(extension, "40.beta", True).version, 5)
+ self.assertEqual(views.grab_proper_extension_version(extension, "44.2", True).version, 5)
+ self.assertEqual(views.grab_proper_extension_version(extension, "129.rc", True).version, 5)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]