about summary refs log tree commit diff
path: root/pkgs/development/python-modules/lightgbm/default.nix
blob: 2b7e33347c945673413eb2bc092a2e033a61b9b1 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
  lib,
  config,
  stdenv,
  buildPythonPackage,
  fetchPypi,

  # build-system
  cmake,
  ninja,
  pathspec,
  pyproject-metadata,
  scikit-build-core,

  # dependencies
  llvmPackages,
  numpy,
  scipy,
  pythonOlder,

  # optionals
  cffi,
  dask,
  pandas,
  pyarrow,
  scikit-learn,

  # optionals: gpu
  boost,
  ocl-icd,
  opencl-headers,
  gpuSupport ? stdenv.isLinux && !cudaSupport,
  cudaSupport ? config.cudaSupport,
  cudaPackages,
}:

assert gpuSupport -> cudaSupport != true;
assert cudaSupport -> gpuSupport != true;

buildPythonPackage rec {
  pname = "lightgbm";
  version = "4.3.0";
  pyproject = true;

  disabled = pythonOlder "3.7";

  src = fetchPypi {
    inherit pname version;
    hash = "sha256-AG9XhKm87kPlp+lD3E8C3hui7np68e5fGQ04Pztsnr4=";
  };

  nativeBuildInputs = [
    cmake
    ninja
    pathspec
    pyproject-metadata
    scikit-build-core
  ] ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ];

  dontUseCmakeConfigure = true;

  buildInputs =
    (lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ])
    ++ (lib.optionals gpuSupport [
      boost
      ocl-icd
      opencl-headers
    ])
    ++ lib.optionals cudaSupport [
      cudaPackages.cuda_nvcc
      cudaPackages.cuda_cudart
    ];

  propagatedBuildInputs = [
    numpy
    scipy
  ];

  pypaBuildFlags =
    lib.optionals gpuSupport [ "--config-setting=cmake.define.USE_GPU=ON" ]
    ++ lib.optionals cudaSupport [ "--config-setting=cmake.define.USE_CUDA=ON" ];

  postConfigure = ''
    export HOME=$(mktemp -d)
  '';

  passthru.optional-dependencies = {
    arrow = [
      cffi
      pyarrow
    ];
    dask =
      [
        dask
        pandas
      ]
      ++ dask.optional-dependencies.array
      ++ dask.optional-dependencies.dataframe
      ++ dask.optional-dependencies.distributed;
    pandas = [ pandas ];
    scikit-learn = [ scikit-learn ];
  };

  # The pypi package doesn't distribute the tests from the GitHub
  # repository. It contains c++ tests which don't seem to wired up to
  # `make check`.
  doCheck = false;

  pythonImportsCheck = [ "lightgbm" ];

  meta = {
    description = "Fast, distributed, high performance gradient boosting (GBDT, GBRT, GBM or MART) framework";
    homepage = "https://github.com/Microsoft/LightGBM";
    changelog = "https://github.com/microsoft/LightGBM/releases/tag/v${version}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ teh ];
  };
}