1{ lib
2, fetchFromGitHub
3, fetchpatch
4, buildBazelPackage
5, buildPythonPackage
6, python
7, setuptools
8, wheel
9, absl-py
10, tensorflow
11, six
12, numpy
13, decorator
14, cloudpickle
15, gast
16, hypothesis
17, scipy
18, matplotlib
19, mock
20, pytest
21}:
22
23let
24 version = "0.8.0";
25 pname = "tensorflow_probability";
26
27 # first build all binaries and generate setup.py using bazel
28 bazel-wheel = buildBazelPackage {
29 name = "${pname}-${version}-py2.py3-none-any.whl";
30
31 src = fetchFromGitHub {
32 owner = "tensorflow";
33 repo = "probability";
34 rev = "${version}";
35 sha256 = "07cm8zba8n0ihzdm3k4a4rsg5v62xxsfvcw4h0niz91c0parqjqy";
36 };
37
38 patches = [
39 (fetchpatch {
40 name = "gast-0.3.patch";
41 url = "https://github.com/tensorflow/probability/commit/ae7a9d9771771ec1e7755a3588b9325f050a84cc.patch";
42 sha256 = "0kfhx30gshm8f3945na9yjjik71r20qmjzifbigaj4l8dwd9dz1a";
43 excludes = ["testing/*"];
44 })
45 (fetchpatch {
46 name = "cloudpickle-1.2.patch";
47 url = "https://github.com/tensorflow/probability/commit/78ef12b5afe3f567d16c70b74015ed1ddff1b0c8.patch";
48 sha256 = "12ms2xcljvvrnig0j78s3wfv4yf3bm5ps4rgfgv5lg2a8mzpc1ga";
49 })
50 ];
51
52 nativeBuildInputs = [
53 # needed to create the output wheel in installPhase
54 python
55 setuptools
56 wheel
57 absl-py
58 tensorflow
59 ];
60
61 bazelTarget = ":pip_pkg";
62
63 fetchAttrs = {
64 sha256 = "1qw7vkwnxy45z4vm94isq5m96xiz35sigag7vjg1xb2sklbymxh8";
65 };
66
67 buildAttrs = {
68 preBuild = ''
69 patchShebangs .
70 '';
71
72 installPhase = ''
73 # work around timestamp issues
74 # https://github.com/NixOS/nixpkgs/issues/270#issuecomment-467583872
75 export SOURCE_DATE_EPOCH=315532800
76
77 # First build, then move. Otherwise pip_pkg would create the dir $out
78 # and then put the wheel in that directory. However we want $out to
79 # point directly to the wheel file.
80 ./bazel-bin/pip_pkg . --release
81 mv *.whl "$out"
82 '';
83 };
84 };
85in buildPythonPackage {
86 inherit version pname;
87 format = "wheel";
88
89 src = bazel-wheel;
90
91 propagatedBuildInputs = [
92 tensorflow
93 six
94 numpy
95 decorator
96 cloudpickle
97 gast
98 ];
99
100 # Listed here:
101 # https://github.com/tensorflow/probability/blob/f01d27a6f256430f03b14beb14d37def726cb257/testing/run_tests.sh#L58
102 checkInputs = [
103 hypothesis
104 pytest
105 scipy
106 matplotlib
107 mock
108 ];
109
110 # actual checks currently fail because for some reason
111 # tf.enable_eager_execution is called too late. Probably because upstream
112 # intents these tests to be run by bazel, not plain pytest.
113 # checkPhase = ''
114 # # tests need to import from other test files
115 # export PYTHONPATH="$PWD/tensorflow-probability:$PYTHONPATH"
116 # py.test
117 # '';
118
119 # sanity check
120 checkPhase = ''
121 python -c 'import tensorflow_probability'
122 '';
123
124 meta = with lib; {
125 description = "Library for probabilistic reasoning and statistical analysis";
126 homepage = "https://www.tensorflow.org/probability/";
127 license = licenses.asl20;
128 maintainers = with maintainers; [ timokau ];
129 };
130}