summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/xgboost/default.nix
blob: 150b7fb45f06f7d365a6e2fda5c5d1d3066f36b1 (plain)
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
{
  buildPythonPackage,
  cmake,
  numpy,
  scipy,
  hatchling,
  python,
  stdenv,
  xgboost,
}:

let
  libExtension = stdenv.hostPlatform.extensions.sharedLibrary;
  libName = "libxgboost${libExtension}";
  libPath = "${xgboost}/lib/${libName}";
in
buildPythonPackage {
  pname = "xgboost";
  pyproject = true;
  inherit (xgboost) version src meta;

  nativeBuildInputs = [
    cmake
    hatchling
  ];
  buildInputs = [ xgboost ];
  propagatedBuildInputs = [
    numpy
    scipy
  ];

  pythonRemoveDeps = [
    "nvidia-nccl-cu12"
  ];

  # Place libxgboost.so where the build will look for it
  # to avoid triggering the compilation of the library
  prePatch = ''
    mkdir -p lib
    ln -s ${libPath} lib/
  '';

  dontUseCmakeConfigure = true;

  postPatch = ''
    cd python-package
  '';

  # test setup tries to download test data with no option to disable
  # (removing sklearn from nativeCheckInputs causes all previously enabled tests to be skipped)
  # and are extremely cpu intensive anyway
  doCheck = false;

  # During the build libxgboost.so is copied to its current location
  # Replacing it with a symlink to the original
  postInstall =
    let
      libOutPath = "$out/${python.sitePackages}/xgboost/lib/${libName}";
    in
    ''
      rm "${libOutPath}"
      ln -s "${libPath}" "${libOutPath}"
    '';

  pythonImportsCheck = [ "xgboost" ];

  __darwinAllowLocalNetworking = true;
}