From 3abc0e781f69872c199f8078fd9ec165650be8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 2 Feb 2016 13:18:12 +0100 Subject: [PATCH] Relax version validation Check the format only if version starts with a digit. This allows having non-numeric versions such as Rawhide. Fixes #11 --- doc/terminology.rst | 6 ++++++ productmd/composeinfo.py | 6 +++++- tests/test_composeinfo.py | 10 +++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/terminology.rst b/doc/terminology.rst index 785693b..a98f1da 100644 --- a/doc/terminology.rst +++ b/doc/terminology.rst @@ -108,6 +108,12 @@ Recommended schema is dot separated numbers: * **X.Y.Z** -- bugfix version / hotfix version +.. note :: + It is technically possible to use arbitrary string as a version, but this + is highly discouraged as it does not allow sorting. If you need it, just + start your version with any non-digit character. + + .. _Milestones: ========== diff --git a/productmd/composeinfo.py b/productmd/composeinfo.py index bb6c757..aece4a0 100644 --- a/productmd/composeinfo.py +++ b/productmd/composeinfo.py @@ -374,8 +374,12 @@ class BaseProduct(productmd.common.MetadataBase): self._assert_type("name", list(six.string_types)) def _validate_version(self): + """If the version starts with a digit, it must be a sematic-versioning + style string. + """ self._assert_type("version", list(six.string_types)) - self._assert_matches_re("version", [r"^\d+(\.\d+)*$"]) + if re.match('^\d', self.version): + self._assert_matches_re("version", [r"^\d+(\.\d+)*$"]) def _validate_short(self): self._assert_type("short", list(six.string_types)) diff --git a/tests/test_composeinfo.py b/tests/test_composeinfo.py index e24984d..79cad82 100755 --- a/tests/test_composeinfo.py +++ b/tests/test_composeinfo.py @@ -29,7 +29,7 @@ import shutil DIR = os.path.dirname(__file__) sys.path.insert(0, os.path.join(DIR, "..")) -from productmd.composeinfo import ComposeInfo, Variant +from productmd.composeinfo import ComposeInfo, Variant, Release class TestComposeInfo(unittest.TestCase): @@ -117,6 +117,14 @@ class TestComposeInfo(unittest.TestCase): ci.compose.label = "GA" self.assertRaises(ValueError, ci.dump, self.ci_path) + def test_release_non_numeric_version(self): + r = Release(None) + r.name = "Fedora" + r.short = "f" + r.version = "Rawhide" + + r.validate() + if __name__ == "__main__": unittest.main() -- 2.5.0