1{ 2 config, 3 lib, 4 stdenv, 5 buildPythonPackage, 6 fetchPypi, 7 python, 8 pythonOlder, 9 pythonAtLeast, 10 zlib, 11 setuptools, 12 cudaSupport ? config.cudaSupport or false, 13 cudaPackages, 14 addDriverRunpath, 15 # runtime dependencies 16 httpx, 17 numpy, 18 protobuf, 19 pillow, 20 decorator, 21 astor, 22 opt-einsum, 23 typing-extensions, 24}: 25 26let 27 pname = "paddlepaddle" + lib.optionalString cudaSupport "-gpu"; 28 version = if cudaSupport then "2.6.2" else "3.0.0"; 29 format = "wheel"; 30 pyShortVersion = "cp${builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion}"; 31 cpuOrGpu = if cudaSupport then "gpu" else "cpu"; 32 allHashAndPlatform = import ./binary-hashes.nix; 33 hash = 34 allHashAndPlatform."${stdenv.hostPlatform.system}"."${cpuOrGpu}"."${pyShortVersion}" 35 or (throw "${pname} has no binary-hashes.nix entry for '${stdenv.hostPlatform.system}.${cpuOrGpu}.${pyShortVersion}' attribute"); 36 platform = allHashAndPlatform."${stdenv.hostPlatform.system}".platform; 37 src = fetchPypi { 38 inherit 39 version 40 format 41 hash 42 platform 43 ; 44 pname = builtins.replaceStrings [ "-" ] [ "_" ] pname; 45 dist = pyShortVersion; 46 python = pyShortVersion; 47 abi = pyShortVersion; 48 }; 49in 50buildPythonPackage { 51 inherit 52 pname 53 version 54 format 55 src 56 ; 57 58 disabled = 59 if cudaSupport then 60 (pythonOlder "3.11" || pythonAtLeast "3.13") 61 else 62 (pythonOlder "3.12" || pythonAtLeast "3.14"); 63 64 nativeBuildInputs = [ addDriverRunpath ]; 65 66 dependencies = [ 67 setuptools 68 httpx 69 numpy 70 protobuf 71 pillow 72 decorator 73 astor 74 opt-einsum 75 typing-extensions 76 ]; 77 78 pythonImportsCheck = [ "paddle" ]; 79 80 # no tests 81 doCheck = false; 82 83 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ( 84 let 85 libraryPath = lib.makeLibraryPath ( 86 [ 87 zlib 88 (lib.getLib stdenv.cc.cc) 89 ] 90 ++ lib.optionals cudaSupport ( 91 with cudaPackages; 92 [ 93 cudatoolkit.lib 94 cudatoolkit.out 95 cudnn 96 ] 97 ) 98 ); 99 in 100 '' 101 function fixRunPath { 102 p=$(patchelf --print-rpath $1) 103 patchelf --set-rpath "$p:${libraryPath}" $1 104 ${lib.optionalString cudaSupport '' 105 addDriverRunpath $1 106 ''} 107 } 108 fixRunPath $out/${python.sitePackages}/paddle/base/libpaddle.so 109 fixRunPath $out/${python.sitePackages}/paddle/libs/lib*.so 110 '' 111 ); 112 113 meta = { 114 description = "Machine Learning Framework from Industrial Practice"; 115 homepage = "https://github.com/PaddlePaddle/Paddle"; 116 license = lib.licenses.asl20; 117 maintainers = with lib.maintainers; [ happysalada ]; 118 platforms = [ 119 "x86_64-linux" 120 ] 121 ++ lib.optionals (!cudaSupport) [ 122 "aarch64-linux" 123 "x86_64-darwin" 124 "aarch64-darwin" 125 ]; 126 }; 127}