summary refs log tree commit diff
path: root/pkgs/development/python-modules/datafusion/default.nix
blob: 4b36df22d1838037de401b7c0ce86f83cf2bf0cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{ lib
, stdenv
, fetchurl
, buildPythonPackage
, fetchPypi
, fetchFromGitHub
, rustPlatform
, maturin
, pytestCheckHook
, libiconv
, numpy
, pandas
, pyarrow
, pytest
}:
let
  # le sigh, the perils of unrelated versions of software living in the same
  # repo: there's no obvious way to map the top level source repo
  # (arrow-datafusion) version to the version of contained repo
  # (arrow-datafusion/python)
  #
  # A commit hash will do in a pinch, and ultimately the sha256 has the final
  # say of what the content is when building
  cargoLock = fetchurl {
    url = "https://raw.githubusercontent.com/apache/arrow-datafusion/6.0.0/python/Cargo.lock";
    sha256 = "sha256-xiv3drEU5jOGsEIh0U01ZQ1NBKobxO2ctp4mxy9iigw=";
  };

  postUnpack = ''
    cp "${cargoLock}" $sourceRoot/Cargo.lock
    chmod u+w $sourceRoot/Cargo.lock
  '';
in
buildPythonPackage rec {
  pname = "datafusion";
  version = "0.4.0";
  format = "pyproject";

  src = fetchPypi {
    inherit pname version;
    sha256 = "sha256-+YqogteKfNhtI2QbVXv/5CIWm3PcOH653dwONm5ZcL8=";
  };

  inherit postUnpack;

  # TODO: remove the patch hacking and postUnpack hooks after
  # https://github.com/apache/arrow-datafusion/pull/1508 is merged
  #
  # the lock file isn't up to date as of 6.0.0 so we need to patch the source
  # lockfile and the vendored cargo deps lockfile
  patches = [ ./Cargo.lock.patch ];
  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src pname version postUnpack;
    sha256 = "sha256-JGyDxpfBXzduJaMF1sbmRm7KJajHYdVSj+WbiSETiY0=";
    patches = [ ./Cargo.lock.patch ];
  };

  nativeBuildInputs = with rustPlatform; [
    cargoSetupHook
    maturinBuildHook
  ];

  buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];

  propagatedBuildInputs = [
    numpy
    pandas
    pyarrow
  ];

  checkInputs = [ pytest ];
  pythonImportsCheck = [ "datafusion" ];

  checkPhase = ''
    runHook preCheck
    pytest --pyargs "${pname}"
    runHook postCheck
  '';

  meta = with lib; {
    description = "Extensible query execution framework";
    longDescription = ''
      DataFusion is an extensible query execution framework, written in Rust,
      that uses Apache Arrow as its in-memory format.
    '';
    homepage = "https://arrow.apache.org/datafusion/";
    license = with licenses; [ asl20 ];
    maintainers = with maintainers; [ cpcloud ];
  };
}