]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make singledispatch and backports_abc mandatory dependencies.
authorBen Darnell <ben@bendarnell.com>
Sun, 18 Oct 2015 20:34:47 +0000 (22:34 +0200)
committerBen Darnell <ben@bendarnell.com>
Sun, 18 Oct 2015 20:34:47 +0000 (22:34 +0200)
I anticipate confusion around the differing behavior based on whether or
not these packages are installed, so it's better to just make them
mandatory (except on app engine).

.travis.yml
setup.py
tornado/gen.py
tornado/test/asyncio_test.py
tornado/test/twisted_test.py

index f7affbba54cdf80055f5a50e4d41a669bc8cdf50..2e34e3915a33be3ece3653e26a85aeb92f169568 100644 (file)
@@ -19,12 +19,11 @@ install:
     # always install unittest2 on py26 even if $DEPS is unset
     - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then travis_retry pip install unittest2; fi
     - if [[ $TRAVIS_PYTHON_VERSION == 2* && $DEPS == true ]]; then travis_retry pip install futures mock Monotime trollius; fi
-    - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then travis_retry pip install singledispatch; fi
-    - if [[ $TRAVIS_PYTHON_VERSION == 'pypy' && $DEPS == true ]]; then travis_retry pip install futures mock singledispatch; fi
+    - if [[ $TRAVIS_PYTHON_VERSION == 'pypy' && $DEPS == true ]]; then travis_retry pip install futures mock; fi
     # TODO(bdarnell): pycares tests are currently disabled on travis due to ipv6 issues.
     #- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* && $DEPS == true ]]; then travis_retry pip install pycares; fi
     - if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* && $DEPS == true ]]; then travis_retry pip install pycurl; fi
-    - if [[ $TRAVIS_PYTHON_VERSION == '3.2' && $DEPS == true ]]; then travis_retry pip install mock singledispatch; fi
+    - if [[ $TRAVIS_PYTHON_VERSION == '3.2' && $DEPS == true ]]; then travis_retry pip install mock; fi
     # Twisted runs on 2.x and 3.3+, but is flaky on pypy.
     - if [[ $TRAVIS_PYTHON_VERSION != '3.2' && $TRAVIS_PYTHON_VERSION != 'pypy'* && $DEPS == true ]]; then travis_retry pip install Twisted; fi
     - if [[ $TRAVIS_PYTHON_VERSION == '2.7' && $DEPS == true ]]; then travis_retry pip install sphinx sphinx_rtd_theme; fi
index 49e436ec3bf13027fb8a26af5990649174907c49..c63e14b44a4bb7e81dbb507814290a927acb2621 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -125,10 +125,13 @@ if setuptools is not None:
     if sys.version_info < (3, 2):
         install_requires.append('backports.ssl_match_hostname')
     if sys.version_info < (3, 4):
+        install_requires.append('singledispatch')
         # Certifi is also optional on 2.7.9+, although making our dependencies
         # conditional on micro version numbers seems like a bad idea
         # until we have more declarative metadata.
         install_requires.append('certifi')
+    if sys.version_info < (3, 5):
+        install_requires.append('backports_abc>=0.4')
     kwargs['install_requires'] = install_requires
 
 setup(
index 84a2da68325f243e9889f11bbd9a204f4c0633cf..bf184e548451226ffd43081217fc0aa22814e751 100644 (file)
@@ -79,6 +79,7 @@ from __future__ import absolute_import, division, print_function, with_statement
 import collections
 import functools
 import itertools
+import os
 import sys
 import textwrap
 import types
@@ -90,30 +91,38 @@ from tornado import stack_context
 from tornado.util import raise_exc_info
 
 try:
-    from functools import singledispatch  # py34+
-except ImportError as e:
     try:
-        from singledispatch import singledispatch  # backport
+        from functools import singledispatch  # py34+
     except ImportError:
-        singledispatch = None
-
+        from singledispatch import singledispatch  # backport
+except ImportError:
+    # In most cases, singledispatch is required (to avoid
+    # difficult-to-diagnose problems in which the functionality
+    # available differs depending on which invisble packages are
+    # installed). However, in Google App Engine third-party
+    # dependencies are more trouble so we allow this module to be
+    # imported without it.
+    if 'APPENGINE_RUNTIME' not in os.environ:
+        raise
+    singledispatch = None
 
 try:
-    from collections.abc import Generator as GeneratorType  # py35+
-except ImportError:
     try:
-        from backports_abc import Generator as GeneratorType
+        from collections.abc import Generator as GeneratorType  # py35+
     except ImportError:
-        from types import GeneratorType
+        from backports_abc import Generator as GeneratorType
 
-try:
-    from inspect import isawaitable  # py35+
-except ImportError:
     try:
-        from backports_abc import isawaitable
+        from inspect import isawaitable  # py35+
     except ImportError:
-        def isawaitable(x):
-            return False
+        from backports_abc import isawaitable
+except ImportError:
+    if 'APPENGINE_RUNTIME' not in os.environ:
+        raise
+    from types import GeneratorType
+
+    def isawaitable(x):
+        return False
 
 try:
     import builtins  # py3
index 52ba9d353b73e501d2e97fc815f7009b2e3695b9..b50b2048ee8e39bb7ae8eebb8f0751336b046d24 100644 (file)
@@ -25,9 +25,6 @@ else:
     # This is used in dynamically-evaluated code, so silence pyflakes.
     to_asyncio_future
 
-skipIfNoSingleDispatch = unittest.skipIf(
-    gen.singledispatch is None, "singledispatch module not present")
-
 
 @unittest.skipIf(asyncio is None, "asyncio module not present")
 class AsyncIOLoopTest(AsyncTestCase):
@@ -41,7 +38,6 @@ class AsyncIOLoopTest(AsyncTestCase):
         asyncio.get_event_loop().call_soon(self.stop)
         self.wait()
 
-    @skipIfNoSingleDispatch
     @gen_test
     def test_asyncio_future(self):
         # Test that we can yield an asyncio future from a tornado coroutine.
@@ -51,7 +47,6 @@ class AsyncIOLoopTest(AsyncTestCase):
         self.assertEqual(x, 42)
 
     @skipBefore33
-    @skipIfNoSingleDispatch
     @gen_test
     def test_asyncio_yield_from(self):
         # Test that we can use asyncio coroutines with 'yield from'
index 3be087cb128ee6a53db53f6ae08a1ae053ed0920..8389e60bbf63d33c02f7b1559d5e2857eebfe503 100644 (file)
@@ -72,9 +72,6 @@ from tornado.web import RequestHandler, Application
 skipIfNoTwisted = unittest.skipUnless(have_twisted,
                                       "twisted module not present")
 
-skipIfNoSingleDispatch = unittest.skipIf(
-    gen.singledispatch is None, "singledispatch module not present")
-
 
 def save_signal_handlers():
     saved = {}
@@ -495,7 +492,6 @@ class CompatibilityTests(unittest.TestCase):
             'http://127.0.0.1:%d' % self.tornado_port, self.run_reactor)
         self.assertEqual(response, 'Hello from tornado!')
 
-    @skipIfNoSingleDispatch
     def testTornadoServerTwistedCoroutineClientIOLoop(self):
         self.start_tornado_server()
         response = self.twisted_coroutine_fetch(
@@ -504,7 +500,6 @@ class CompatibilityTests(unittest.TestCase):
 
 
 @skipIfNoTwisted
-@skipIfNoSingleDispatch
 class ConvertDeferredTest(unittest.TestCase):
     def test_success(self):
         @inlineCallbacks