chromium,chromedriver: 129.0.6668.91 -> 129.0.6668.100
[NixPkgs.git] / pkgs / by-name / ba / backgroundremover / package.nix
blob1d16ec2071a70425081eddcbd8b6930bfb4375ac
1 { python3
2 , lib
3 , runCommand
4 , fetchFromGitHub
5 , fetchurl
6 , gitUpdater
7 }:
9 let
10   p = python3.pkgs;
11   self = p.buildPythonApplication rec {
12     pname = "backgroundremover";
13     version = "0.2.8";
14     pyproject = true;
16     src = fetchFromGitHub {
17       owner = "nadermx";
18       repo = "backgroundremover";
19       rev = "v${version}";
20       hash = "sha256-LjVT4j0OzfbVSQgU0z/gzRTLm7N0RQRrfxtTugWwOxs=";
21     };
23     models = runCommand "background-remover-models" {} ''
24       mkdir $out
25       cat ${src}/models/u2a{a,b,c,d} > $out/u2net.pth
26       cat ${src}/models/u2ha{a,b,c,d} > $out/u2net_human_seg.pth
27       cp ${src}/models/u2netp.pth $out
28     '';
30     postPatch = ''
31       substituteInPlace backgroundremover/bg.py backgroundremover/u2net/detect.py \
32         --replace-fail 'os.path.expanduser(os.path.join("~", ".u2net", model_name + ".pth"))' "os.path.join(\"$models\", model_name + \".pth\")"
33     '';
35     nativeBuildInputs = [ p.setuptools p.wheel ];
37     pythonRelaxDeps = [ "pillow" "torchvision" ];
39     propagatedBuildInputs = [
40       p.certifi
41       p.charset-normalizer
42       p.ffmpeg-python
43       p.filelock
44       p.filetype
45       p.hsh
46       p.idna
47       p.more-itertools
48       p.moviepy
49       p.numpy
50       p.pillow
51       p.pymatting
52       p.pysocks
53       p.requests
54       p.scikit-image
55       p.scipy
56       p.six
57       p.torch
58       p.torchvision
59       p.tqdm
60       p.urllib3
61       p.waitress
62     ];
64     pythonImportsCheck = [ "backgroundremover" ];
66     passthru = {
67       inherit models;
68       tests = {
69         image = let
70           # random no copyright car image from the internet
71           demoImage = fetchurl {
72             url = "https://pics.craiyon.com/2023-07-16/38653769ac3b4e068181cb5ab1e542a1.webp";
73             hash = "sha256-Kvd06eZdibgDbabVVe0+cNTeS1rDnMXIZZpPlHIlfBo=";
74           };
75         in runCommand "backgroundremover-image-test.png" {
76           buildInputs = [ self ];
77         } ''
78           export NUMBA_CACHE_DIR=$(mktemp -d)
79           backgroundremover -i ${demoImage} -o $out
80         '';
81       };
82       updateScript = gitUpdater { rev-prefix = "v"; };
83     };
85     doCheck = false; # no tests
87     meta = with lib; {
88       mainProgram = "backgroundremover";
89       description = "Command line tool to remove background from image and video, made by nadermx to power";
90       homepage = "https://BackgroundRemoverAI.com";
91       downloadPage = "https://github.com/nadermx/backgroundremover/releases";
92       license = licenses.mit;
93       maintainers = [ maintainers.lucasew ];
94     };
95   };
96 in self