1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 cryptography,
6 cython,
7 eventlet,
8 fetchFromGitHub,
9 geomet,
10 gevent,
11 gremlinpython,
12 iana-etc,
13 libev,
14 libredirect,
15 pytestCheckHook,
16 pytz,
17 pyyaml,
18 scales,
19 six,
20 sure,
21 twisted,
22 setuptools,
23 distutils,
24 pythonAtLeast,
25}:
26
27buildPythonPackage rec {
28 pname = "cassandra-driver";
29 version = "3.29.2";
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "datastax";
34 repo = "python-driver";
35 tag = version;
36 hash = "sha256-RX9GLk2admzRasmP7LCwIfsJIt8TC/9rWhIcoTqS0qc=";
37 };
38
39 pythonRelaxDeps = [ "geomet" ];
40
41 build-system = [
42 distutils
43 setuptools
44 cython
45 ];
46
47 buildInputs = [ libev ];
48
49 dependencies = [
50 six
51 geomet
52 ];
53
54 nativeCheckInputs = [
55 pytestCheckHook
56 pytz
57 pyyaml
58 sure
59 ]
60 ++ lib.flatten (lib.attrValues optional-dependencies);
61
62 # This is used to determine the version of cython that can be used
63 CASS_DRIVER_ALLOWED_CYTHON_VERSION = cython.version;
64
65 # Make /etc/protocols accessible to allow socket.getprotobyname('tcp') in sandbox,
66 # also /etc/resolv.conf is referenced by some tests
67 preCheck =
68 (lib.optionalString stdenv.hostPlatform.isLinux ''
69 echo "nameserver 127.0.0.1" > resolv.conf
70 export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocols:/etc/resolv.conf=$(realpath resolv.conf)
71 export LD_PRELOAD=${libredirect}/lib/libredirect.so
72 '')
73 + ''
74 # increase tolerance for time-based test
75 substituteInPlace tests/unit/io/utils.py --replace 'delta=.15' 'delta=.3'
76
77 export HOME=$(mktemp -d)
78 # cythonize this before we hide the source dir as it references
79 # one of its files
80 cythonize -i tests/unit/cython/types_testhelper.pyx
81
82 mv cassandra .cassandra.hidden
83 '';
84
85 pythonImportsCheck = [ "cassandra" ];
86
87 postCheck = ''
88 unset NIX_REDIRECTS LD_PRELOAD
89 '';
90
91 enabledTestPaths = [ "tests/unit" ];
92
93 disabledTestPaths = [
94 # requires puresasl
95 "tests/unit/advanced/test_auth.py"
96 # Uses asyncore, which is deprecated in python 3.12+
97 "tests/unit/io/test_asyncorereactor.py"
98 ];
99
100 disabledTests = [
101 # doesn't seem to be intended to be run directly
102 "_PoolTests"
103 # attempts to make connection to localhost
104 "test_connection_initialization"
105 # time-sensitive
106 "test_nts_token_performance"
107 ];
108
109 optional-dependencies = {
110 cle = [ cryptography ];
111 eventlet = [ eventlet ];
112 gevent = [ gevent ];
113 graph = [ gremlinpython ];
114 metrics = [ scales ];
115 twisted = [ twisted ];
116 };
117
118 meta = {
119 # cassandra/io/libevwrapper.c:668:10: error: implicit declaration of function ‘PyEval_ThreadsInitialized’ []
120 broken = pythonAtLeast "3.13";
121 description = "Python client driver for Apache Cassandra";
122 homepage = "http://datastax.github.io/python-driver";
123 changelog = "https://github.com/datastax/python-driver/blob/${version}/CHANGELOG.rst";
124 license = lib.licenses.asl20;
125 maintainers = with lib.maintainers; [ ris ];
126 };
127}