1{
2 lib,
3 config,
4 stdenv,
5 buildPythonPackage,
6 fetchPypi,
7
8 # build-system
9 cmake,
10 ninja,
11 pathspec,
12 pyproject-metadata,
13 scikit-build-core,
14
15 # dependencies
16 llvmPackages,
17 numpy,
18 scipy,
19 pythonOlder,
20
21 # optionals
22 cffi,
23 dask,
24 pandas,
25 pyarrow,
26 scikit-learn,
27
28 # optionals: gpu
29 boost,
30 ocl-icd,
31 opencl-headers,
32 gpuSupport ? stdenv.isLinux && !cudaSupport,
33 cudaSupport ? config.cudaSupport,
34 cudaPackages,
35}:
36
37assert gpuSupport -> cudaSupport != true;
38assert cudaSupport -> gpuSupport != true;
39
40buildPythonPackage rec {
41 pname = "lightgbm";
42 version = "4.3.0";
43 pyproject = true;
44
45 disabled = pythonOlder "3.7";
46
47 src = fetchPypi {
48 inherit pname version;
49 hash = "sha256-AG9XhKm87kPlp+lD3E8C3hui7np68e5fGQ04Pztsnr4=";
50 };
51
52 nativeBuildInputs = [
53 cmake
54 ninja
55 pathspec
56 pyproject-metadata
57 scikit-build-core
58 ] ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ];
59
60 dontUseCmakeConfigure = true;
61
62 buildInputs =
63 (lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ])
64 ++ (lib.optionals gpuSupport [
65 boost
66 ocl-icd
67 opencl-headers
68 ])
69 ++ lib.optionals cudaSupport [
70 cudaPackages.cuda_nvcc
71 cudaPackages.cuda_cudart
72 ];
73
74 propagatedBuildInputs = [
75 numpy
76 scipy
77 ];
78
79 pypaBuildFlags =
80 lib.optionals gpuSupport [ "--config-setting=cmake.define.USE_GPU=ON" ]
81 ++ lib.optionals cudaSupport [ "--config-setting=cmake.define.USE_CUDA=ON" ];
82
83 postConfigure = ''
84 export HOME=$(mktemp -d)
85 '';
86
87 passthru.optional-dependencies = {
88 arrow = [
89 cffi
90 pyarrow
91 ];
92 dask =
93 [
94 dask
95 pandas
96 ]
97 ++ dask.optional-dependencies.array
98 ++ dask.optional-dependencies.dataframe
99 ++ dask.optional-dependencies.distributed;
100 pandas = [ pandas ];
101 scikit-learn = [ scikit-learn ];
102 };
103
104 # The pypi package doesn't distribute the tests from the GitHub
105 # repository. It contains c++ tests which don't seem to wired up to
106 # `make check`.
107 doCheck = false;
108
109 pythonImportsCheck = [ "lightgbm" ];
110
111 meta = {
112 description = "A fast, distributed, high performance gradient boosting (GBDT, GBRT, GBM or MART) framework";
113 homepage = "https://github.com/Microsoft/LightGBM";
114 changelog = "https://github.com/microsoft/LightGBM/releases/tag/v${version}";
115 license = lib.licenses.mit;
116 maintainers = with lib.maintainers; [ teh ];
117 };
118}