diff --git a/.travis.yml b/.travis.yml index 0332bbb..dd4eeed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: python +dist: xenial python: - - '2.7' - - '3.3' - - '3.4' - - pypy + - 3.5 + - 3.6 + - 3.7 install: - pip install -e . - pip install -r test-requirements.txt @@ -18,6 +18,6 @@ deploy: secure: qzSC7nsNS1rnDKgiZe2GiojMznf35GLzUeqlf5HESYiKDIlXLIpdxS1Ii9G+afnJH1cGT9dheDUvlRzwZ3eDsZHbVYjKtj/uvy8j4x8H+N66Zvm1AMdGvF4sDCUo01DdbsSe7Xh77VY3kV0AgHb8UZuXOgXcdN0kYJjfWuUWTl0= distributions: "sdist bdist_wheel" on: - python: 2.7 + python: 3.6 tags: true all_branches: true diff --git a/HISTORY.rst b/HISTORY.rst index 1a621c3..f37329e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,12 @@ Version History --------------- +`2.0.0`_ (26-Nov-2018) +~~~~~~~~~~~~~~~~~~~~~~ +- Drop support for Python 2.7, 3.3, 3.4 +- Drop support for Tornado < 4.2 +- Add support for Tornado 5.1 and async with ``AsyncIOHandlerMixin`` + `1.0.2`_ (20-Jun-2016) ~~~~~~~~~~~~~~~~~~~~~~ - Add support for async prepare in superclasses of ``HandlerMixin`` @@ -9,6 +15,6 @@ Version History ~~~~~~~~~~~~~~~~~~~~~~ - Adds ``sprockets.mixins.correlation.HandlerMixin`` - +.. _`2.0.0`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.2...2.0.0 .. _`1.0.2`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.1...1.0.2 .. _`1.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/0.0.0...1.0.1 diff --git a/LICENSE b/LICENSE index 3c72859..4fa05e6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015 AWeber Communications +Copyright (c) 2015-2018 AWeber Communications All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/dev-requirements.txt b/dev-requirements.txt index 4e8c0ae..8870054 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,5 @@ -r requirements.txt -r test-requirements.txt -flake8>=2.1,<3 +flake8 sphinx>=1.2,<2 sphinx-rtd-theme>=0.1,<1.0 -tornado>=4.0,<5 diff --git a/docs/index.rst b/docs/index.rst index 30bedc7..0d0efc5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,6 +8,10 @@ correlation.HandlerMixin .. autoclass:: sprockets.mixins.correlation.HandlerMixin :members: +.. autoclass:: sprockets.mixins.correlation.AsyncIOHandlerMixin + :members: + + Contributing to this Library ---------------------------- diff --git a/requirements.txt b/requirements.txt index 3f55f96..b33c704 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -tornado>=3.1,<4.4 +tornado>=4.0,<5.2 diff --git a/setup.py b/setup.py index 27435c0..c9c7f31 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import codecs +from os import path import sys import setuptools @@ -7,24 +8,23 @@ import setuptools from sprockets.mixins import correlation -def read_requirements_file(req_name): +def read_requirements(name): requirements = [] try: - with codecs.open(req_name, encoding='utf-8') as req_file: - for req_line in req_file: - if '#' in req_line: - req_line = req_line[0:req_line.find('#')].strip() - if req_line: - requirements.append(req_line.strip()) + with open(path.join('requires', name)) as req_file: + for line in req_file: + if '#' in line: + line = line[:line.index('#')] + line = line.strip() + if line.startswith('-r'): + requirements.extend(read_requirements(line[2:].strip())) + elif line and not line.startswith('-'): + requirements.append(line) except IOError: pass return requirements -install_requires = read_requirements_file('requirements.txt') -setup_requires = read_requirements_file('setup-requirements.txt') -tests_require = read_requirements_file('test-requirements.txt') - setuptools.setup( name='sprockets.mixins.correlation', version=correlation.__version__, @@ -35,16 +35,15 @@ setuptools.setup( author_email='api@aweber.com', license=codecs.open('LICENSE', encoding='utf-8').read(), classifiers=[ - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries', @@ -52,9 +51,8 @@ setuptools.setup( ], packages=setuptools.find_packages(), namespace_packages=['sprockets'], - install_requires=install_requires, - setup_requires=setup_requires, - tests_require=tests_require, + install_requires=read_requirements('requirements.txt'), + tests_require=read_requirements('test-requirements.txt'), test_suite='nose.collector', zip_safe=True, ) diff --git a/sprockets/mixins/correlation/__init__.py b/sprockets/mixins/correlation/__init__.py index 0dfe0ff..1611839 100644 --- a/sprockets/mixins/correlation/__init__.py +++ b/sprockets/mixins/correlation/__init__.py @@ -1,12 +1,11 @@ try: from .mixins import HandlerMixin - -except ImportError as error: +except ImportError: class HandlerMixin(object): def __init__(self, *args, **kwargs): - raise error + raise ImportError -version_info = (1, 0, 2) +version_info = (2, 0, 0) __version__ = '.'.join(str(v) for v in version_info[:3]) diff --git a/sprockets/mixins/correlation/mixins.py b/sprockets/mixins/correlation/mixins.py index 121c4d6..7703ec6 100644 --- a/sprockets/mixins/correlation/mixins.py +++ b/sprockets/mixins/correlation/mixins.py @@ -1,15 +1,6 @@ import uuid -import tornado.gen -import tornado.log - -if tornado.version_info[0] >= 4: - from tornado.concurrent import is_future -else: - import tornado.concurrent - - def is_future(maybe_future): - return isinstance(maybe_future, tornado.concurrent.Future) +from tornado import concurrent, log class HandlerMixin(object): @@ -50,14 +41,13 @@ class HandlerMixin(object): self.__correlation_id = str(uuid.uuid4()) super(HandlerMixin, self).__init__(*args, **kwargs) - @tornado.gen.coroutine - def prepare(self): + async def prepare(self): # Here we want to copy an incoming Correlation-ID header if # one exists. We also want to set it in the outgoing response # which the property setter does for us. maybe_future = super(HandlerMixin, self).prepare() - if is_future(maybe_future): - yield maybe_future + if concurrent.is_future(maybe_future): + await maybe_future correlation_id = self.get_request_header(self.__header_name, None) if correlation_id is not None: @@ -113,11 +103,11 @@ def correlation_id_logger(handler): is processing the client request. """ if handler.get_status() < 400: - log_method = tornado.log.access_log.info + log_method = log.access_log.info elif handler.get_status() < 500: - log_method = tornado.log.access_log.warning + log_method = log.access_log.warning else: - log_method = tornado.log.access_log.error + log_method = log.access_log.error request_time = 1000.0 * handler.request.request_time() correlation_id = getattr(handler, "correlation_id", None) if correlation_id is None: diff --git a/test-requirements.txt b/test-requirements.txt index dc209eb..27a5c8e 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -coverage>=3.7,<4 -coveralls>=0.4,<1 -nose>=1.3,<2 -tox>=1.7,<2 +coverage>=4.5.2,<5 +coveralls>=1.5.1,<2 +nose>=1.3.7,<2 +tox>=3.5.3,<4 diff --git a/tests.py b/tests.py index 9abe799..72ac07f 100644 --- a/tests.py +++ b/tests.py @@ -23,18 +23,15 @@ class CorrelationMixinTests(testing.AsyncHTTPTestCase): ]) def test_that_correlation_id_is_returned_when_successful(self): - self.http_client.fetch(self.get_url('/status/200'), self.stop) - response = self.wait() + response = self.fetch('/status/200') self.assertIsNotNone(response.headers.get('Correlation-ID')) def test_that_correlation_id_is_returned_in_error(self): - self.http_client.fetch(self.get_url('/status/500'), self.stop) - response = self.wait() + response = self.fetch('/status/500') self.assertIsNotNone(response.headers.get('Correlation-ID')) def test_that_correlation_id_is_copied_from_request(self): correlation_id = uuid.uuid4().hex - self.http_client.fetch(self.get_url('/status/200'), self.stop, - headers={'Correlation-Id': correlation_id}) - response = self.wait() + response = self.fetch('/status/500', + headers={'Correlation-Id': correlation_id}) self.assertEqual(response.headers['correlation-id'], correlation_id) diff --git a/tox.ini b/tox.ini index 1f3b989..cba03ff 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py33,py34,pypy,pypy3,tornado31,tornado32,tornado40,tornado43 +envlist = py35,py36,py37,tornado43,torando51 toxworkdir = {toxinidir}/build/tox skip_missing_intepreters = true @@ -9,27 +9,12 @@ deps = tornado commands = {envbindir}/nosetests -[testenv:py27] -deps = - {[testenv]deps} - mock - -[testenv:tornado31] -deps = - -rtest-requirements.txt - tornado>=3.1,<3.2 - -[testenv:tornado32] -deps = - -rtest-requirements.txt - tornado>=3.2,<3.3 - -[testenv:tornado40] -deps = - -rtest-requirements.txt - tornado>=4.0,<4.1 - [testenv:tornado43] deps = -rtest-requirements.txt tornado>=4.3,<4.4 + +[testenv:tornado51] +deps = + -rtest-requirements.txt + tornado>=5.1,<5.2