git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #12826 from NixOS/python-wip

pythonPackages: new functions to build numpy and scipy

commit0806e44f52a05c0274552bebbb29983ca2bfda76 authorFrederik Rietdijk <freddyrietdijk@fridh.nl> dateMon 8 Feb 2016, 20:39 (11 years ago) parente5b143a9123a84
6 files changed+191−108
pkgs/development/libraries/science/math/openblas/0.2.14.nix+65 pkgs/development/python-modules/numpy-scipy-support.nix−35 pkgs/development/python-modules/numpy.nix+51 pkgs/development/python-modules/scipy.nix+47 pkgs/top-level/all-packages.nix+2 pkgs/top-level/python-packages.nix+26−73
pkgs/development/libraries/science/math/openblas/0.2.14.nixnew file+65
@@ -0,0 +1,65 @@
1+{ stdenv, fetchurl, gfortran, perl, which, config, coreutils
2+# Most packages depending on openblas expect integer width to match pointer width,
3+# but some expect to use 32-bit integers always (for compatibility with reference BLAS).
4+, blas64 ? null
5+}:
6+
7+with stdenv.lib;
8+
9+let blas64_ = blas64; in
10+
11+let local = config.openblas.preferLocalBuild or false;
12+ binary =
13+ { i686-linux = "32";
14+ x86_64-linux = "64";
15+ x86_64-darwin = "64";
16+ }."${stdenv.system}" or (throw "unsupported system: ${stdenv.system}");
17+ genericFlags =
18+ [ "DYNAMIC_ARCH=1"
19+ "NUM_THREADS=64"
20+ ];
21+ localFlags = config.openblas.flags or
22+ optionals (hasAttr "target" config.openblas) [ "TARGET=${config.openblas.target}" ];
23+ blas64 = if blas64_ != null then blas64_ else hasPrefix "x86_64" stdenv.system;
24+
25+ version = "0.2.14";
26+in
27+stdenv.mkDerivation {
28+ name = "openblas-${version}";
29+ src = fetchurl {
30+ url = "https://github.com/xianyi/OpenBLAS/archive/v${version}.tar.gz";
31+ sha256 = "2411c4f56f477b42dff54db2b7ffc0b7cf53bb9778d54982595c64cc69c40fc1";
32+ name = "openblas-${version}.tar.gz";
33+ };
34+
35+ inherit blas64;
36+
37+ nativeBuildInputs = optionals stdenv.isDarwin [coreutils] ++ [gfortran perl which];
38+
39+ makeFlags =
40+ (if local then localFlags else genericFlags)
41+ ++
42+ optionals stdenv.isDarwin ["MACOSX_DEPLOYMENT_TARGET=10.9"]
43+ ++
44+ [
45+ "FC=gfortran"
46+ # Note that clang is available through the stdenv on OSX and
47+ # thus is not an explicit dependency.
48+ "CC=${if stdenv.isDarwin then "clang" else "gcc"}"
49+ ''PREFIX="''$(out)"''
50+ "BINARY=${binary}"
51+ "USE_OPENMP=${if stdenv.isDarwin then "0" else "1"}"
52+ "INTERFACE64=${if blas64 then "1" else "0"}"
53+ ];
54+
55+ doCheck = true;
56+ checkTarget = "tests";
57+
58+ meta = with stdenv.lib; {
59+ description = "Basic Linear Algebra Subprograms";
60+ license = licenses.bsd3;
61+ homepage = "https://github.com/xianyi/OpenBLAS";
62+ platforms = platforms.unix;
63+ maintainers = with maintainers; [ ttuegel ];
64+ };
65+}
pkgs/development/python-modules/numpy-scipy-support.nixdeleted−35
@@ -1,35 +0,0 @@
1−{
2− # Python package expression
3− python,
4− # Name of package (e.g. numpy or scipy)
5− pkgName,
6− # OpenBLAS math library
7− openblas
8−}:
9−
10−{
11− # Re-export openblas here so that it can be sure that the same one will be used
12− # in the propagatedBuildInputs.
13− inherit openblas;
14−
15− # First "install" the package, then import what was installed, and call the
16− # .test() function, which will run the test suite.
17− checkPhase = ''
18− runHook preCheck
19− pushd dist
20− ${python.interpreter} -c 'import ${pkgName}; ${pkgName}.test("fast", verbose=10)'
21− popd
22− runHook postCheck
23− '';
24−
25− # Creates a site.cfg telling the setup script where to find depended-on
26− # math libraries.
27− preBuild = ''
28− echo "Creating site.cfg file..."
29− cat << EOF > site.cfg
30− [openblas]
31− include_dirs = ${openblas}/include
32− library_dirs = ${openblas}/lib
33− EOF
34− '';
35−}
pkgs/development/python-modules/numpy.nixnew file+51
@@ -0,0 +1,51 @@
1+{lib, python, buildPythonPackage, isPyPy, gfortran, nose, blas}:
2+
3+args:
4+
5+let
6+ inherit (args) version;
7+in buildPythonPackage (args // rec {
8+
9+ name = "numpy-${version}";
10+
11+ disabled = isPyPy;
12+ buildInputs = args.buildInputs or [ gfortran nose ];
13+ propagatedBuildInputs = args.propagatedBuildInputs or [ passthru.blas ];
14+
15+ preConfigure = ''
16+ sed -i 's/-faltivec//' numpy/distutils/system_info.py
17+ '';
18+
19+ preBuild = ''
20+ echo "Creating site.cfg file..."
21+ cat << EOF > site.cfg
22+ [openblas]
23+ include_dirs = ${passthru.blas}/include
24+ library_dirs = ${passthru.blas}/lib
25+ EOF
26+ '';
27+
28+ checkPhase = ''
29+ runHook preCheck
30+ pushd dist
31+ ${python.interpreter} -c 'import numpy; numpy.test("fast", verbose=10)'
32+ popd
33+ runHook postCheck
34+ '';
35+
36+ passthru = {
37+ blas = blas;
38+ };
39+
40+ # The large file support test is disabled because it takes forever
41+ # and can cause the machine to run out of disk space when run.
42+ prePatch = ''
43+ sed -i 's/test_large_file_support/donttest/' numpy/lib/tests/test_format.py
44+ '';
45+
46+ meta = {
47+ description = "Scientific tools for Python";
48+ homepage = "http://numpy.scipy.org/";
49+ maintainers = with lib.maintainers; [ fridh ];
50+ } // (args.meta or {});
51+})
pkgs/development/python-modules/scipy.nixnew file+47
@@ -0,0 +1,47 @@
1+{lib, python, buildPythonPackage, isPyPy, gfortran, nose}:
2+
3+args:
4+
5+let
6+ inherit (args) version;
7+ inherit (args) numpy;
8+in buildPythonPackage (args // rec {
9+
10+ name = "scipy-${version}";
11+
12+ buildInputs = (args.buildInputs or [ gfortran nose ]);
13+ propagatedBuildInputs = (args.propagatedBuildInputs or [ passthru.blas numpy]);
14+
15+ preConfigure = ''
16+ sed -i '0,/from numpy.distutils.core/s//import setuptools;from numpy.distutils.core/' setup.py
17+ '';
18+
19+ preBuild = ''
20+ echo "Creating site.cfg file..."
21+ cat << EOF > site.cfg
22+ [openblas]
23+ include_dirs = ${passthru.blas}/include
24+ library_dirs = ${passthru.blas}/lib
25+ EOF
26+ '';
27+
28+ checkPhase = ''
29+ runHook preCheck
30+ pushd dist
31+ ${python.interpreter} -c 'import scipy; scipy.test("fast", verbose=10)'
32+ popd
33+ runHook postCheck
34+ '';
35+
36+ passthru = {
37+ blas = numpy.blas;
38+ };
39+
40+ setupPyBuildFlags = [ "--fcompiler='gnu95'" ];
41+
42+ meta = {
43+ description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering. ";
44+ homepage = http://www.scipy.org/;
45+ maintainers = with lib.maintainers; [ fridh ];
46+ } // (args.meta or {});
47+})
pkgs/top-level/all-packages.nix+2
@@ -15029,10 +15029,12 @@ let
1502915029 liblbfgs = callPackage ../development/libraries/science/math/liblbfgs { };
1503015030
1503115031 openblas = callPackage ../development/libraries/science/math/openblas { };
15032+ openblas_2_14 = callPackage ../development/libraries/science/math/openblas/0.2.14.nix { };
1503215033
1503315034 # A version of OpenBLAS using 32-bit integers on all platforms for compatibility with
1503415035 # standard BLAS and LAPACK.
1503515036 openblasCompat = openblas.override { blas64 = false; };
15037+ openblasCompat_2_14 = openblas_2_14.override { blas64 = false; };
1503615038
1503715039 openlibm = callPackage ../development/libraries/science/math/openlibm {};
1503815040
pkgs/top-level/python-packages.nix+26−73
@@ -12505,48 +12505,20 @@ in modules // {
1250512505 };
1250612506 };
1250712507
12508− numpy = let
12509− support = import ../development/python-modules/numpy-scipy-support.nix {
12510− inherit python;
12511− openblas = pkgs.openblasCompat;
12512− pkgName = "numpy";
12513− };
12514− in buildPythonPackage ( rec {
12515− name = "numpy-${version}";
12516− version = "1.10.4";
12508+ buildNumpyPackage = callPackage ../development/python-modules/numpy.nix {
12509+ gfortran = pkgs.gfortran;
12510+ blas = pkgs.openblasCompat_2_14;
12511+ };
12512+
12513+ numpy = self.numpy_1_10;
1251712514
12515+ numpy_1_10 = self.buildNumpyPackage rec {
12516+ version = "1.10.4";
1251812517 src = pkgs.fetchurl {
12519− url = "https://pypi.python.org/packages/source/n/numpy/${name}.tar.gz";
12518+ url = "https://pypi.python.org/packages/source/n/numpy/numpy-${version}.tar.gz";
1252012519 sha256 = "7356e98fbcc529e8d540666f5a919912752e569150e9a4f8d869c686f14c720b";
1252112520 };
12522−
12523− disabled = isPyPy; # WIP
12524−
12525− preConfigure = ''
12526− sed -i 's/-faltivec//' numpy/distutils/system_info.py
12527− '';
12528−
12529− inherit (support) preBuild checkPhase;
12530−
12531− buildInputs = [ pkgs.gfortran self.nose ];
12532− propagatedBuildInputs = [ support.openblas ];
12533−
12534− # Disable failing test_f2py test.
12535− # f2py couldn't be found by test,
12536− # even though it was used successfully to build numpy
12537−
12538− # The large file support test is disabled because it takes forever
12539− # and can cause the machine to run out of disk space when run.
12540− prePatch = ''
12541− sed -i 's/test_f2py/donttest/' numpy/tests/test_scripts.py
12542− sed -i 's/test_large_file_support/donttest/' numpy/lib/tests/test_format.py
12543− '';
12544−
12545− meta = {
12546− description = "Scientific tools for Python";
12547− homepage = "http://numpy.scipy.org/";
12548− };
12549− });
12521+ };
1255012522
1255112523 numpydoc = buildPythonPackage rec {
1255212524 name = "numpydoc-${version}";
@@ -18488,47 +18460,28 @@ in modules // {
1848818460 };
1848918461 };
1849018462
18463+ buildScipyPackage = callPackage ../development/python-modules/scipy.nix {
18464+ gfortran = pkgs.gfortran;
18465+ };
1849118466
18492− scipy = let
18493− support = import ../development/python-modules/numpy-scipy-support.nix {
18494− inherit python;
18495− openblas = pkgs.openblasCompat;
18496− pkgName = "scipy";
18497− };
18498− in buildPythonPackage rec {
18499− name = "scipy-${version}";
18500− version = "0.16.1";
18467+ scipy = self.scipy_0_17;
1850118468
18469+ scipy_0_16 = self.buildScipyPackage rec {
18470+ version = "0.16.1";
1850218471 src = pkgs.fetchurl {
18503− url = "http://pypi.python.org/packages/source/s/scipy/${name}.tar.gz";
18472+ url = "https://pypi.python.org/packages/source/s/scipy/scipy-${version}.tar.gz";
1850418473 sha256 = "ecd1efbb1c038accb0516151d1e6679809c6010288765eb5da6051550bf52260";
1850518474 };
18475+ numpy = self.numpy_1_10;
18476+ };
1850618477
18507− buildInputs = [ pkgs.gfortran self.nose ];
18508− propagatedBuildInputs = [ self.numpy ];
18509−
18510− preConfigure = ''
18511− sed -i '0,/from numpy.distutils.core/s//import setuptools;from numpy.distutils.core/' setup.py
18512− '';
18513−
18514− # First test: RuntimeWarning: Mean of empty slice.
18515− # Second: SyntaxError: invalid syntax. Due to wrapper?
18516− # Third: test checks permissions
18517− prePatch = ''
18518− substituteInPlace scipy/stats/tests/test_stats.py --replace "test_chisquare_masked_arrays" "remove_this_one"
18519− rm scipy/linalg/tests/test_lapack.py
18520− substituteInPlace scipy/weave/tests/test_catalog.py --replace "test_user" "remove_this_one"
18521− '';
18522−
18523− inherit (support) preBuild checkPhase;
18524−
18525− patches = [../development/python-modules/scipy-0.16.1-decorator-fix.patch];
18526− setupPyBuildFlags = [ "--fcompiler='gnu95'" ];
18527−
18528− meta = {
18529− description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering. ";
18530− homepage = http://www.scipy.org/;
18478+ scipy_0_17 = self.buildScipyPackage rec {
18479+ version = "0.17.0";
18480+ src = pkgs.fetchurl {
18481+ url = "https://pypi.python.org/packages/source/s/scipy/scipy-${version}.tar.gz";
18482+ sha256 = "f600b755fb69437d0f70361f9e560ab4d304b1b66987ed5a28bdd9dd7793e089";
1853118483 };
18484+ numpy = self.numpy_1_10;
1853218485 };
1853318486
1853418487 scikitimage = buildPythonPackage rec {
@@ -18563,7 +18516,7 @@ in modules // {
1856318516 };
1856418517
1856518518 buildInputs = with self; [ nose pillow pkgs.gfortran pkgs.glibcLocales ];
18566− propagatedBuildInputs = with self; [ numpy scipy pkgs.openblas ];
18519+ propagatedBuildInputs = with self; [ numpy scipy numpy.blas ];
1856718520
1856818521 LC_ALL="en_US.UTF-8";
1856918522