From e7cb9c9af9efdb254380671f056eea8a646601c0 Mon Sep 17 00:00:00 2001 From: kuqin12 <42554914+kuqin12@users.noreply.github.com> Date: Thu, 10 Jun 2021 23:22:43 -0700 Subject: [PATCH] Added logic to support nuget versions suffix with numbers (#253) * Added logic to support nuget versions such as rc1/beta2 Co-authored-by: kuqin --- .cspell.json | 3 ++- .../environment/extdeptypes/nuget_dependency.py | 12 +++++++++++- edk2toolext/tests/test_nuget_dependency.py | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.cspell.json b/.cspell.json index 0faf67a0..3c21092c 100644 --- a/.cspell.json +++ b/.cspell.json @@ -122,6 +122,7 @@ "Boothole", "dbxupdate", "FileFlagsMask", - "markdownlint" + "markdownlint", + "xffd" ] } diff --git a/edk2toolext/environment/extdeptypes/nuget_dependency.py b/edk2toolext/environment/extdeptypes/nuget_dependency.py index 15d4bb32..f505d09a 100644 --- a/edk2toolext/environment/extdeptypes/nuget_dependency.py +++ b/edk2toolext/environment/extdeptypes/nuget_dependency.py @@ -72,7 +72,17 @@ def normalize_version(version): int_parts = tuple([0 if a == "" else int(a) for a in parts]) - if tag not in [None, "beta", "alpha", "rc"]: + if tag is not None: + # It might start with "beta*", "alpha*" or "rc*" + legit_tag = False + for rv in ["beta", "alpha", "rc"]: + if tag.startswith(rv): + legit_tag = True + else: + # Otherwise, it is legit + legit_tag = True + + if not legit_tag: raise ValueError(f"Unparsable version tag: {tag}") if len(int_parts) > 4: diff --git a/edk2toolext/tests/test_nuget_dependency.py b/edk2toolext/tests/test_nuget_dependency.py index ed42bf4f..baf5d54b 100644 --- a/edk2toolext/tests/test_nuget_dependency.py +++ b/edk2toolext/tests/test_nuget_dependency.py @@ -132,6 +132,9 @@ def test_normalize_version(self): version5 = "3.2.1.-alpha" proper_version5 = "3.2.1-alpha" self.assertEqual(proper_version5, NugetDependency.normalize_version(version5)) + version6 = "3.2.1.0-rc1" + proper_version6 = "3.2.1-rc1" + self.assertEqual(proper_version6, NugetDependency.normalize_version(version6)) # try some bad cases with self.assertRaises(ValueError): NugetDependency.normalize_version("not a number")