Be more careful when Cython is available but NumPy is not
This commit is contained in:
@@ -2,4 +2,10 @@ try:
|
|||||||
from cassandra.rowparser import make_recv_results_rows
|
from cassandra.rowparser import make_recv_results_rows
|
||||||
HAVE_CYTHON = True
|
HAVE_CYTHON = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAVE_CYTHON = False
|
HAVE_CYTHON = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
import numpy
|
||||||
|
HAVE_NUMPY = True
|
||||||
|
except ImportError:
|
||||||
|
HAVE_NUMPY = False
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ from cassandra.cqltypes import (AsciiType, BytesType, BooleanType,
|
|||||||
TupleType, lookup_casstype, SimpleDateType,
|
TupleType, lookup_casstype, SimpleDateType,
|
||||||
TimeType, ByteType, ShortType)
|
TimeType, ByteType, ShortType)
|
||||||
from cassandra.policies import WriteType
|
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
|
from cassandra import util
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -1039,14 +1039,17 @@ def cython_protocol_handler(colparser):
|
|||||||
|
|
||||||
if HAVE_CYTHON:
|
if HAVE_CYTHON:
|
||||||
from cassandra.objparser import ListParser, LazyParser
|
from cassandra.objparser import ListParser, LazyParser
|
||||||
from cassandra.numpyparser import NumpyParser
|
|
||||||
|
|
||||||
ProtocolHandler = cython_protocol_handler(ListParser())
|
ProtocolHandler = cython_protocol_handler(ListParser())
|
||||||
LazyProtocolHandler = cython_protocol_handler(LazyParser())
|
LazyProtocolHandler = cython_protocol_handler(LazyParser())
|
||||||
NumpyProtocolHandler = cython_protocol_handler(NumpyParser())
|
|
||||||
else:
|
else:
|
||||||
# Use Python-based ProtocolHandler
|
# Use Python-based ProtocolHandler
|
||||||
LazyProtocolHandler = None
|
LazyProtocolHandler = None
|
||||||
|
|
||||||
|
|
||||||
|
if HAVE_CYTHON and HAVE_NUMPY:
|
||||||
|
from cassandra.numpyparser import NumpyParser
|
||||||
|
NumpyProtocolHandler = cython_protocol_handler(NumpyParser())
|
||||||
|
else:
|
||||||
NumpyProtocolHandler = None
|
NumpyProtocolHandler = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
try:
|
from cassandra.cython_deps import HAVE_CYTHON, HAVE_NUMPY
|
||||||
import tests.unit.cython.dummy_module
|
|
||||||
except ImportError:
|
|
||||||
have_cython = False
|
|
||||||
else:
|
|
||||||
have_cython = True
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
@@ -18,10 +13,11 @@ def cyimport(import_path):
|
|||||||
try:
|
try:
|
||||||
return __import__(import_path, fromlist=True)
|
return __import__(import_path, fromlist=True)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if have_cython:
|
if HAVE_CYTHON:
|
||||||
raise
|
raise
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# @cythontest
|
# @cythontest
|
||||||
# def test_something(self): ...
|
# 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')
|
||||||
Reference in New Issue
Block a user