From 5fbf23e35365bb70002cbad591980a92267f57ba Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Thu, 28 Jul 2016 08:59:49 -0500 Subject: [PATCH] Initial py3 support. --- .travis.yml | 2 ++ CHANGES | 0 CHANGES.rst | 7 +++++++ README.rst | 7 +++++++ setup.py | 5 ++++- .../tests/test_transaction_queue.py | 9 +++++++-- src/nti/transactions/transactions.py | 20 ++++++++++++------- tox.ini | 3 +-- 8 files changed, 41 insertions(+), 12 deletions(-) delete mode 100644 CHANGES create mode 100644 CHANGES.rst diff --git a/.travis.yml b/.travis.yml index 2d761f1..3458b54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: python sudo: false python: - 2.7 + - 3.4 + - 3.5 - pypy script: - coverage run `which zope-testrunner` --test-path=src --auto-color --auto-progress diff --git a/CHANGES b/CHANGES deleted file mode 100644 index e69de29..0000000 diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 0000000..608fdfe --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,7 @@ +Changes +======== + +1.0.0 (unreleased) +------------------ + +- Add support for Python 3. diff --git a/README.rst b/README.rst index e69de29..3e1500b 100644 --- a/README.rst +++ b/README.rst @@ -0,0 +1,7 @@ +================== + nti.transactions +================== + +Extensions to the `transaction`_ package. + +.. _transaction: https://pypi.python.org/pypi/transaction diff --git a/setup.py b/setup.py index d836d24..339566e 100755 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def _read(fname): author='Jason Madden', author_email='jason@nextthought.com', description="NTI Transactions Utility", - long_description=_read('README.rst'), + long_description=_read('README.rst') + _read('CHANGES.rst'), license='Apache', keywords='ZODB transaction', classifiers=[ @@ -34,7 +34,10 @@ def _read(fname): 'Development Status :: 5 - Production/Stable', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', 'Framework :: ZODB', ], packages=find_packages('src'), diff --git a/src/nti/transactions/tests/test_transaction_queue.py b/src/nti/transactions/tests/test_transaction_queue.py index dcd4854..fed5f26 100644 --- a/src/nti/transactions/tests/test_transaction_queue.py +++ b/src/nti/transactions/tests/test_transaction_queue.py @@ -12,13 +12,18 @@ from hamcrest import assert_that import transaction +import six try: from gevent.queue import Full from gevent.queue import Queue except ImportError: - from Queue import Full - from Queue import Queue + if six.PY2: + from Queue import Full + from Queue import Queue + else: + from queue import Full + from queue import Queue from nti.transactions.transactions import put_nowait diff --git a/src/nti/transactions/transactions.py b/src/nti/transactions/transactions.py index 1a81545..ce42e4b 100644 --- a/src/nti/transactions/transactions.py +++ b/src/nti/transactions/transactions.py @@ -18,12 +18,16 @@ import sys import time +import six + from zope import interface from ZODB.loglevels import TRACE +from ZODB.POSException import StorageError import transaction + from transaction.interfaces import TransactionError from transaction.interfaces import IDataManagerSavepoint from transaction.interfaces import ISavepointDataManager @@ -32,7 +36,11 @@ from gevent import sleep as _sleep from gevent.queue import Full as QFull except ImportError: # pragma: no cover # pypy - from Queue import Full as QFull + if six.PY2: + from Queue import Full as QFull + else: + from queue import Full as QFull + from time import sleep as _sleep from dm.transaction.aborthook import add_abort_hooks @@ -225,7 +233,6 @@ def do(*args, **kwargs): transaction.get().join( ObjectDataManager(*args, **kwargs)) -from ZODB.POSException import StorageError def _do_commit(tx, description, long_commit_duration): exc_info = sys.exc_info() @@ -238,7 +245,7 @@ def _do_commit(tx, description, long_commit_duration): except TypeError: # Translate this into something meaningful exc_info = sys.exc_info() - raise StorageError, exc_info[1], exc_info[2] + six.reraise(StorageError, exc_info[1], exc_info[2]) except (AssertionError, ValueError): # pragma: no cover # We've seen this when we are recalled during retry handling. The higher level # is in the process of throwing a different exception and the transaction is @@ -248,7 +255,7 @@ def _do_commit(tx, description, long_commit_duration): # TODO: Prior to transaction 1.4.0, this was only an AssertionError. 1.4 makes it a ValueError, which is hard to distinguish and might fail retries? logger.exception("Failing to commit; should already be an exception in progress") if exc_info and exc_info[0]: - raise exc_info[0], None, exc_info[2] + six.reraise(exc_info[0], None, exc_info[2]) raise @@ -476,7 +483,7 @@ def __call__(self, *args, **kwargs): del orig_excinfo self.__free(tx); del tx - raise TransactionError, exc_info[1], exc_info[2] + six.reraise(TransactionError, exc_info[1], exc_info[2]) self.__free(tx); del tx @@ -491,7 +498,6 @@ def __call__(self, *args, **kwargs): _sleep(self.sleep) # logger.log( TRACE, "Retrying transaction on exception %d", number, exc_info=True ) except SystemExit: - t, v, tb = sys.exc_info() # If we are exiting, or otherwise probably going to exit, do try # to abort the transaction. The state of the system is somewhat undefined # at this point, though, so don't try to time or log it, just print to stderr on exception. @@ -502,7 +508,7 @@ def __call__(self, *args, **kwargs): from zope.exceptions.exceptionformatter import print_exception print_exception(*sys.exc_info()) - raise t, v, tb + raise # By default, it wants to create a different logger # for each and every thread or greenlet. We go through diff --git a/tox.ini b/tox.ini index beb3eb1..8226349 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,5 @@ [tox] -envlist = pypy, py27 -#, py34, py35 +envlist = pypy, py27, py34, py35 [testenv] deps =