diff --git a/.gitignore b/.gitignore index 9514978..4a43022 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,6 @@ include/ lib/ parts/ -doc/_build -doc/__pycache__ -doc/relstorage.*.rst -doc/changelog.rst + +docs/_build /.settings/ diff --git a/.travis.yml b/.travis.yml index 8e23adf..9e8b12c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,19 @@ language: python -sudo: false group: travis_latest language: python -jobs: - include: - - python: 2.7 # 2.7.14 pip 9.0.1 - - python: 3.6 # 3.6.3 pip 9.0.1 - - python: 3.7 # 3.7.0 pip 10.0.1 - dist: xenial - sudo: true - - python: pypy # 2.7.13 pip 9.0.1 - - python: pypy3 # 3.5.3 pip 9.0.1 +python: + - 2.7 + - 3.6 + - 3.7 + - 3.8 + - pypy + - pypy3 env: global: - PYTHONHASHSEED=random - PIP_UPGRADE_STRATEGY=eager script: + - pylint nti.transactions - coverage run -m zope.testrunner --test-path=src after_success: - coveralls diff --git a/CHANGES.rst b/CHANGES.rst index f39deb8..78831ad 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,10 +3,16 @@ Changes ========= -3.0.1 (unreleased) +3.1.0 (unreleased) ================== -- Nothing changed yet. +- Add support for Python 3.8. + +- Refactor internal implementation details. Instead of importing + everything from ``nti.transactions.transactions``, more specific + modules are used to group objects by function. The old imports + continue to work. In 4.0 they will generate a deprecation warning + and in 5.0 they will be removed. 3.0.0 (2019-09-06) diff --git a/README.rst b/README.rst index 1361aae..d276db0 100644 --- a/README.rst +++ b/README.rst @@ -17,10 +17,10 @@ Extensions to the `transaction`_ package. -Transaction Manager -=================== +Transaction Management +====================== -``nti.transactions.transactions.TransactionsLoop`` is a retryable +``nti.transactions.loop.TransactionsLoop`` is a retryable transaction manager. It is conceptually similar to the `attempts`_ context manager provided by the transaction package itself, but much more powerful and extensible via subclasses. Features include: @@ -34,7 +34,8 @@ more powerful and extensible via subclasses. Features include: The TransactionLoop can be used as-is, or it can be subclassed for customization. For use in a Pyramid tween, for example, a minimal -subclass might look like this:: +subclass might look like this (see ``nti.transactions.pyramid_tween`` +for a full-featured tween):: >>> class PyramidTransactionLoop(TransactionLoop): ... def prep_for_retry(self, number, request): @@ -52,7 +53,7 @@ The first data manager is used to put an object in a ``queue`` transaction succeeds. If the queue is full, then the transaction will not be allowed to commit:: - >>> from nti.transactions.transactions import put_nowait + >>> from nti.transactions.queue import put_nowait >>> put_nowait(queue, object) This is a special case of the ``ObjectDataManager``, which will call @@ -63,12 +64,12 @@ the transaction is successful. It can be constructed directly, but the ``do`` function is a shorthand way of joining one to the current transaction:: - >>> from nti.transactions.transactions import do + >>> from nti.transactions.manager import do >>> do(print, args=("Committed")) .. caution:: See the documentation of this object for numerous - warnings about side-effects and its interaction with the - transaction machinery. Use it with care! + warnings about side-effects and its interaction with the + transaction machinery. Use it with care! .. _attempts: http://zodb.readthedocs.io/en/latest/transactions.html#retrying-transactions .. _data managers: http://zodb.readthedocs.io/en/latest/transactions.html#data-managers diff --git a/docs/conf.py b/docs/conf.py index 69845cb..d706602 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -355,6 +355,8 @@ # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { 'https://docs.python.org/': None, + 'https://transaction.readthedocs.io/en/latest/': None, + 'https://perfmetrics.readthedocs.io/en/latest/': None, } extlinks = {'issue': ('https://github.com/NextThought/nti.transactions/issues/%s', diff --git a/docs/index.rst b/docs/index.rst index 9472712..3b3f9c9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,12 +8,39 @@ Contents: changelog + + +nti.transactions.interfaces +=========================== .. automodule:: nti.transactions.interfaces :members: -.. automodule:: nti.transactions.transactions + +nti.transactions.manager +======================== +.. automodule:: nti.transactions.manager + :members: + +nti.transactions.queue +====================== +.. automodule:: nti.transactions.queue :members: +nti.transactions.loop +===================== +.. automodule:: nti.transactions.loop + :members: + +nti.transactions.pyramid_tween +============================== +.. automodule:: nti.transactions.pyramid_tween + :members: + +nti.transactions.transactions (deprecated) +========================================== + +This module only contains backwards compatibility imports. + ==================== Indices and tables diff --git a/setup.py b/setup.py index 544af77..8fc047c 100755 --- a/setup.py +++ b/setup.py @@ -9,9 +9,10 @@ } TESTS_REQUIRE = [ - 'zope.testrunner', - 'nti.testing', 'fudge', + 'nti.testing', + 'pylint', + 'zope.testrunner', ] def _read(fname): diff --git a/src/nti/transactions/interfaces.py b/src/nti/transactions/interfaces.py index ea467c7..644c1b3 100644 --- a/src/nti/transactions/interfaces.py +++ b/src/nti/transactions/interfaces.py @@ -17,10 +17,16 @@ class IExtendedTransaction(ITransaction): """Extensions to the transaction api.""" def nti_commit(): - """Like ``commit``, but produces a perfmetrics ``transaction.commit`` metric.""" + """ + Like ``commit``, but produces a :obj:`perfmetrics.Metric` ``transaction.commit`` + metric. + """ def nti_abort(): - """Like ``abort``, but produces a perfmetrics ``transaction.abort`` metric.""" + """ + Like ``abort``, but produces a :obj:`perfmetrics.Metric` + ``transaction.abort`` metric. + """ class CommitFailedError(TransactionError): """ diff --git a/src/nti/transactions/loop.py b/src/nti/transactions/loop.py index eabeec8..15f2aa1 100644 --- a/src/nti/transactions/loop.py +++ b/src/nti/transactions/loop.py @@ -28,7 +28,6 @@ def exc_clear(): from zope.exceptions.exceptionformatter import format_exception from zope.exceptions.exceptionformatter import print_exception -TRACE = 5 # from ZODB.loglevels. from .interfaces import CommitFailedError from .interfaces import AbortFailedError from .interfaces import ForeignTransactionError @@ -130,6 +129,7 @@ def __init__(self, response, reason): #: If not none, this should be a number that will be passed to #: time.sleep or gevent.sleep in between retries. + #: TODO: add a backoff delay interval/multiplier between retries. sleep = None attempts = 10 long_commit_duration = DEFAULT_LONG_RUNNING_COMMIT_IN_SECS # seconds diff --git a/src/nti/transactions/transactions.py b/src/nti/transactions/transactions.py index 755b6eb..87c12d6 100644 --- a/src/nti/transactions/transactions.py +++ b/src/nti/transactions/transactions.py @@ -10,6 +10,8 @@ logger = __import__('logging').getLogger(__name__) # BWC imports +# For 4.0 makke this produce a deprecation warning. For 5.0 +# remove this. from dm.transaction.aborthook import add_abort_hooks from nti.transactions.loop import TransactionLoop from nti.transactions.manager import ObjectDataManager diff --git a/tox.ini b/tox.ini index abd38a4..6d516a6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,19 @@ [tox] -envlist = py27,py35,py36,py37,pypy,pypy3,coverage +envlist = py27,py35,py36,py37,py38,pypy,pypy3,coverage [testenv] usedevelop = true commands = zope-testrunner --test-path=src [] -deps = - .[test] + pylint nti.transactions +extras = test + [testenv:coverage] basepython = - python2.7 + python3.8 commands = coverage run -m zope.testrunner --test-path=src coverage report --fail-under=100 deps = - {[testenv]deps} coverage