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 substituteInPlace setup.py \
26 --replace-fail \
27 'include_dirs = ["libxnd", "ndtypes/python/ndtypes"] + INCLUDES' \
28 'include_dirs = ["${libndtypes}/include", "${ndtypes}/include", "${libxnd}/include"]' \
29 --replace-fail \
30 'library_dirs = ["libxnd", "ndtypes/libndtypes"] + LIBS' \
31 'library_dirs = ["${libndtypes}/lib", "${libxnd}/lib"]' \
32 --replace-fail \
33 'runtime_library_dirs = ["$ORIGIN"]' \
34 'runtime_library_dirs = ["${libndtypes}/lib", "${libxnd}/lib"]'
35 ''
36 + lib.optionalString (pythonAtLeast "3.12") ''
37 substituteInPlace python/xnd/util.h \
38 --replace-fail '->ob_digit[i]' '->long_value.ob_digit[i]'
39 '';
40
41 postInstall = ''
42 mkdir $out/include
43 cp python/xnd/*.h $out/include
44 ''
45 + lib.optionalString stdenv.hostPlatform.isDarwin ''
46 install_name_tool -add_rpath ${libxnd}/lib $out/${python.sitePackages}/xnd/_xnd.*.so
47 '';
48
49 checkPhase = ''
50 runHook preCheck
51
52 pushd python
53 mv xnd _xnd
54 python test_xnd.py
55 popd
56
57 runHook postCheck
58 '';
59}