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