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