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