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 BUILD_HTTPFS = 1;
42 DUCKDB_BUILD_UNITY = 1;
43 OVERRIDE_GIT_DESCRIBE = "v${version}-0-g${rev}";
44 };
45
46 nativeBuildInputs = [
47 pybind11
48 setuptools-scm
49 ];
50
51 buildInputs = [ openssl ];
52
53 propagatedBuildInputs = [
54 numpy
55 pandas
56 ];
57
58 nativeCheckInputs = [
59 fsspec
60 google-cloud-storage
61 psutil
62 pytestCheckHook
63 ];
64
65 # test flags from .github/workflows/Python.yml
66 pytestFlagsArray = [ "--verbose" ] ++ lib.optionals stdenv.isDarwin [ "tests/fast" ];
67
68 disabledTestPaths = [
69 # avoid dependency on mypy
70 "tests/stubs/test_stubs.py"
71 ];
72
73 disabledTests = [
74 # tries to make http request
75 "test_install_non_existent_extension"
76
77 # test is flaky https://github.com/duckdb/duckdb/issues/11961
78 "test_fetchmany"
79
80 # https://github.com/duckdb/duckdb/issues/10702
81 # tests are racy and interrupt can be delivered before or after target point
82 # causing a later test to fail with a spurious KeyboardInterrupt
83 "test_connection_interrupt"
84 "test_query_interruption"
85 ];
86
87 # remove duckdb dir to prevent import confusion by pytest
88 preCheck = ''
89 export HOME="$(mktemp -d)"
90 rm -rf duckdb
91 '';
92
93 pythonImportsCheck = [ "duckdb" ];
94
95 meta = with lib; {
96 description = "Python binding for DuckDB";
97 homepage = "https://duckdb.org/";
98 license = licenses.mit;
99 maintainers = with maintainers; [ cpcloud ];
100 };
101}