Be more careful when Cython is available but NumPy is not

This commit is contained in:
Mark Florisson
2015-08-08 12:28:53 +01:00
parent 3b6b720c4b
commit 53b2b48f58
3 changed files with 18 additions and 13 deletions

View File

@@ -2,4 +2,10 @@ try:
from cassandra.rowparser import make_recv_results_rows
HAVE_CYTHON = True
except ImportError:
HAVE_CYTHON = False
HAVE_CYTHON = False
try:
import numpy
HAVE_NUMPY = True
except ImportError:
HAVE_NUMPY = False

View File

@@ -40,7 +40,7 @@ from cassandra.cqltypes import (AsciiType, BytesType, BooleanType,
TupleType, lookup_casstype, SimpleDateType,
TimeType, ByteType, ShortType)
from cassandra.policies import WriteType
from cassandra.cython_deps import HAVE_CYTHON
from cassandra.cython_deps import HAVE_CYTHON, HAVE_NUMPY
from cassandra import util
log = logging.getLogger(__name__)
@@ -1039,14 +1039,17 @@ def cython_protocol_handler(colparser):
if HAVE_CYTHON:
from cassandra.objparser import ListParser, LazyParser
from cassandra.numpyparser import NumpyParser
ProtocolHandler = cython_protocol_handler(ListParser())
LazyProtocolHandler = cython_protocol_handler(LazyParser())
NumpyProtocolHandler = cython_protocol_handler(NumpyParser())
else:
# Use Python-based ProtocolHandler
LazyProtocolHandler = None
if HAVE_CYTHON and HAVE_NUMPY:
from cassandra.numpyparser import NumpyParser
NumpyProtocolHandler = cython_protocol_handler(NumpyParser())
else:
NumpyProtocolHandler = None

View File

@@ -1,9 +1,4 @@
try:
import tests.unit.cython.dummy_module
except ImportError:
have_cython = False
else:
have_cython = True
from cassandra.cython_deps import HAVE_CYTHON, HAVE_NUMPY
try:
import unittest2 as unittest
@@ -18,10 +13,11 @@ def cyimport(import_path):
try:
return __import__(import_path, fromlist=True)
except ImportError:
if have_cython:
if HAVE_CYTHON:
raise
return None
# @cythontest
# def test_something(self): ...
cythontest = unittest.skipUnless(have_cython, 'Cython is not available')
cythontest = unittest.skipUnless(HAVE_CYTHON, 'Cython is not available')
numpytest = unittest.skipUnless(HAVE_CYTHON and HAVE_NUMPY, 'NumPy is not available')