@@ -1,8 +1,13 @@
11{ lib
22, fetchFromGitHub
3+, buildBazelPackage
34, buildPythonPackage
45, python
6+, setuptools
7+, wheel
58, tensorflow
9+, six
10+, numpy
611, decorator
712, cloudpickle
813, hypothesis
@@ -12,19 +17,62 @@
1217, pytest
1318}:
1419
15−buildPythonPackage rec {
16− pname = "tensorflow-probability";
20+let
1721 version = "0.7";
22+ pname = "tensorflow_probability";
1823
19− src = fetchFromGitHub {
20− owner = "tensorflow";
21− repo = "probability";
22− rev = "v${version}";
23− sha256 = "0sy9gmjcvmwciamqvd7kd9qw2wd7ksklk80815fsn7sj0wiqxjyd";
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+ };
2465 };
66+in buildPythonPackage rec {
67+ inherit version pname;
68+ format = "wheel";
69+
70+ src = bazel-wheel;
2571
2672 propagatedBuildInputs = [
2773 tensorflow
74+ six
75+ numpy
2876 decorator
2977 cloudpickle
3078 ];