Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swap 2.6 support for 3.x in version module #718

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions src/rez/vendor/version/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
35 changes: 26 additions & 9 deletions src/rez/vendor/version/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,20 +29,33 @@
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

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)

Expand Down Expand Up @@ -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_

Expand Down Expand Up @@ -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()

Expand Down