nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 cmake,
7 ninja,
8 duckdb,
9 fsspec,
10 google-cloud-storage,
11 ipython,
12 numpy,
13 openssl,
14 pandas,
15 psutil,
16 pyarrow,
17 pybind11,
18 pytz,
19 scikit-build-core,
20 setuptools-scm,
21 pytest-reraise,
22 pytestCheckHook,
23}:
24
25buildPythonPackage rec {
26 inherit (duckdb)
27 pname
28 version # nixpkgs-update: no auto update
29 ;
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "duckdb";
34 repo = "duckdb-python";
35 tag = "v${version}";
36 hash = duckdb.passthru.pythonHash;
37 };
38
39 postPatch = ''
40 # The build depends on a duckdb git submodule
41 rm -r external/duckdb
42 ln -s ${duckdb.src} external/duckdb
43
44 # replace pybind11[global] with pybind11
45 substituteInPlace pyproject.toml \
46 --replace-fail "pybind11[global]" "pybind11"
47
48 # replace custom build backend with standard scikit-build-core
49 substituteInPlace pyproject.toml \
50 --replace-fail 'build-backend = "duckdb_packaging.build_backend"' \
51 'build-backend = "scikit_build_core.build"' \
52 --replace-fail 'backend-path = ["./"]' \
53 '# backend-path removed'
54 '';
55
56 nativeBuildInputs = [
57 cmake
58 ninja
59 ];
60
61 dontUseCmakeConfigure = true;
62
63 build-system = [
64 pybind11
65 scikit-build-core
66 setuptools-scm
67 ];
68
69 buildInputs = [
70 duckdb
71 openssl
72 ];
73
74 optional-dependencies = {
75 all = [
76 # FIXME package adbc_driver_manager
77 ipython
78 fsspec
79 numpy
80 pandas
81 pyarrow
82 ];
83 };
84
85 env = {
86 DUCKDB_BUILD_UNITY = 1;
87 # default to disabled extension autoload/autoinstall
88 CMAKE_DEFINE_DUCKDB_EXTENSION_AUTOLOAD_DEFAULT = "0";
89 CMAKE_DEFINE_DUCKDB_EXTENSION_AUTOINSTALL_DEFAULT = "0";
90 };
91
92 cmakeFlags = [
93 (lib.cmakeFeature "OVERRIDE_GIT_DESCRIBE" "v${version}-0-g${duckdb.rev}")
94 ];
95
96 nativeCheckInputs = [
97 fsspec
98 google-cloud-storage
99 psutil
100 pytest-reraise
101 pytestCheckHook
102 pytz
103 ]
104 ++ optional-dependencies.all;
105
106 # test flags from .github/workflows/Python.yml
107 pytestFlags = [ "--verbose" ];
108 enabledTestPaths = if stdenv.hostPlatform.isDarwin then [ "tests/fast" ] else [ "tests" ];
109
110 disabledTestPaths = [
111 # avoid dependency on adbc_driver_manager
112 "tests/fast/adbc"
113 # avoid dependency on pyotp
114 "tests/fast/test_pypi_cleanup.py"
115 # avoid test data download requiring network access
116 "tests/slow/test_h2oai_arrow.py"
117 ];
118
119 disabledTests = [
120 # tries to make http request
121 "test_install_non_existent_extension"
122
123 # test is flaky https://github.com/duckdb/duckdb/issues/11961
124 "test_fetchmany"
125
126 # https://github.com/duckdb/duckdb/issues/10702
127 # tests are racy and interrupt can be delivered before or after target point
128 # causing a later test to fail with a spurious KeyboardInterrupt
129 "test_connection_interrupt"
130 "test_query_interruption"
131
132 # flaky due to a race condition in checking whether a thread is alive
133 "test_query_progress"
134 ];
135
136 # remove duckdb dir to prevent import confusion by pytest
137 preCheck = ''
138 export HOME="$(mktemp -d)"
139 rm -rf duckdb
140 '';
141
142 pythonImportsCheck = [ "duckdb" ];
143
144 meta = {
145 description = "Python binding for DuckDB";
146 homepage = "https://duckdb.org/";
147 license = lib.licenses.mit;
148 maintainers = with lib.maintainers; [ cpcloud ];
149 };
150}