summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/img2pdf/default.nix
blob: f6cbbb13c2deaaadb229bddda036bc706267d39a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
  lib,
  pkgs,
  buildPythonPackage,
  fetchFromGitHub,
  replaceVars,
  colord,
  setuptools,
  pikepdf,
  pillow,
  stdenv,
  exiftool,
  imagemagick,
  mupdf-headless,
  netpbm,
  numpy,
  poppler-utils,
  pytestCheckHook,
  runCommand,
  scipy,
}:

buildPythonPackage rec {
  pname = "img2pdf";
  version = "0.6.1";
  pyproject = true;

  # gitlab.mister-muffin.de produces a 500 error on 0.6.1
  # when upgrading, switch src attribute back to gitlab if fixed.
  src = fetchFromGitHub {
    owner = "josch";
    repo = "img2pdf";
    tag = version;
    hash = "sha256-71u6ex+UAEFPDtR9QI8Ezah5zCorn4gMdAnzFz4blsI=";
  };

  patches = [
    (replaceVars ./default-icc-profile.patch {
      srgbProfile =
        if stdenv.hostPlatform.isDarwin then
          "/System/Library/ColorSync/Profiles/sRGB Profile.icc"
        else
          # break runtime dependency chain all of colord dependencies
          runCommand "sRGC.icc" { } ''
            cp ${colord}/share/color/icc/colord/sRGB.icc $out
          '';
    })
  ];

  build-system = [ setuptools ];

  dependencies = [
    pikepdf
    pillow
  ];

  # FIXME: Only add "sRGB Profile.icc" to __impureHostDeps once
  # https://github.com/NixOS/nix/issues/9301 is fixed.
  __impureHostDeps = lib.optionals stdenv.hostPlatform.isDarwin [
    "/System/Library/ColorSync/Profiles"
  ];

  nativeCheckInputs = [
    exiftool
    pkgs.ghostscript
    imagemagick
    mupdf-headless
    netpbm
    numpy
    poppler-utils
    pytestCheckHook
    scipy
  ];

  preCheck = ''
    export img2pdfprog="$out/bin/img2pdf"
  '';

  disabledTests = [
    # https://gitlab.mister-muffin.de/josch/img2pdf/issues/178
    "test_jpg_cmyk"
    "test_miff_cmyk8"
    "test_tiff_cmyk8"
    "test_miff_cmyk16"
    "test_png_gray16"
    "test_png_rgb16"
    # these only fail on aarch64
    "test_png_rgba8"
    "test_png_gray8a"
    # AssertionError: assert 'resolution' not in ...
    # (starting with ImagMagick 7.1.2-5)
    "test_date"
    "test_jpg"
  ];

  pythonImportsCheck = [ "img2pdf" ];

  meta = {
    changelog = "https://gitlab.mister-muffin.de/josch/img2pdf/src/tag/${src.tag}/CHANGES.rst";
    description = "Convert images to PDF via direct JPEG inclusion";
    homepage = "https://gitlab.mister-muffin.de/josch/img2pdf";
    license = lib.licenses.lgpl3Plus;
    mainProgram = "img2pdf";
    maintainers = with lib.maintainers; [
      veprbl
      dotlambda
    ];
  };
}