1{ stdenv
2, runCommandCC
3, fetchPypi
4, buildPythonPackage
5, isPyPy
6, pythonOlder
7, isPy3k
8, nose
9, numpy
10, scipy
11, six
12, libgpuarray
13, libredirect
14, cudaSupport ? false, cudatoolkit
15, cudnnSupport ? false, cudnn
16, nvidia_x11
17}:
18
19assert cudnnSupport -> cudaSupport;
20
21assert cudaSupport -> nvidia_x11 != null
22 && cudatoolkit != null
23 && cudnn != null;
24
25let
26 wrapped = command: buildTop: buildInputs:
27 runCommandCC "${command}-wrapped" { inherit buildInputs; } ''
28 type -P '${command}' || { echo '${command}: not found'; exit 1; }
29 cat > "$out" <<EOF
30 #!$(type -P bash)
31 $(declare -xp | sed -e '/^[^=]\+="\('"''${NIX_STORE//\//\\/}"'\|[^\/]\)/!d')
32 declare -x NIX_BUILD_TOP="${buildTop}"
33 $(type -P '${command}') "\$@"
34 EOF
35 chmod +x "$out"
36 '';
37
38 # Theano spews warnings and disabled flags if the compiler isn't named g++
39 cxx_compiler_name =
40 if stdenv.cc.isGNU then "g++" else
41 if stdenv.cc.isClang then "clang++" else
42 throw "Unknown C++ compiler";
43 cxx_compiler = wrapped cxx_compiler_name "\\$HOME/.theano"
44 ( stdenv.lib.optional cudaSupport libgpuarray_
45 ++ stdenv.lib.optional cudnnSupport cudnn );
46
47 libgpuarray_ = libgpuarray.override { inherit cudaSupport cudatoolkit; };
48
49in buildPythonPackage rec {
50 pname = "Theano";
51 version = "1.0.5";
52
53 disabled = isPyPy || pythonOlder "2.6" || (isPy3k && pythonOlder "3.3");
54
55 src = fetchPypi {
56 inherit pname version;
57 sha256 = "129f43ww2a6badfdr6b88kzjzz2b0wk0dwkvwb55z6dsagfkk53f";
58 };
59
60 postPatch = ''
61 substituteInPlace theano/configdefaults.py \
62 --replace 'StrParam(param, is_valid=warn_cxx)' 'StrParam('\'''${cxx_compiler}'\''', is_valid=warn_cxx)' \
63 --replace 'rc == 0 and config.cxx != ""' 'config.cxx != ""'
64 '' + stdenv.lib.optionalString cudaSupport ''
65 substituteInPlace theano/configdefaults.py \
66 --replace 'StrParam(get_cuda_root)' 'StrParam('\'''${cudatoolkit}'\''')'
67 '' + stdenv.lib.optionalString cudnnSupport ''
68 substituteInPlace theano/configdefaults.py \
69 --replace 'StrParam(default_dnn_base_path)' 'StrParam('\'''${cudnn}'\''')'
70 '';
71
72 # Needs to be postFixup so it runs before pythonImportsCheck even when
73 # doCheck = false (meaning preCheck would be disabled).
74 # This branch is missing #97597 (and its predecessor #93560), meaning only
75 # "/tmp" is exempt from NIX_ENFORCE_PURITY's objections when theano is
76 # imported from within a nix build environment. Therefore use libredirect
77 # to convince the wrapper we are actually accessing "/tmp".
78 postFixup = ''
79 mkdir -p check-phase
80 export HOME=$(pwd)/check-phase
81
82 export NIX_REDIRECTS=/tmp=$TMPDIR
83 export LD_PRELOAD=${libredirect}/lib/libredirect.so
84 export TEMP=/tmp
85 export TEMPDIR=/tmp
86 export TMP=/tmp
87 export TMPDIR=/tmp
88 '';
89 doCheck = false;
90 # takes far too long, also throws "TypeError: sort() missing 1 required positional argument: 'a'"
91 # when run from the installer, and testing with Python 3.5 hits github.com/Theano/Theano/issues/4276,
92 # the fix for which hasn't been merged yet.
93
94 # keep Nose around since running the tests by hand is possible from Python or bash
95 checkInputs = [ nose ];
96 propagatedBuildInputs = [ numpy numpy.blas scipy six libgpuarray_ ];
97
98 pythonImportsCheck = [ "theano" ];
99
100 meta = with stdenv.lib; {
101 homepage = "http://deeplearning.net/software/theano/";
102 description = "A Python library for large-scale array computation";
103 license = licenses.bsd3;
104 maintainers = with maintainers; [ maintainers.bcdarwin ];
105 };
106}