Added total_ordering to Py2.6 requirements

This commit is contained in:
Konsta Vesterinen
2013-10-23 09:00:01 +03:00
parent 00395f8702
commit a797731f2d
5 changed files with 15 additions and 76 deletions

View File

@@ -4,6 +4,12 @@ Changelog
Here you can see the full list of changes between each SQLAlchemy-Utils release.
0.17.1 (2013-10-23)
^^^^^^^^^^^^^^^^^^^
- Removed compat module, added total_ordering package to Python 2.6 requirements
0.17.0 (2013-10-23)
^^^^^^^^^^^^^^^^^^^

View File

@@ -57,7 +57,7 @@ for name, requirements in extras_require.items():
setup(
name='SQLAlchemy-Utils',
version='0.17.0',
version='0.17.1',
url='https://github.com/kvesteri/sqlalchemy-utils',
license='BSD',
author='Konsta Vesterinen, Ryan Leckey, Janne Vanhala, Vesa Uimonen',
@@ -78,6 +78,8 @@ setup(
install_requires=[
'six',
'SQLAlchemy>=0.8.0',
'total_ordering>=0.1'
if sys.version_info[0] == 2 and sys.version_info[1] < 7 else ''
],
extras_require=extras_require,
cmdclass={'test': PyTest},

View File

@@ -38,7 +38,7 @@ from .types import (
)
__version__ = '0.17.0'
__version__ = '0.17.1'
__all__ = (

View File

@@ -1,73 +0,0 @@
# -*- coding: utf-8 -*-
try:
from functools import total_ordering
except ImportError:
""" Backport to work with Python 2.6 """
def total_ordering(cls):
"""Class decorator that fills in missing ordering methods"""
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

View File

@@ -4,7 +4,11 @@ from sqlalchemy import types
from sqlalchemy.dialects.postgresql import BIT
import six
from ..compat import total_ordering
try:
from functools import total_ordering
except ImportError:
# Python 2.6 port
from total_ordering import total_ordering
from sqlalchemy_utils import i18n