1{ lib
2, fetchPypi
3, python
4, buildPythonPackage
5, gfortran
6, pytest
7, blas
8, writeTextFile
9, isPyPy
10, cython
11, setuptoolsBuildHook
12 }:
13
14let
15 blasImplementation = lib.nameFromURL blas.name "-";
16 cfg = writeTextFile {
17 name = "site.cfg";
18 text = (lib.generators.toINI {} {
19 ${blasImplementation} = {
20 include_dirs = "${blas}/include";
21 library_dirs = "${blas}/lib";
22 } // lib.optionalAttrs (blasImplementation == "mkl") {
23 mkl_libs = "mkl_rt";
24 lapack_libs = "";
25 };
26 });
27 };
28in buildPythonPackage rec {
29 pname = "numpy";
30 version = "1.18.1";
31 format = "pyproject.toml";
32
33 src = fetchPypi {
34 inherit pname version;
35 extension = "zip";
36 sha256 = "b6ff59cee96b454516e47e7721098e6ceebef435e3e21ac2d6c3b8b02628eb77";
37 };
38
39 nativeBuildInputs = [ gfortran pytest cython setuptoolsBuildHook ];
40 buildInputs = [ blas ];
41
42 patches = lib.optionals python.hasDistutilsCxxPatch [
43 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585
44 # Patching of numpy.distutils is needed to prevent it from undoing the
45 # patch to distutils.
46 ./numpy-distutils-C++.patch
47 ];
48
49 preConfigure = ''
50 sed -i 's/-faltivec//' numpy/distutils/system_info.py
51 export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES
52 '';
53
54 preBuild = ''
55 ln -s ${cfg} site.cfg
56 '';
57
58 enableParallelBuilding = true;
59
60 doCheck = !isPyPy; # numpy 1.16+ hits a bug in pypy's ctypes, using either numpy or pypy HEAD fixes this (https://github.com/numpy/numpy/issues/13807)
61
62 checkPhase = ''
63 runHook preCheck
64 pushd dist
65 ${python.interpreter} -c 'import numpy; numpy.test("fast", verbose=10)'
66 popd
67 runHook postCheck
68 '';
69
70 passthru = {
71 blas = blas;
72 inherit blasImplementation cfg;
73 };
74
75 # Disable test
76 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space
77 NOSE_EXCLUDE="test_large_file_support";
78
79 meta = {
80 description = "Scientific tools for Python";
81 homepage = https://numpy.org/;
82 maintainers = with lib.maintainers; [ fridh ];
83 };
84}