1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 rustPlatform,
7 cmake,
8 libiconv,
9 fetchFromGitHub,
10 typing-extensions,
11 jemalloc,
12 rust-jemalloc-sys,
13 darwin,
14}:
15
16let
17 rust-jemalloc-sys' = rust-jemalloc-sys.override {
18 jemalloc = jemalloc.override { disableInitExecTls = true; };
19 };
20in
21
22buildPythonPackage rec {
23 pname = "polars";
24 version = "0.20.15";
25 pyproject = true;
26
27 disabled = pythonOlder "3.8";
28
29 src = fetchFromGitHub {
30 owner = "pola-rs";
31 repo = "polars";
32 rev = "refs/tags/py-${version}";
33 hash = "sha256-N/VIi0s5unYWqlR5Mpaq9cqXl2ccbzWPuOtE2UbmQw8=";
34 };
35
36 # Cargo.lock file is sometimes behind actual release which throws an error,
37 # thus the `sed` command
38 # Make sure to check that the right substitutions are made when updating the package
39 preBuild = ''
40 #sed -i 's/version = "0.18.0"/version = "${version}"/g' Cargo.lock
41 '';
42
43 cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
44
45 buildAndTestSubdir = "py-polars";
46
47 # Revisit this whenever package or Rust is upgraded
48 RUSTC_BOOTSTRAP = 1;
49
50 propagatedBuildInputs = lib.optionals (pythonOlder "3.11") [ typing-extensions ];
51
52 # trick taken from the polars repo since there seems to be a problem
53 # with simd enabled with our stable rust (instead of nightly).
54 maturinBuildFlags = [
55 "--no-default-features"
56 "--features=all"
57 ];
58
59 dontUseCmakeConfigure = true;
60
61 nativeBuildInputs =
62 [
63 # needed for libz-ng-sys
64 # TODO: use pkgs.zlib-ng
65 cmake
66 ]
67 ++ (with rustPlatform; [
68 cargoSetupHook
69 maturinBuildHook
70 ]);
71
72 buildInputs =
73 [ rust-jemalloc-sys' ]
74 ++ lib.optionals stdenv.isDarwin [
75 libiconv
76 darwin.apple_sdk.frameworks.Security
77 darwin.apple_sdk.frameworks.SystemConfiguration
78 ];
79
80 # nativeCheckInputs = [
81 # pytestCheckHook
82 # fixtures
83 # graphviz
84 # matplotlib
85 # networkx
86 # numpy
87 # pydot
88 # ];
89
90 pythonImportsCheck = [ "polars" ];
91
92 meta = with lib; {
93 description = "Fast multi-threaded DataFrame library";
94 homepage = "https://github.com/pola-rs/polars";
95 changelog = "https://github.com/pola-rs/polars/releases/tag/py-${version}";
96 license = licenses.asl20;
97 maintainers = with maintainers; [ happysalada ];
98 };
99}