From 3056954eb3e4b21088e48d8e753226c8fb72e46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Mennetrier?= Date: Thu, 28 Oct 2021 15:24:32 +0200 Subject: [PATCH] Improve check of version in manifest --- package_linter.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/package_linter.py b/package_linter.py index 0cf0012..ab902c7 100755 --- a/package_linter.py +++ b/package_linter.py @@ -332,6 +332,38 @@ class TestSuite: test_name = test.__qualname__ tests_reports[report_type(report)].append((test_name, report)) +# Defined in packaging module +# See https://github.com/pypa/packaging/blob/20cd09e00917adbc4afeaa753be831a6bc2740f7/packaging/version.py#L225 +VERSION_PATTERN = r""" + v? + (?: + (?:(?P[0-9]+)!)? # epoch + (?P[0-9]+(?:\.[0-9]+)*) # release segment + (?P
                                          # pre-release
+            [-_\.]?
+            (?P(a|b|c|rc|alpha|beta|pre|preview))
+            [-_\.]?
+            (?P[0-9]+)?
+        )?
+        (?P                                         # post release
+            (?:-(?P[0-9]+))
+            |
+            (?:
+                [-_\.]?
+                (?Ppost|rev|r)
+                [-_\.]?
+                (?P[0-9]+)?
+            )
+        )?
+        (?P                                          # dev release
+            [-_\.]?
+            (?Pdev)
+            [-_\.]?
+            (?P[0-9]+)?
+        )?
+    )
+    (?:\+(?P[a-z0-9]+(?:[-_\.][a-z0-9]+)*))?       # local version
+"""
 
 # ############################################################################
 #   Actual high-level checks
@@ -1414,8 +1446,7 @@ class Manifest(TestSuite):
 
     @test()
     def version_format(self):
-
-        if not re.match("^([0-9]|\.|-)+~ynh[0-9]+$", self.manifest.get("version", "")):
+        if not re.match(r"^" + VERSION_PATTERN + r"~ynh[0-9]+$", self.manifest.get("version", ""), re.VERBOSE):
             yield Error(
                 "The 'version' field should match the format ~ynh. "
                 "For example: 4.3-2~ynh3. It is composed of the upstream version number (in the "