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
|
{ lib
, stdenv
, buildPythonPackage
, pythonOlder
, fetchFromGitHub
, pytestCheckHook
, python
, swig
, mupdf
, freetype
, harfbuzz
, openjpeg
, jbig2dec
, libjpeg_turbo
, gumbo
, memstreamHook
, fonttools
}:
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.23.6";
format = "setuptools";
disabled = pythonOlder "3.7";
src = fetchFromGitHub {
owner = "pymupdf";
repo = "PyMuPDF";
rev = version;
hash = "sha256-60KT5+EGP+s7HD4UIeaf9x2QVNU9IUbC5WKEJbrIBCI=";
};
nativeBuildInputs = [
pytestCheckHook
swig
];
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 = "";
# 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
'';
checkInputs = [
fonttools
];
disabledTests = [
# fails for indeterminate reasons
"test_color_count"
] ++ lib.optionals stdenv.isDarwin [
# darwin does not support OCR right now
"test_tesseract"
];
pythonImportsCheck = [
"fitz"
"fitz_new"
];
meta = with lib; {
description = "Python bindings for MuPDF's rendering library";
homepage = "https://github.com/pymupdf/PyMuPDF";
changelog = "https://github.com/pymupdf/PyMuPDF/releases/tag/${version}";
license = licenses.agpl3Only;
maintainers = with maintainers; [ teto ];
platforms = platforms.unix;
};
}
|