2021-08-10 14:31:46 +00:00
|
|
|
{ lib
|
2023-03-24 00:07:29 +00:00
|
|
|
, stdenv
|
2021-08-10 14:31:46 +00:00
|
|
|
, buildPythonPackage
|
2023-03-24 00:07:29 +00:00
|
|
|
, pythonOlder
|
2023-11-16 04:20:00 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, python
|
2024-01-13 08:15:51 +00:00
|
|
|
|
|
|
|
# build-system
|
|
|
|
, libclang
|
|
|
|
, psutil
|
|
|
|
, setuptools
|
2021-08-10 14:31:46 +00:00
|
|
|
, swig
|
2024-01-13 08:15:51 +00:00
|
|
|
|
|
|
|
# native dependencies
|
2021-08-10 14:31:46 +00:00
|
|
|
, freetype
|
|
|
|
, harfbuzz
|
|
|
|
, openjpeg
|
|
|
|
, jbig2dec
|
|
|
|
, libjpeg_turbo
|
|
|
|
, gumbo
|
2023-03-24 00:07:29 +00:00
|
|
|
, memstreamHook
|
2024-01-13 08:15:51 +00:00
|
|
|
|
|
|
|
# dependencies
|
|
|
|
, mupdf
|
|
|
|
|
|
|
|
# tests
|
2023-11-16 04:20:00 +00:00
|
|
|
, fonttools
|
2024-01-13 08:15:51 +00:00
|
|
|
, pytestCheckHook
|
2021-08-10 14:31:46 +00:00
|
|
|
}:
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
let
|
|
|
|
# PyMuPDF needs the C++ bindings generated
|
|
|
|
mupdf-cxx = mupdf.override { enableOcr = true; enableCxx = true; enablePython = true; python3 = python; };
|
|
|
|
in buildPythonPackage rec {
|
2020-11-19 00:13:47 +00:00
|
|
|
pname = "pymupdf";
|
2024-01-13 08:15:51 +00:00
|
|
|
version = "1.23.7";
|
|
|
|
pyproject = true;
|
2022-12-17 10:02:37 +00:00
|
|
|
|
|
|
|
disabled = pythonOlder "3.7";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "pymupdf";
|
|
|
|
repo = "PyMuPDF";
|
2024-01-13 08:15:51 +00:00
|
|
|
rev = "refs/tags/${version}";
|
|
|
|
hash = "sha256-XVf9nKbcTS/rxRCD2u5u8ecCf0bWZ3FXXN/YulI9etU=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-01-13 08:15:51 +00:00
|
|
|
# swig is not wrapped as python package
|
|
|
|
# libclang calls itself just clang in wheel metadata
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace pyproject.toml \
|
|
|
|
--replace '"swig",' "" \
|
|
|
|
--replace "libclang" "clang"
|
|
|
|
'';
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
nativeBuildInputs = [
|
2024-01-13 08:15:51 +00:00
|
|
|
libclang
|
2022-12-17 10:02:37 +00:00
|
|
|
swig
|
2024-01-13 08:15:51 +00:00
|
|
|
psutil
|
|
|
|
setuptools
|
2022-12-17 10:02:37 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
freetype
|
|
|
|
harfbuzz
|
|
|
|
openjpeg
|
|
|
|
jbig2dec
|
|
|
|
libjpeg_turbo
|
|
|
|
gumbo
|
2023-03-24 00:07:29 +00:00
|
|
|
] ++ lib.optionals (stdenv.system == "x86_64-darwin") [
|
|
|
|
memstreamHook
|
2022-12-17 10:02:37 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2024-01-13 08:15:51 +00:00
|
|
|
nativeCheckInputs = [
|
|
|
|
pytestCheckHook
|
2023-11-16 04:20:00 +00:00
|
|
|
fonttools
|
|
|
|
];
|
|
|
|
|
|
|
|
disabledTests = [
|
|
|
|
# fails for indeterminate reasons
|
|
|
|
"test_color_count"
|
2024-01-13 08:15:51 +00:00
|
|
|
"test_2753"
|
|
|
|
"test_2548"
|
2023-11-16 04:20:00 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
# darwin does not support OCR right now
|
|
|
|
"test_tesseract"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
pythonImportsCheck = [
|
|
|
|
"fitz"
|
2023-11-16 04:20:00 +00:00
|
|
|
"fitz_new"
|
2022-12-17 10:02:37 +00:00
|
|
|
];
|
2021-08-10 14:31:46 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2022-12-17 10:02:37 +00:00
|
|
|
description = "Python bindings for MuPDF's rendering library";
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "https://github.com/pymupdf/PyMuPDF";
|
2022-12-17 10:02:37 +00:00
|
|
|
changelog = "https://github.com/pymupdf/PyMuPDF/releases/tag/${version}";
|
2021-08-10 14:31:46 +00:00
|
|
|
license = licenses.agpl3Only;
|
2022-12-17 10:02:37 +00:00
|
|
|
maintainers = with maintainers; [ teto ];
|
2023-03-24 00:07:29 +00:00
|
|
|
platforms = platforms.unix;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|