Skip to content

Commit

Permalink
Merge pull request #5 from NextThought/py3
Browse files Browse the repository at this point in the history
Initial py3 support.
  • Loading branch information
jamadden committed Jul 28, 2016
2 parents 44ac442 + 5fbf23e commit d29d1e2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -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
Expand Down
Empty file removed CHANGES
Empty file.
7 changes: 7 additions & 0 deletions CHANGES.rst
@@ -0,0 +1,7 @@
Changes
========

1.0.0 (unreleased)
------------------

- Add support for Python 3.
7 changes: 7 additions & 0 deletions README.rst
@@ -0,0 +1,7 @@
==================
nti.transactions
==================

Extensions to the `transaction`_ package.

.. _transaction: https://pypi.python.org/pypi/transaction
5 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -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=[
Expand All @@ -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'),
Expand Down
9 changes: 7 additions & 2 deletions src/nti/transactions/tests/test_transaction_queue.py
Expand Up @@ -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

Expand Down
20 changes: 13 additions & 7 deletions src/nti/transactions/transactions.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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

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

Expand All @@ -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.
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
@@ -1,6 +1,5 @@
[tox]
envlist = pypy, py27
#, py34, py35
envlist = pypy, py27, py34, py35

[testenv]
deps =
Expand Down

0 comments on commit d29d1e2

Please sign in to comment.