summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/xnd/default.nix
blob: e3145bacc53952575c8adf387d8150944175b88b (about) (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
{
  lib,
  stdenv,
  buildPythonPackage,
  libxnd,
  setuptools,
  ndtypes,
  libndtypes,
  pythonAtLeast,
  python,
}:

buildPythonPackage {
  pname = "xnd";
  inherit (libxnd) version src meta;
  pyproject = true;

  build-system = [ setuptools ];

  dependencies = [ ndtypes ];

  buildInputs = [ libndtypes ];

  postPatch =
    ''
      substituteInPlace setup.py \
        --replace-fail \
          'include_dirs = ["libxnd", "ndtypes/python/ndtypes"] + INCLUDES' \
          'include_dirs = ["${libndtypes}/include", "${ndtypes}/include", "${libxnd}/include"]' \
        --replace-fail \
          'library_dirs = ["libxnd", "ndtypes/libndtypes"] + LIBS' \
          'library_dirs = ["${libndtypes}/lib", "${libxnd}/lib"]' \
        --replace-fail \
          'runtime_library_dirs = ["$ORIGIN"]' \
          'runtime_library_dirs = ["${libndtypes}/lib", "${libxnd}/lib"]'
    ''
    + lib.optionalString (pythonAtLeast "3.12") ''
      substituteInPlace python/xnd/util.h \
        --replace-fail '->ob_digit[i]' '->long_value.ob_digit[i]'
    '';

  postInstall =
    ''
      mkdir $out/include
      cp python/xnd/*.h $out/include
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      install_name_tool -add_rpath ${libxnd}/lib $out/${python.sitePackages}/xnd/_xnd.*.so
    '';

  checkPhase = ''
    runHook preCheck

    pushd python
    mv xnd _xnd
    python test_xnd.py
    popd

    runHook postCheck
  '';
}