diff --git a/src/rez/vendor/version/util.py b/src/rez/vendor/version/util.py index ca014ecb8..21a420044 100644 --- a/src/rez/vendor/version/util.py +++ b/src/rez/vendor/version/util.py @@ -20,80 +20,6 @@ def __repr__(self): return "%s(%r)" % (self.__class__.__name__, str(self)) -def total_ordering(cls): - """ - Backport to work with Python 2.6 - Class decorator that fills in missing ordering methods - Code from: http://code.activestate.com/recipes/576685/ - """ - convert = { - '__lt__': [ - ( - '__gt__', - lambda self, other: not (self < other or self == other) - ), - ( - '__le__', - lambda self, other: self < other or self == other - ), - ( - '__ge__', - lambda self, other: not self < other - )], - '__le__': [ - ( - '__ge__', - lambda self, other: not self <= other or self == other - ), - ( - '__lt__', - lambda self, other: self <= other and not self == other - ), - ( - '__gt__', - lambda self, other: not self <= other - )], - '__gt__': [ - ( - '__lt__', - lambda self, other: not (self > other or self == other) - ), - ( - '__ge__', - lambda self, other: self > other or self == other - ), - ( - '__le__', - lambda self, other: not self > other - )], - '__ge__': [ - ( - '__le__', - lambda self, other: (not self >= other) or self == other - ), - ( - '__gt__', - lambda self, other: self >= other and not self == other - ), - ( - '__lt__', - lambda self, other: not self >= other - )] - } - roots = set(dir(cls)) & set(convert) - if not roots: - raise ValueError( - 'must define at least one ordering operation: < > <= >=' - ) - root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__ - for opname, opfunc in convert[root]: - if opname not in roots: - opfunc.__name__ = opname - opfunc.__doc__ = getattr(int, opname).__doc__ - setattr(cls, opname, opfunc) - return cls - - def dedup(iterable): """Removes duplicates from a sorted sequence.""" for e in groupby(iterable): diff --git a/src/rez/vendor/version/version.py b/src/rez/vendor/version/version.py index 87a45e092..aeb17be5d 100644 --- a/src/rez/vendor/version/version.py +++ b/src/rez/vendor/version/version.py @@ -16,8 +16,9 @@ version is used to denote unversioned objects. The empty version range, also known as the 'any' range, is used to refer to any version of an object. """ -from rez.vendor.version.util import VersionError, ParseException, _Common, \ - total_ordering, dedup +from __future__ import print_function +from .util import VersionError, ParseException, _Common, \ + dedup import rez.vendor.pyparsing.pyparsing as pp from bisect import bisect_left import copy @@ -28,13 +29,17 @@ re_token = re.compile(r"[a-zA-Z0-9_]+") -@total_ordering class _Comparable(_Common): - def __lt__(self, other): - raise NotImplementedError + def __gt__(self, other): + return not (self < other or self == other) + + def __le__(self, other): + return self < other or self == other + + def __ge__(self, other): + return not self < other -@total_ordering class _ReversedComparable(_Common): def __init__(self, value): self.value = value @@ -42,6 +47,15 @@ def __init__(self, value): def __lt__(self, other): return not (self.value < other.value) + def __gt__(self, other): + return not (self < other or self == other) + + def __le__(self, other): + return self < other or self == other + + def __ge__(self, other): + return not self < other + def __str__(self): return "reverse(%s)" % str(self.value) @@ -655,10 +669,10 @@ def fn_(self): result = fn(self) if self.debug: label = fn.__name__.replace("_act_", "") - print "%-21s: %s" % (label, self._input_string) + print("%-21s: %s" % (label, self._input_string)) for key, value in self._groups.items(): - print " %-17s= %s" % (key, value) - print " %-17s= %s" % ("bounds", self.bounds) + print(" %-17s= %s" % (key, value)) + print(" %-17s= %s" % ("bounds", self.bounds)) return result return fn_ @@ -1310,6 +1324,9 @@ def __init__(self, range_, iterable, key=None, descending=False, mode=MODE_ALL): def __iter__(self): return self + def __next__(self): + return self.next_fn() + def next(self): return self.next_fn()