]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a new TORNADO_EXTENSION environment variable for testing purposes.
authorBen Darnell <ben@bendarnell.com>
Fri, 17 Jan 2014 03:32:32 +0000 (22:32 -0500)
committerBen Darnell <ben@bendarnell.com>
Fri, 17 Jan 2014 03:32:32 +0000 (22:32 -0500)
This variable can be set to 0 to suppress or 1 to require the use of the
extension (instead of the default to use it when it is available but silently
fall back).  Require the extension to be present on travis-ci.

.travis.yml
setup.py
tornado/websocket.py

index 0ab836688aa3074f5e8cdfbb2060b654da8c411c..704e09ad05c818e51f7b2e9c439af1b85ac5d534 100644 (file)
@@ -19,10 +19,13 @@ install:
     - if [[ $TRAVIS_PYTHON_VERSION == 'pypy' && $DEPS == true ]]; then pip install --use-mirrors futures mock; fi
     - if [[ $TRAVIS_PYTHON_VERSION == '3.2' && $DEPS == true ]]; then pip install --use-mirrors pycares mock; fi
     - if [[ $TRAVIS_PYTHON_VERSION == '3.3' && $DEPS == true ]]; then pip install --use-mirrors pycares; fi
+    # On travis the extension should always be built
+    - if [[ $TRAVIS_PYTHON_VERSION != 'pypy' ]]; then export TORNADO_EXTENSION=1; fi
     - python setup.py install
     - pip install --use-mirrors coveralls
 
 script:
+    - if [[ $TRAVIS_PYTHON_VERSION != 'pypy' ]]; then export TORNADO_EXTENSION=1; fi
     - export TARGET="-m tornado.test.runtests"
     # We use "python -m coverage" instead of the "bin/coverage" script
     # so we can pass additional arguments to python.  However, this doesn't
index eb496d9818c961da88b71bd07679814a8fbd82a2..11250532cf6ff0a4ff2512029345ecd70c062fbd 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import os
 import platform
 import sys
 import warnings
@@ -118,7 +119,8 @@ version = "3.2"
 with open('README.rst') as f:
     kwargs['long_description'] = f.read()
 
-if platform.python_implementation() == 'CPython':
+if (platform.python_implementation() == 'CPython' and
+    os.environ.get('TORNADO_EXTENSION') != '0'):
     # This extension builds and works on pypy as well, although pypy's jit
     # produces equivalent performance.
     kwargs['ext_modules'] = [
@@ -126,6 +128,11 @@ if platform.python_implementation() == 'CPython':
                   sources=['tornado/speedups.c']),
     ]
 
+    if os.environ.get('TORNADO_EXTENSION') != '1':
+        # Unless the user has specified that the extension is mandatory,
+        # fall back to the pure-python implementation on any build failure.
+        kwargs['cmdclass'] = {'build_ext': custom_build_ext}
+
 if setuptools is not None:
     # If setuptools is not available, you're on your own for dependencies.
     if sys.version_info < (3, 2):
@@ -170,6 +177,5 @@ setup(
         'Programming Language :: Python :: Implementation :: CPython',
         'Programming Language :: Python :: Implementation :: PyPy',
         ],
-    cmdclass={"build_ext": custom_build_ext},
     **kwargs
 )
index 9bec9bbae28d63d667fc20db69b4c484e9a6369d..fda231d0c2effe7ef995d424cf652c1faaabe3cb 100644 (file)
@@ -913,12 +913,15 @@ def _websocket_mask_python(mask, data):
     else:
         return unmasked.tostring()
 
-if os.environ.get('TORNADO_NO_EXTENSION'):
-    # This environment variable exists to make it easier to do performance comparisons;
-    # it's not guaranteed to remain supported in the future.
+if (os.environ.get('TORNADO_NO_EXTENSION') or
+    os.environ.get('TORNADO_EXTENSION') == '0'):
+    # These environment variables exist to make it easier to do performance
+    # comparisons; they are not guaranteed to remain supported in the future.
     _websocket_mask = _websocket_mask_python
 else:
     try:
         from tornado.speedups import websocket_mask as _websocket_mask
     except ImportError:
+        if os.environ.get('TORNADO_EXTENSION') == '1':
+            raise
         _websocket_mask = _websocket_mask_python