1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 duckdb,
6 fsspec,
7 google-cloud-storage,
8 numpy,
9 openssl,
10 pandas,
11 psutil,
12 pybind11,
13 setuptools-scm,
14 pytest-reraise,
15 pytestCheckHook,
16}:
17
18buildPythonPackage rec {
19 inherit (duckdb)
20 patches
21 pname
22 rev
23 src
24 version
25 ;
26 pyproject = true;
27
28 postPatch = (duckdb.postPatch or "") + ''
29 # we can't use sourceRoot otherwise patches don't apply, because the patches apply to the C++ library
30 cd tools/pythonpkg
31
32 # 1. let nix control build cores
33 # 2. default to extension autoload & autoinstall disabled
34 substituteInPlace setup.py \
35 --replace-fail "ParallelCompile()" 'ParallelCompile("NIX_BUILD_CORES")' \
36 --replace-fail "define_macros.extend([('DUCKDB_EXTENSION_AUTOLOAD_DEFAULT', '1'), ('DUCKDB_EXTENSION_AUTOINSTALL_DEFAULT', '1')])" "pass"
37
38 substituteInPlace pyproject.toml \
39 --replace-fail 'setuptools_scm>=6.4,<8.0' 'setuptools_scm'
40 '';
41
42 env = {
43 DUCKDB_BUILD_UNITY = 1;
44 OVERRIDE_GIT_DESCRIBE = "v${version}-0-g${rev}";
45 };
46
47 build-system = [
48 pybind11
49 setuptools-scm
50 ];
51
52 buildInputs = [ openssl ];
53
54 dependencies = [
55 numpy
56 pandas
57 ];
58
59 nativeCheckInputs = [
60 fsspec
61 google-cloud-storage
62 psutil
63 pytest-reraise
64 pytestCheckHook
65 ];
66
67 pytestFlags = [ "--verbose" ];
68
69 # test flags from .github/workflows/Python.yml
70 pytestFlagsArray = [ "--verbose" ];
71 enabledTestPaths = if stdenv.hostPlatform.isDarwin then [ "tests/fast" ] else [ "tests" ];
72
73 disabledTestPaths = [
74 # avoid dependency on mypy
75 "tests/stubs/test_stubs.py"
76 ];
77
78 disabledTests = [
79 # tries to make http request
80 "test_install_non_existent_extension"
81
82 # test is flaky https://github.com/duckdb/duckdb/issues/11961
83 "test_fetchmany"
84
85 # https://github.com/duckdb/duckdb/issues/10702
86 # tests are racy and interrupt can be delivered before or after target point
87 # causing a later test to fail with a spurious KeyboardInterrupt
88 "test_connection_interrupt"
89 "test_query_interruption"
90 ];
91
92 # remove duckdb dir to prevent import confusion by pytest
93 preCheck = ''
94 export HOME="$(mktemp -d)"
95 rm -rf duckdb
96 '';
97
98 pythonImportsCheck = [ "duckdb" ];
99
100 meta = with lib; {
101 description = "Python binding for DuckDB";
102 homepage = "https://duckdb.org/";
103 license = licenses.mit;
104 maintainers = with maintainers; [ cpcloud ];
105 };
106}