[fix] parse cube version number without space in them
authorLaurent Peuch <cortex@worlddomination.be>
Tue, 28 May 2019 12:35:34 +0200
changeset 12629 6b314fc558ed
parent 12628 7b89cad574f8
child 12636 06faf72cf308
[fix] parse cube version number without space in them
cubicweb/migration.py
cubicweb/test/unittest_migration.py
--- a/cubicweb/migration.py	Fri May 24 17:09:10 2019 +0200
+++ b/cubicweb/migration.py	Tue May 28 12:35:34 2019 +0200
@@ -19,8 +19,10 @@
 
 import sys
 import os
+import string
 import logging
 import tempfile
+import itertools
 from os.path import exists, join, basename, splitext
 from itertools import chain
 
@@ -466,6 +468,14 @@
 def max_version(a, b):
     return str(max(Version(a), Version(b)))
 
+
+def split_constraint(constraint):
+    oper = itertools.takewhile(lambda x: x in "<>=", constraint)
+    version = itertools.dropwhile(lambda x: x not in string.digits + ".", constraint)
+
+    return "".join(oper), "".join(version)
+
+
 class ConfigurationProblem(object):
     """Each cube has its own list of dependencies on other cubes/versions.
 
@@ -499,7 +509,7 @@
                 self.reverse_dependencies.setdefault(name,set())
                 if constraint:
                     try:
-                        oper, version = constraint.split()
+                        oper, version = split_constraint(constraint)
                         self.reverse_dependencies[name].add( (oper, version, cube) )
                     except Exception:
                         self.warnings.append(
--- a/cubicweb/test/unittest_migration.py	Fri May 24 17:09:10 2019 +0200
+++ b/cubicweb/test/unittest_migration.py	Tue May 28 12:35:34 2019 +0200
@@ -22,7 +22,11 @@
 
 from cubicweb import devtools
 from cubicweb.cwconfig import CubicWebConfiguration
-from cubicweb.migration import filter_scripts, version_strictly_lower
+from cubicweb.migration import (
+    filter_scripts,
+    split_constraint,
+    version_strictly_lower,
+)
 
 
 class Schema(dict):
@@ -113,5 +117,16 @@
                              [['activated']])
         repo.shutdown()
 
+def test_split_constraint():
+    assert split_constraint(">=0.1.0") == (">=", "0.1.0")
+    assert split_constraint(">= 0.1.0") == (">=", "0.1.0")
+    assert split_constraint(">0.1.1") == (">", "0.1.1")
+    assert split_constraint("> 0.1.1") == (">", "0.1.1")
+    assert split_constraint("<0.2.0") == ("<", "0.2.0")
+    assert split_constraint("< 0.2.0") == ("<", "0.2.0")
+    assert split_constraint("<=42.1.0") == ("<=", "42.1.0")
+    assert split_constraint("<= 42.1.0") == ("<=", "42.1.0")
+
+
 if __name__ == '__main__':
     unittest_main()