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