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