1{ lib 2, stdenv 3, buildPythonPackage 4, pythonOlder 5, fetchFromGitHub 6, pytestCheckHook 7, python 8, swig 9, mupdf 10, freetype 11, harfbuzz 12, openjpeg 13, jbig2dec 14, libjpeg_turbo 15, gumbo 16, memstreamHook 17, fonttools 18}: 19 20let 21 # PyMuPDF needs the C++ bindings generated 22 mupdf-cxx = mupdf.override { enableOcr = true; enableCxx = true; enablePython = true; python3 = python; }; 23in buildPythonPackage rec { 24 pname = "pymupdf"; 25 version = "1.23.6"; 26 format = "setuptools"; 27 28 disabled = pythonOlder "3.7"; 29 30 src = fetchFromGitHub { 31 owner = "pymupdf"; 32 repo = "PyMuPDF"; 33 rev = version; 34 hash = "sha256-60KT5+EGP+s7HD4UIeaf9x2QVNU9IUbC5WKEJbrIBCI="; 35 }; 36 37 nativeBuildInputs = [ 38 pytestCheckHook 39 swig 40 ]; 41 42 buildInputs = [ 43 freetype 44 harfbuzz 45 openjpeg 46 jbig2dec 47 libjpeg_turbo 48 gumbo 49 ] ++ lib.optionals (stdenv.system == "x86_64-darwin") [ 50 memstreamHook 51 ]; 52 53 propagatedBuildInputs = [ 54 mupdf-cxx 55 ]; 56 57 env = { 58 # force using system MuPDF (must be defined in environment and empty) 59 PYMUPDF_SETUP_MUPDF_BUILD = ""; 60 # provide MuPDF paths 61 PYMUPDF_MUPDF_LIB = "${lib.getLib mupdf-cxx}/lib"; 62 PYMUPDF_MUPDF_INCLUDE = "${lib.getDev mupdf-cxx}/include"; 63 }; 64 65 # TODO: manually add mupdf rpath until upstream fixes it 66 postInstall = lib.optionalString stdenv.isDarwin '' 67 for lib in */*.so $out/${python.sitePackages}/*/*.so; do 68 install_name_tool -add_rpath ${lib.getLib mupdf-cxx}/lib "$lib" 69 done 70 ''; 71 72 checkInputs = [ 73 fonttools 74 ]; 75 76 disabledTests = [ 77 # fails for indeterminate reasons 78 "test_color_count" 79 ] ++ lib.optionals stdenv.isDarwin [ 80 # darwin does not support OCR right now 81 "test_tesseract" 82 ]; 83 84 pythonImportsCheck = [ 85 "fitz" 86 "fitz_new" 87 ]; 88 89 meta = with lib; { 90 description = "Python bindings for MuPDF's rendering library"; 91 homepage = "https://github.com/pymupdf/PyMuPDF"; 92 changelog = "https://github.com/pymupdf/PyMuPDF/releases/tag/${version}"; 93 license = licenses.agpl3Only; 94 maintainers = with maintainers; [ teto ]; 95 platforms = platforms.unix; 96 }; 97}