about summary refs log tree commit diff
path: root/pkgs/development/python-modules/pymupdf/default.nix
blob: f54a8b7a8462819c5167eec6bc36d502d85bd791 (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
  lib,
  stdenv,
  buildPythonPackage,
  pythonOlder,
  fetchFromGitHub,
  python,

  # build-system
  libclang,
  psutil,
  setuptools,
  swig,

  # native dependencies
  freetype,
  harfbuzz,
  openjpeg,
  jbig2dec,
  libjpeg_turbo,
  gumbo,
  memstreamHook,

  # dependencies
  mupdf,

  # tests
  fonttools,
  pytestCheckHook,
}:

let
  # PyMuPDF needs the C++ bindings generated
  mupdf-cxx = mupdf.override {
    enableOcr = true;
    enableCxx = true;
    enablePython = true;
    python3 = python;
  };
in
buildPythonPackage rec {
  pname = "pymupdf";
  version = "1.24.8";
  pyproject = true;

  disabled = pythonOlder "3.7";

  src = fetchFromGitHub {
    owner = "pymupdf";
    repo = "PyMuPDF";
    rev = "refs/tags/${version}";
    hash = "sha256-NG4ZJYMYTQHiqpnaOz7hxf5UW417UKawe5EqXaBnKJ8=";
  };

  # swig is not wrapped as Python package
  # libclang calls itself just clang in wheel metadata
  postPatch = ''
    substituteInPlace setup.py \
      --replace-fail "ret.append( 'swig')" "pass" \
  '';

  nativeBuildInputs = [
    libclang
    swig
    psutil
    setuptools
  ];

  buildInputs = [
    freetype
    harfbuzz
    openjpeg
    jbig2dec
    libjpeg_turbo
    gumbo
  ] ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memstreamHook ];

  propagatedBuildInputs = [ mupdf-cxx ];

  env = {
    # force using system MuPDF (must be defined in environment and empty)
    PYMUPDF_SETUP_MUPDF_BUILD = "";
    # Setup the name of the package away from the default 'libclang'
    PYMUPDF_SETUP_LIBCLANG = "clang";
    # provide MuPDF paths
    PYMUPDF_MUPDF_LIB = "${lib.getLib mupdf-cxx}/lib";
    PYMUPDF_MUPDF_INCLUDE = "${lib.getDev mupdf-cxx}/include";
  };

  # TODO: manually add mupdf rpath until upstream fixes it
  postInstall = lib.optionalString stdenv.isDarwin ''
    for lib in */*.so $out/${python.sitePackages}/*/*.so; do
      install_name_tool -add_rpath ${lib.getLib mupdf-cxx}/lib "$lib"
    done
  '';

  nativeCheckInputs = [
    pytestCheckHook
    fonttools
  ];

  preCheck = ''
    export PATH="$PATH:$out/bin";
  '';

  disabledTests =
    [
      # Fails in release tarballs without .git
      "test_codespell"
      "test_pylint"
      # fails for indeterminate reasons
      "test_2548"
      "test_2753"
      "test_3020"
      "test_3050"
      "test_3058"
      "test_3177"
      "test_3186"
      "test_color_count"
      "test_pilsave"
      "test_fz_write_pixmap_as_jpeg"
      # NotImplementedError
      "test_1824"
      "test_2093"
      "test_2093"
      "test_2108"
      "test_2182"
      "test_2182"
      "test_2246"
      "test_2270"
      "test_2270"
      "test_2391"
      "test_2788"
      "test_2861"
      "test_2871"
      "test_2886"
      "test_2904"
      "test_2922"
      "test_2934"
      "test_2957"
      "test_2969"
      "test_3070"
      "test_3131"
      "test_3140"
      "test_3209"
      "test_3209"
      "test_3301"
      "test_3347"
      "test_caret"
      "test_deletion"
      "test_file_info"
      "test_line"
      "test_page_links_generator"
      "test_polyline"
      "test_redact"
      "test_techwriter_append"
      "test_text2"
      # Issue with FzArchive
      "test_htmlbox"
      "test_2246"
      "test_3140"
      "test_3400"
      "test_707560"
      "test_open"
      "test_objectstream1"
      "test_objectstream2"
      "test_objectstream3"
      "test_fit_springer"
      "test_write_stabilized_with_links"
      "test_textbox"
      "test_delete_image"
      # Fonts not available
      "test_fontarchive"
      "test_subset_fonts"
      # Exclude lint tests
      "test_flake8"
    ]
    ++ lib.optionals stdenv.isDarwin [
      # darwin does not support OCR right now
      "test_tesseract"
    ];

  disabledTestPaths = [
    # Issue with FzArchive
    "tests/test_docs_samples.py"
  ];

  pythonImportsCheck = [ "fitz" ];

  meta = {
    description = "Python bindings for MuPDF's rendering library";
    homepage = "https://github.com/pymupdf/PyMuPDF";
    changelog = "https://github.com/pymupdf/PyMuPDF/releases/tag/${version}";
    license = lib.licenses.agpl3Only;
    maintainers = with lib.maintainers; [ teto ];
    platforms = lib.platforms.unix;
  };
}