nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at r-updates 103 lines 2.6 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 setuptools, 7 opencv-python, 8 torch, 9 onnx, 10 onnxruntime, 11 pillow, 12 pywavelets, 13 numpy, 14 callPackage, 15 withOnnx ? false, # Enables the rivaGan en- and decoding method 16}: 17 18buildPythonPackage rec { 19 pname = "invisible-watermark"; 20 version = "0.2.0"; 21 pyproject = true; 22 23 src = fetchFromGitHub { 24 owner = "ShieldMnt"; 25 repo = "invisible-watermark"; 26 # nixpkgs-update: no auto update 27 rev = "e58e451cff7e092457cd915e445b1a20b64a7c8f"; # No git tag, see https://github.com/ShieldMnt/invisible-watermark/issues/22 28 hash = "sha256-6SjVpKFtiiLLU7tZ3hBQr0KT/YEQyywJj0e21/dJRzk="; 29 }; 30 31 build-system = [ setuptools ]; 32 33 dependencies = [ 34 opencv-python 35 torch 36 pillow 37 pywavelets 38 numpy 39 ] 40 ++ lib.optionals withOnnx [ 41 onnx 42 onnxruntime 43 ]; 44 45 postPatch = '' 46 substituteInPlace imwatermark/rivaGan.py --replace \ 47 'You can install it with pip: `pip install onnxruntime`.' \ 48 'You can install it with an override: `python3Packages.invisible-watermark.override { withOnnx = true; };`.' 49 ''; 50 51 passthru.tests = 52 let 53 image = "${src}/test_vectors/original.jpg"; 54 methods = [ 55 "dwtDct" 56 "dwtDctSvd" 57 "rivaGan" 58 ]; 59 testCases = builtins.concatMap (method: [ 60 { 61 method = method; 62 withOnnx = true; 63 } 64 { 65 method = method; 66 withOnnx = false; 67 } 68 ]) methods; 69 createTest = 70 { method, withOnnx }: 71 let 72 testName = "${if withOnnx then "withOnnx" else "withoutOnnx"}-${method}"; 73 # This test fails in the sandbox on aarch64-linux, see https://github.com/microsoft/onnxruntime/issues/10038 74 skipTest = 75 stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 && withOnnx && method == "rivaGan"; 76 in 77 lib.optionalAttrs (!skipTest) { 78 "${testName}" = callPackage ./tests/cli.nix { 79 inherit 80 image 81 method 82 testName 83 withOnnx 84 ; 85 }; 86 }; 87 allTests = map createTest testCases; 88 in 89 (lib.attrsets.mergeAttrsList allTests) 90 // { 91 python = callPackage ./tests/python { inherit image; }; 92 }; 93 94 pythonImportsCheck = [ "imwatermark" ]; 95 96 meta = { 97 description = "Library for creating and decoding invisible image watermarks"; 98 mainProgram = "invisible-watermark"; 99 homepage = "https://github.com/ShieldMnt/invisible-watermark"; 100 license = lib.licenses.mit; 101 maintainers = with lib.maintainers; [ Luflosi ]; 102 }; 103}