Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 bazel_6, 6 buildBazelPackage, 7 buildPythonPackage, 8 cctools, 9 python, 10 setuptools, 11 wheel, 12 absl-py, 13 tensorflow, 14 six, 15 numpy, 16 dm-tree, 17 keras, 18 decorator, 19 cloudpickle, 20 gast, 21 hypothesis, 22 scipy, 23 pandas, 24 mpmath, 25 matplotlib, 26 mock, 27 pytest, 28}: 29 30let 31 version = "0.21.0"; 32 pname = "tensorflow-probability"; 33 34 # first build all binaries and generate setup.py using bazel 35 bazel-wheel = buildBazelPackage { 36 name = "tensorflow_probability-${version}-py2.py3-none-any.whl"; 37 src = fetchFromGitHub { 38 owner = "tensorflow"; 39 repo = "probability"; 40 rev = "refs/tags/v${version}"; 41 hash = "sha256-DsJd1E5n86xNS7Ci0DXxoUxQ9jH8OwTZq2UuLlQtMUU="; 42 }; 43 nativeBuildInputs = [ 44 # needed to create the output wheel in installPhase 45 python 46 setuptools 47 wheel 48 absl-py 49 tensorflow 50 ]; 51 52 bazel = bazel_6; 53 54 bazelTargets = [ ":pip_pkg" ]; 55 LIBTOOL = lib.optionalString stdenv.isDarwin "${cctools}/bin/libtool"; 56 57 fetchAttrs = { 58 sha256 = "sha256-TbWcWYidyXuAMgBnO2/k0NKCzc4wThf2uUeC3QxdBJY="; 59 }; 60 61 buildAttrs = { 62 preBuild = '' 63 patchShebangs . 64 ''; 65 66 installPhase = '' 67 # work around timestamp issues 68 # https://github.com/NixOS/nixpkgs/issues/270#issuecomment-467583872 69 export SOURCE_DATE_EPOCH=315532800 70 71 # First build, then move. Otherwise pip_pkg would create the dir $out 72 # and then put the wheel in that directory. However we want $out to 73 # point directly to the wheel file. 74 ./bazel-bin/pip_pkg . --release 75 mv *.whl "$out" 76 ''; 77 }; 78 }; 79in 80buildPythonPackage { 81 inherit version pname; 82 format = "wheel"; 83 84 src = bazel-wheel; 85 86 propagatedBuildInputs = [ 87 tensorflow 88 six 89 numpy 90 decorator 91 cloudpickle 92 gast 93 dm-tree 94 keras 95 ]; 96 97 # Listed here: 98 # https://github.com/tensorflow/probability/blob/f3777158691787d3658b5e80883fe1a933d48989/testing/dependency_install_lib.sh#L83 99 nativeCheckInputs = [ 100 hypothesis 101 pytest 102 scipy 103 pandas 104 mpmath 105 matplotlib 106 mock 107 ]; 108 109 # Ideally, we run unit tests with pytest, but in checkPhase, only the Bazel-build wheel is available. 110 # But it seems not guaranteed that running the tests with pytest will even work, see 111 # https://github.com/tensorflow/probability/blob/c2a10877feb2c4c06a4dc58281e69c37a11315b9/CONTRIBUTING.md?plain=1#L69 112 # Ideally, tests would be run using Bazel. For now, lets's do a... 113 114 # sanity check 115 pythonImportsCheck = [ "tensorflow_probability" ]; 116 117 meta = with lib; { 118 description = "Library for probabilistic reasoning and statistical analysis"; 119 homepage = "https://www.tensorflow.org/probability/"; 120 license = licenses.asl20; 121 maintainers = with maintainers; [ GaetanLepage ]; 122 }; 123}