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