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