1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 libxnd,
6 setuptools,
7 ndtypes,
8 libndtypes,
9 pythonAtLeast,
10 python,
11}:
12
13buildPythonPackage {
14 pname = "xnd";
15 inherit (libxnd) version src meta;
16 pyproject = true;
17
18 build-system = [ setuptools ];
19
20 dependencies = [ ndtypes ];
21
22 buildInputs = [ libndtypes ];
23
24 postPatch =
25 ''
26 substituteInPlace setup.py \
27 --replace-fail \
28 'include_dirs = ["libxnd", "ndtypes/python/ndtypes"] + INCLUDES' \
29 'include_dirs = ["${libndtypes}/include", "${ndtypes}/include", "${libxnd}/include"]' \
30 --replace-fail \
31 'library_dirs = ["libxnd", "ndtypes/libndtypes"] + LIBS' \
32 'library_dirs = ["${libndtypes}/lib", "${libxnd}/lib"]' \
33 --replace-fail \
34 'runtime_library_dirs = ["$ORIGIN"]' \
35 'runtime_library_dirs = ["${libndtypes}/lib", "${libxnd}/lib"]'
36 ''
37 + lib.optionalString (pythonAtLeast "3.12") ''
38 substituteInPlace python/xnd/util.h \
39 --replace-fail '->ob_digit[i]' '->long_value.ob_digit[i]'
40 '';
41
42 postInstall =
43 ''
44 mkdir $out/include
45 cp python/xnd/*.h $out/include
46 ''
47 + lib.optionalString stdenv.hostPlatform.isDarwin ''
48 install_name_tool -add_rpath ${libxnd}/lib $out/${python.sitePackages}/xnd/_xnd.*.so
49 '';
50
51 checkPhase = ''
52 runHook preCheck
53
54 pushd python
55 mv xnd _xnd
56 python test_xnd.py
57 popd
58
59 runHook postCheck
60 '';
61}