nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 128 lines 2.6 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 7 # build-system 8 poetry-core, 9 poetry-dynamic-versioning, 10 11 # dependencies 12 jsonschema, 13 numpy, 14 onnxruntime, 15 pillow, 16 pooch, 17 pymatting, 18 scikit-image, 19 scipy, 20 tqdm, 21 22 # optional-dependencies 23 aiohttp, 24 asyncer, 25 click, 26 fastapi, 27 filetype, 28 gradio, 29 python-multipart, 30 sniffio, 31 uvicorn, 32 watchdog, 33 34 # tests 35 versionCheckHook, 36 37 withCli ? false, 38}: 39 40let 41 isNotAarch64Linux = !(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64); 42in 43buildPythonPackage (finalAttrs: { 44 pname = "rembg"; 45 version = "2.0.72"; 46 pyproject = true; 47 48 src = fetchFromGitHub { 49 owner = "danielgatis"; 50 repo = "rembg"; 51 tag = "v${finalAttrs.version}"; 52 hash = "sha256-KYpqRuC7EjgH0UqgIoMaeHF3oQSI87j6J3bcqU+43Wo="; 53 }; 54 55 env.POETRY_DYNAMIC_VERSIONING_BYPASS = finalAttrs.version; 56 57 build-system = [ 58 poetry-core 59 poetry-dynamic-versioning 60 ]; 61 62 pythonRelaxDeps = [ 63 "jsonschema" 64 "pillow" 65 "pymatting" 66 "scikit-image" 67 ]; 68 dependencies = [ 69 jsonschema 70 numpy 71 onnxruntime 72 pillow 73 pooch 74 pymatting 75 scikit-image 76 scipy 77 tqdm 78 ] 79 ++ lib.optionals withCli finalAttrs.passthru.optional-dependencies.cli; 80 81 optional-dependencies = { 82 cli = [ 83 aiohttp 84 asyncer 85 click 86 fastapi 87 filetype 88 gradio 89 python-multipart 90 sniffio 91 uvicorn 92 watchdog 93 ]; 94 }; 95 96 preConfigure = '' 97 export NUMBA_CACHE_DIR="$(mktemp -d)" 98 ''; 99 100 postInstall = lib.optionalString (!withCli) "rm -r $out/bin"; 101 102 # not running python tests, as they require network access 103 nativeCheckInputs = lib.optionals withCli [ 104 versionCheckHook 105 ]; 106 versionCheckKeepEnvironment = [ 107 # Otherwise, fail with: 108 # RuntimeError: cannot cache function '_make_tree': no locator available for file 109 # '{{storeDir}}/lib/python3.13/site-packages/pymatting/util/kdtree.py' 110 "NUMBA_CACHE_DIR" 111 ]; 112 113 # aarch64-linux fails cpuinfo test, because /sys/devices/system/cpu/ does not exist in the sandbox: 114 # terminate called after throwing an instance of 'onnxruntime::OnnxRuntimeException' 115 # 116 # -> Skip all tests that require importing rembg 117 pythonImportsCheck = lib.optionals isNotAarch64Linux [ "rembg" ]; 118 doCheck = isNotAarch64Linux; 119 120 meta = { 121 description = "Tool to remove background from images"; 122 homepage = "https://github.com/danielgatis/rembg"; 123 changelog = "https://github.com/danielgatis/rembg/releases/tag/${finalAttrs.src.tag}"; 124 license = lib.licenses.mit; 125 maintainers = with lib.maintainers; [ defelo ]; 126 mainProgram = "rembg"; 127 }; 128})